[Groonga-commit] droonga/droonga-message-pack-packer-ruby at bb34ee2 [master] Extract from fluent-plugin-droonga

Back to archive index

Kouhei Sutou null+****@clear*****
Thu Apr 10 16:44:30 JST 2014


Kouhei Sutou	2014-04-10 16:44:30 +0900 (Thu, 10 Apr 2014)

  New Revision: bb34ee222f92827563703f5145d2017f3f81898d
  https://github.com/droonga/droonga-message-pack-packer-ruby/commit/bb34ee222f92827563703f5145d2017f3f81898d

  Message:
    Extract from fluent-plugin-droonga

  Added files:
    .gitignore
    Gemfile
    LICENSE.txt
    README.md
    Rakefile
    droonga-message-pack-packer.gemspec
    lib/droonga/message-pack-packer.rb
    lib/droonga/message-pack-packer/time-formatter.rb
    lib/droonga/message-pack-packer/version.rb
    test/run-test.rb
    test/test-packer.rb
    test/test-time-formatter.rb

  Added: .gitignore (+2 -0) 100644
===================================================================
--- /dev/null
+++ .gitignore    2014-04-10 16:44:30 +0900 (ceb75b8)
@@ -0,0 +1,2 @@
+/Gemfile.lock
+/pkg/

  Added: Gemfile (+18 -0) 100644
===================================================================
--- /dev/null
+++ Gemfile    2014-04-10 16:44:30 +0900 (cb6221f)
@@ -0,0 +1,18 @@
+# Copyright (C) 2013-2014 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
+
+source "https://rubygems.org"
+
+gemspec

  Added: LICENSE.txt (+14 -0) 100644
===================================================================
--- /dev/null
+++ LICENSE.txt    2014-04-10 16:44:30 +0900 (0918bdf)
@@ -0,0 +1,14 @@
+Copyright (C) 2013-2014 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

  Added: README.md (+36 -0) 100644
===================================================================
--- /dev/null
+++ README.md    2014-04-10 16:44:30 +0900 (79cdd80)
@@ -0,0 +1,36 @@
+# droonga-message-pack-packer
+
+A MessagePack packer for Droonga message. In Droonga message, time
+value should be formatted as
+[W3C-TDF](http://www.w3.org/TR/NOTE-datetime) string. You need to
+format all times in Droonga message as W3C-TDF string by yourself when
+you use the original MessagePack packer. This library does it instead
+of you. You can pass your Droonga message that may have time values
+into MessagePack packer in this library.
+
+## Installation
+
+Add this line to your application's Gemfile:
+
+    gem 'droonga-message-pack-packer
+
+And then execute:
+
+    $ bundle
+
+Or install it yourself as:
+
+    $ gem install droonga-message-pack-packer
+
+## Usage
+
+    require "droonga/message-pack-packer"
+    Droonga::MessagePackPacker.pack(message)
+
+## Contributing
+
+1. Fork it
+2. Create your feature branch (`git checkout -b my-new-feature`)
+3. Commit your changes (`git commit -am 'Add some feature'`)
+4. Push to the branch (`git push origin my-new-feature`)
+5. Create new Pull Request

  Added: Rakefile (+35 -0) 100644
===================================================================
--- /dev/null
+++ Rakefile    2014-04-10 16:44:30 +0900 (6d1dbaf)
@@ -0,0 +1,35 @@
+# -*- mode: ruby; coding: utf-8 -*-
+#
+# Copyright (C) 2013-2014 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 "bundler/gem_helper"
+require "packnga"
+
+base_dir = File.join(File.dirname(__FILE__))
+
+helper = Bundler::GemHelper.new(base_dir)
+def helper.version_tag
+  version
+end
+
+helper.install
+spec = helper.gemspec
+
+Packnga::DocumentTask.new(spec) do |task|
+  task.original_language = "en"
+  task.translate_languages = ["ja"]
+end
+

  Added: droonga-message-pack-packer.gemspec (+42 -0) 100644
===================================================================
--- /dev/null
+++ droonga-message-pack-packer.gemspec    2014-04-10 16:44:30 +0900 (2d27f4b)
@@ -0,0 +1,42 @@
+# Copyright (C) 2013-2014 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
+
+lib = File.expand_path('../lib', __FILE__)
+$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
+require 'droonga/message-pack-packer/version'
+
+Gem::Specification.new do |spec|
+  spec.name          = "droonga-message-pack-packer"
+  spec.version       = Droonga::MessagePackPacker::VERSION
+  spec.authors       = ["Droonga Project"]
+  spec.email         = ["droonga �� groonga.org"]
+  spec.summary       = "A MessagePack packer for Droonga message"
+  spec.description   = "This MessagePack packer packs time values into W3C-TDF format string automatically. Because it is a rule in Droonga message."
+  spec.homepage      = "https://github.com/droonga/droonga-message-pack-packer-ruby"
+  spec.license       = "LGPL-2.1"
+  spec.required_ruby_version = '>= 1.9.3'
+
+  spec.files         = `git ls-files`.split($/)
+  spec.executables   = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
+  spec.test_files    = spec.files.grep(%r{^(test|spec|features)/})
+  spec.require_paths = ["lib"]
+
+  spec.add_runtime_dependency "msgpack"
+
+  spec.add_development_dependency "bundler"
+  spec.add_development_dependency "rake"
+  spec.add_development_dependency "packnga"
+  spec.add_development_dependency "test-unit"
+end

  Added: lib/droonga/message-pack-packer.rb (+60 -0) 100644
===================================================================
--- /dev/null
+++ lib/droonga/message-pack-packer.rb    2014-04-10 16:44:30 +0900 (b827eb1)
@@ -0,0 +1,60 @@
+# Copyright (C) 2013 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 "msgpack"
+
+require "droonga/message-pack-packer/time-formatter"
+
+module Droonga
+  class MessagePackPacker
+    class << self
+      def pack(object)
+        packer = new
+        packer.pack(object)
+        packer.to_s
+      end
+    end
+
+    MICRO_SECONDS_DECIMAL_PLACE = 6
+
+    def initialize
+      @packer = MessagePack::Packer.new
+    end
+
+    def pack(object)
+      case object
+      when Array
+        @packer.write_array_header(object.size)
+        object.each do |element|
+          pack(element)
+        end
+      when Hash
+        @packer.write_map_header(object.size)
+        object.each do |key, value|
+          pack(key)
+          pack(value)
+        end
+      when Time
+        @packer.write(TimeFormatter.format(object))
+      else
+        @packer.write(object)
+      end
+    end
+
+    def to_s
+      @packer.to_s
+    end
+  end
+end

  Added: lib/droonga/message-pack-packer/time-formatter.rb (+39 -0) 100644
===================================================================
--- /dev/null
+++ lib/droonga/message-pack-packer/time-formatter.rb    2014-04-10 16:44:30 +0900 (7406009)
@@ -0,0 +1,39 @@
+# Copyright (C) 2013-2014 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 MessagePackPacker
+    class TimeFormatter
+      class << self
+        def format(object)
+          formatter = new(object)
+          formatter.format
+        end
+      end
+
+      MICRO_SECONDS_DECIMAL_PLACE = 6
+
+      def initialize(time)
+        @time = time
+      end
+
+      def format
+        @time.utc.iso8601(MICRO_SECONDS_DECIMAL_PLACE)
+      end
+    end
+  end
+end

  Added: lib/droonga/message-pack-packer/version.rb (+20 -0) 100644
===================================================================
--- /dev/null
+++ lib/droonga/message-pack-packer/version.rb    2014-04-10 16:44:30 +0900 (d01b8ee)
@@ -0,0 +1,20 @@
+# Copyright (C) 2013-2014 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
+
+module Droonga
+  class MessagePackPacker
+    VERSION = "1.0.0"
+  end
+end

  Added: test/run-test.rb (+39 -0) 100755
===================================================================
--- /dev/null
+++ test/run-test.rb    2014-04-10 16:44:30 +0900 (60a9bfe)
@@ -0,0 +1,39 @@
+#!/usr/bin/env ruby
+#
+# Copyright (C) 2013-2014 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 "rubygems"
+require "bundler"
+begin
+  Bundler.setup(:default, :development)
+rescue Bundler::BundlerError => e
+  $stderr.puts(e.message)
+  $stderr.puts("Run `bundle install` to install missing gems")
+  exit(e.status_code)
+end
+
+require "test-unit"
+
+base_dir = File.expand_path(File.join(File.dirname(__FILE__), ".."))
+lib_dir = File.join(base_dir, "lib")
+test_dir = File.join(base_dir, "test")
+
+$LOAD_PATH.unshift(lib_dir)
+$LOAD_PATH.unshift(test_dir)
+
+ARGV.unshift("--max-diff-target-string-size=10000")
+
+exit(Test::Unit::AutoRunner.run(true, test_dir))

  Added: test/test-packer.rb (+51 -0) 100644
===================================================================
--- /dev/null
+++ test/test-packer.rb    2014-04-10 16:44:30 +0900 (10b7b5b)
@@ -0,0 +1,51 @@
+# Copyright (C) 2013-2014 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 "droonga/message-pack-packer"
+
+class PackerTest < Test::Unit::TestCase
+  def test_integer
+    assert_equal(29, unpack(pack(29)))
+  end
+
+  def test_string
+    assert_equal("Droonga", unpack(pack("Droonga")))
+  end
+
+  def test_time
+    w3c_dtf_time = "2013-11-29T08:00:00.000000Z"
+    time = Time.parse(w3c_dtf_time)
+    assert_equal(w3c_dtf_time, unpack(pack(time)))
+  end
+
+  def test_hash
+    hash = {"key" => "value"}
+    assert_equal(hash, unpack(pack(hash)))
+  end
+
+  def test_array
+    array = ["Groonga", "Rroonga", "Droonga"]
+    assert_equal(array, unpack(pack(array)))
+  end
+
+  private
+  def pack(object)
+    Droonga::MessagePackPacker.pack(object)
+  end
+
+  def unpack(msgpack)
+    MessagePack.unpack(msgpack)
+  end
+end

  Added: test/test-time-formatter.rb (+29 -0) 100644
===================================================================
--- /dev/null
+++ test/test-time-formatter.rb    2014-04-10 16:44:30 +0900 (eb8adb2)
@@ -0,0 +1,29 @@
+# Copyright (C) 2013-2014 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 "droonga/message-pack-packer/time-formatter"
+
+class TimeFormatterTest < Test::Unit::TestCase
+  def test_fraction
+    w3c_dtf_time = "2013-11-29T08:00:00.292929Z"
+    time = Time.parse(w3c_dtf_time)
+    assert_equal(w3c_dtf_time, format(time))
+  end
+
+  private
+  def format(time)
+    Droonga::MessagePackPacker::TimeFormatter.format(time)
+  end
+end
-------------- next part --------------
HTML����������������������������...
Download 



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