[Groonga-commit] droonga/droonga-client-ruby at 6e216e4 [master] Fixup some fields before a message is sent

Back to archive index

Kouhei Sutou kou****@clear*****
Thu Jan 15 14:42:08 JST 2015


> +      def date
> +        @date ||= Time.now.iso8601
> +      end

代入しないほうがいいんじゃないですかねぇ。
これは「最初に使った時の今の時間」ですけど、
いつでも「今の時刻」の方がよくないですか?

それはそれとして、perfectorとはすごい名前にしましたねぇ。


In <6e216e4c67faa9e865dffc4fd586ab8ca31bbd8b �� jenkins.clear-code.com>
  "[Groonga-commit] droonga/droonga-client-ruby �� 6e216e4 [master] Fixup some fields before a message is sent" on Thu, 15 Jan 2015 14:32:12 +0900,
  YUKI Hiroshi <null+groonga �� clear-code.com> wrote:

> YUKI Hiroshi	2015-01-15 14:32:12 +0900 (Thu, 15 Jan 2015)
> 
>   New Revision: 6e216e4c67faa9e865dffc4fd586ab8ca31bbd8b
>   https://github.com/droonga/droonga-client-ruby/commit/6e216e4c67faa9e865dffc4fd586ab8ca31bbd8b
> 
>   Message:
>     Fixup some fields before a message is sent
> 
>   Added files:
>     lib/droonga/client/message_perfector.rb
>   Modified files:
>     bin/droonga-request
> 
>   Modified: bin/droonga-request (+5 -1)
> ===================================================================
> --- bin/droonga-request    2014-11-29 02:17:06 +0900 (0c30185)
> +++ bin/droonga-request    2015-01-15 14:32:12 +0900 (f8a3134)
> @@ -1,6 +1,6 @@
>  #!/usr/bin/env ruby
>  #
> -# Copyright (C) 2014 Droonga Project
> +# Copyright (C) 2014-2015 Droonga Project
>  #
>  # This library is free software; you can redistribute it and/or
>  # modify it under the terms of the GNU Lesser General Public
> @@ -20,6 +20,7 @@ require "yajl"
>  require "json"
>  
>  require "droonga/client"
> +require "droonga/client/message_perfector"
>  
>  options = {
>    :host                => "localhost",
> @@ -99,6 +100,8 @@ parser.on("--[no-]report-elapsed-time",
>  end
>  request_json_files = parser.parse!(ARGV)
>  
> +perfector = Droonga::Client::MessagePerfector.new
> +
>  client = Droonga::Client.new(options)
>  json_parser = Yajl::Parser.new
>  json_parser.on_parse_complete = lambda do |request_message|
> @@ -112,6 +115,7 @@ json_parser.on_parse_complete = lambda do |request_message|
>      message << "\n"
>      print(message)
>    end
> +  request_message = perfector.perfect(request_message)
>    start = Time.now
>    request = client.request(request_message) do |response|
>      message = ""
> 
>   Added: lib/droonga/client/message_perfector.rb (+44 -0) 100644
> ===================================================================
> --- /dev/null
> +++ lib/droonga/client/message_perfector.rb    2015-01-15 14:32:12 +0900 (feed6d1)
> @@ -0,0 +1,44 @@
> +# -*- coding: utf-8 -*-
> +#
> +# Copyright (C) 2015 Droonga Project
> +#
> +# This library is free software; you can redistribute it and/or
> +# modify it under the terms of the GNU Lesser General Public
> +# License version 2.1 as published by the Free Software Foundation.
> +#
> +# This library is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> +# Lesser General Public License for more details.
> +#
> +# You should have received a copy of the GNU Lesser General Public
> +# License along with this library; if not, write to the Free Software
> +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
> +
> +require "time"
> +
> +module Droonga
> +  class Client
> +    class MessagePerfector
> +      def initialize(options={})
> +        @options = options
> +        @date ||= @options["date"]
> +      end
> +
> +      def perfect(message)
> +        message["id"]   ||= generate_id
> +        message["date"] ||= date
> +        message
> +      end
> +
> +      private
> +      def generate_id
> +        "#{Time.now} / #{Random.rand}"
> +      end
> +
> +      def date
> +        @date ||= Time.now.iso8601
> +      end
> +    end
> +  end
> +end




More information about the Groonga-commit mailing list
Back to archive index