droonga-message-pack-packer 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4a0566ff09b04785e46acc63cbc2448693629122
4
+ data.tar.gz: b661ba7b363dff2313bd10dc92d4d934fdc08146
5
+ SHA512:
6
+ metadata.gz: 812845c60ea60d314ae147e3773ed5ffed46bbfda2762ef3df9930678a3fe6111aa5803e4599dc1c403df6ba49cd48efe07a03c76dcc8e7aa39964f0aa52e4c5
7
+ data.tar.gz: 8b0b29e22a148852460a0ddcaee25957162446fb439842e0552782013957483fe4e9ba1c288eb97202b895be087304a30e73848cbbc405dd339c304909031754
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ /Gemfile.lock
2
+ /pkg/
data/Gemfile ADDED
@@ -0,0 +1,18 @@
1
+ # Copyright (C) 2013-2014 Droonga Project
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License version 2.1 as published by the Free Software Foundation.
6
+ #
7
+ # This library is distributed in the hope that it will be useful,
8
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10
+ # Lesser General Public License for more details.
11
+ #
12
+ # You should have received a copy of the GNU Lesser General Public
13
+ # License along with this library; if not, write to the Free Software
14
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
+
16
+ source "https://rubygems.org"
17
+
18
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,14 @@
1
+ Copyright (C) 2013-2014 Droonga Project
2
+
3
+ This library is free software; you can redistribute it and/or
4
+ modify it under the terms of the GNU Lesser General Public
5
+ License version 2.1 as published by the Free Software Foundation.
6
+
7
+ This library is distributed in the hope that it will be useful,
8
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10
+ Lesser General Public License for more details.
11
+
12
+ You should have received a copy of the GNU Lesser General Public
13
+ License along with this library; if not, write to the Free Software
14
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # droonga-message-pack-packer
2
+
3
+ A MessagePack packer for Droonga message. In Droonga message, time
4
+ value should be formatted as
5
+ [W3C-TDF](http://www.w3.org/TR/NOTE-datetime) string. You need to
6
+ format all times in Droonga message as W3C-TDF string by yourself when
7
+ you use the original MessagePack packer. This library does it instead
8
+ of you. You can pass your Droonga message that may have time values
9
+ into MessagePack packer in this library.
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ gem 'droonga-message-pack-packer
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install droonga-message-pack-packer
24
+
25
+ ## Usage
26
+
27
+ require "droonga/message-pack-packer"
28
+ Droonga::MessagePackPacker.pack(message)
29
+
30
+ ## Contributing
31
+
32
+ 1. Fork it
33
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
34
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
35
+ 4. Push to the branch (`git push origin my-new-feature`)
36
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,35 @@
1
+ # -*- mode: ruby; coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2013-2014 Droonga Project
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License version 2.1 as published by the Free Software Foundation.
8
+ #
9
+ # This library is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # Lesser General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU Lesser General Public
15
+ # License along with this library; if not, write to the Free Software
16
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
+
18
+ require "bundler/gem_helper"
19
+ require "packnga"
20
+
21
+ base_dir = File.join(File.dirname(__FILE__))
22
+
23
+ helper = Bundler::GemHelper.new(base_dir)
24
+ def helper.version_tag
25
+ version
26
+ end
27
+
28
+ helper.install
29
+ spec = helper.gemspec
30
+
31
+ Packnga::DocumentTask.new(spec) do |task|
32
+ task.original_language = "en"
33
+ task.translate_languages = ["ja"]
34
+ end
35
+
data/doc/text/news.md ADDED
@@ -0,0 +1,5 @@
1
+ # News
2
+
3
+ ## 1.0.0: 2014-04-10
4
+
5
+ The first release!!!
@@ -0,0 +1,42 @@
1
+ # Copyright (C) 2013-2014 Droonga Project
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License version 2.1 as published by the Free Software Foundation.
6
+ #
7
+ # This library is distributed in the hope that it will be useful,
8
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10
+ # Lesser General Public License for more details.
11
+ #
12
+ # You should have received a copy of the GNU Lesser General Public
13
+ # License along with this library; if not, write to the Free Software
14
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
+
16
+ lib = File.expand_path('../lib', __FILE__)
17
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
18
+ require 'droonga/message-pack-packer/version'
19
+
20
+ Gem::Specification.new do |spec|
21
+ spec.name = "droonga-message-pack-packer"
22
+ spec.version = Droonga::MessagePackPacker::VERSION
23
+ spec.authors = ["Droonga Project"]
24
+ spec.email = ["droonga@groonga.org"]
25
+ spec.summary = "A MessagePack packer for Droonga message"
26
+ spec.description = "This MessagePack packer packs time values into W3C-TDF format string automatically. Because it is a rule in Droonga message."
27
+ spec.homepage = "https://github.com/droonga/droonga-message-pack-packer-ruby"
28
+ spec.license = "LGPL-2.1"
29
+ spec.required_ruby_version = '>= 1.9.3'
30
+
31
+ spec.files = `git ls-files`.split($/)
32
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
33
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
34
+ spec.require_paths = ["lib"]
35
+
36
+ spec.add_runtime_dependency "msgpack"
37
+
38
+ spec.add_development_dependency "bundler"
39
+ spec.add_development_dependency "rake"
40
+ spec.add_development_dependency "packnga"
41
+ spec.add_development_dependency "test-unit"
42
+ end
@@ -0,0 +1,60 @@
1
+ # Copyright (C) 2013 Droonga Project
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License version 2.1 as published by the Free Software Foundation.
6
+ #
7
+ # This library is distributed in the hope that it will be useful,
8
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10
+ # Lesser General Public License for more details.
11
+ #
12
+ # You should have received a copy of the GNU Lesser General Public
13
+ # License along with this library; if not, write to the Free Software
14
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
+
16
+ require "msgpack"
17
+
18
+ require "droonga/message-pack-packer/time-formatter"
19
+
20
+ module Droonga
21
+ class MessagePackPacker
22
+ class << self
23
+ def pack(object)
24
+ packer = new
25
+ packer.pack(object)
26
+ packer.to_s
27
+ end
28
+ end
29
+
30
+ MICRO_SECONDS_DECIMAL_PLACE = 6
31
+
32
+ def initialize
33
+ @packer = MessagePack::Packer.new
34
+ end
35
+
36
+ def pack(object)
37
+ case object
38
+ when Array
39
+ @packer.write_array_header(object.size)
40
+ object.each do |element|
41
+ pack(element)
42
+ end
43
+ when Hash
44
+ @packer.write_map_header(object.size)
45
+ object.each do |key, value|
46
+ pack(key)
47
+ pack(value)
48
+ end
49
+ when Time
50
+ @packer.write(TimeFormatter.format(object))
51
+ else
52
+ @packer.write(object)
53
+ end
54
+ end
55
+
56
+ def to_s
57
+ @packer.to_s
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,39 @@
1
+ # Copyright (C) 2013-2014 Droonga Project
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License version 2.1 as published by the Free Software Foundation.
6
+ #
7
+ # This library is distributed in the hope that it will be useful,
8
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10
+ # Lesser General Public License for more details.
11
+ #
12
+ # You should have received a copy of the GNU Lesser General Public
13
+ # License along with this library; if not, write to the Free Software
14
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
+
16
+ require "time"
17
+
18
+ module Droonga
19
+ class MessagePackPacker
20
+ class TimeFormatter
21
+ class << self
22
+ def format(object)
23
+ formatter = new(object)
24
+ formatter.format
25
+ end
26
+ end
27
+
28
+ MICRO_SECONDS_DECIMAL_PLACE = 6
29
+
30
+ def initialize(time)
31
+ @time = time
32
+ end
33
+
34
+ def format
35
+ @time.utc.iso8601(MICRO_SECONDS_DECIMAL_PLACE)
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,20 @@
1
+ # Copyright (C) 2013-2014 Droonga Project
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License version 2.1 as published by the Free Software Foundation.
6
+ #
7
+ # This library is distributed in the hope that it will be useful,
8
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10
+ # Lesser General Public License for more details.
11
+ #
12
+ # You should have received a copy of the GNU Lesser General Public
13
+ # License along with this library; if not, write to the Free Software
14
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
+
16
+ module Droonga
17
+ class MessagePackPacker
18
+ VERSION = "1.0.0"
19
+ end
20
+ end
data/test/run-test.rb ADDED
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Copyright (C) 2013-2014 Droonga Project
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License version 2.1 as published by the Free Software Foundation.
8
+ #
9
+ # This library is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # Lesser General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU Lesser General Public
15
+ # License along with this library; if not, write to the Free Software
16
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
+
18
+ require "rubygems"
19
+ require "bundler"
20
+ begin
21
+ Bundler.setup(:default, :development)
22
+ rescue Bundler::BundlerError => e
23
+ $stderr.puts(e.message)
24
+ $stderr.puts("Run `bundle install` to install missing gems")
25
+ exit(e.status_code)
26
+ end
27
+
28
+ require "test-unit"
29
+
30
+ base_dir = File.expand_path(File.join(File.dirname(__FILE__), ".."))
31
+ lib_dir = File.join(base_dir, "lib")
32
+ test_dir = File.join(base_dir, "test")
33
+
34
+ $LOAD_PATH.unshift(lib_dir)
35
+ $LOAD_PATH.unshift(test_dir)
36
+
37
+ ARGV.unshift("--max-diff-target-string-size=10000")
38
+
39
+ exit(Test::Unit::AutoRunner.run(true, test_dir))
@@ -0,0 +1,51 @@
1
+ # Copyright (C) 2013-2014 Droonga Project
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License version 2.1 as published by the Free Software Foundation.
6
+ #
7
+ # This library is distributed in the hope that it will be useful,
8
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10
+ # Lesser General Public License for more details.
11
+ #
12
+ # You should have received a copy of the GNU Lesser General Public
13
+ # License along with this library; if not, write to the Free Software
14
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
+
16
+ require "droonga/message-pack-packer"
17
+
18
+ class PackerTest < Test::Unit::TestCase
19
+ def test_integer
20
+ assert_equal(29, unpack(pack(29)))
21
+ end
22
+
23
+ def test_string
24
+ assert_equal("Droonga", unpack(pack("Droonga")))
25
+ end
26
+
27
+ def test_time
28
+ w3c_dtf_time = "2013-11-29T08:00:00.000000Z"
29
+ time = Time.parse(w3c_dtf_time)
30
+ assert_equal(w3c_dtf_time, unpack(pack(time)))
31
+ end
32
+
33
+ def test_hash
34
+ hash = {"key" => "value"}
35
+ assert_equal(hash, unpack(pack(hash)))
36
+ end
37
+
38
+ def test_array
39
+ array = ["Groonga", "Rroonga", "Droonga"]
40
+ assert_equal(array, unpack(pack(array)))
41
+ end
42
+
43
+ private
44
+ def pack(object)
45
+ Droonga::MessagePackPacker.pack(object)
46
+ end
47
+
48
+ def unpack(msgpack)
49
+ MessagePack.unpack(msgpack)
50
+ end
51
+ end
@@ -0,0 +1,29 @@
1
+ # Copyright (C) 2013-2014 Droonga Project
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License version 2.1 as published by the Free Software Foundation.
6
+ #
7
+ # This library is distributed in the hope that it will be useful,
8
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10
+ # Lesser General Public License for more details.
11
+ #
12
+ # You should have received a copy of the GNU Lesser General Public
13
+ # License along with this library; if not, write to the Free Software
14
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
+
16
+ require "droonga/message-pack-packer/time-formatter"
17
+
18
+ class TimeFormatterTest < Test::Unit::TestCase
19
+ def test_fraction
20
+ w3c_dtf_time = "2013-11-29T08:00:00.292929Z"
21
+ time = Time.parse(w3c_dtf_time)
22
+ assert_equal(w3c_dtf_time, format(time))
23
+ end
24
+
25
+ private
26
+ def format(time)
27
+ Droonga::MessagePackPacker::TimeFormatter.format(time)
28
+ end
29
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: droonga-message-pack-packer
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Droonga Project
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: msgpack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: packnga
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: test-unit
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: This MessagePack packer packs time values into W3C-TDF format string
84
+ automatically. Because it is a rule in Droonga message.
85
+ email:
86
+ - droonga@groonga.org
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - .gitignore
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - doc/text/news.md
97
+ - droonga-message-pack-packer.gemspec
98
+ - lib/droonga/message-pack-packer.rb
99
+ - lib/droonga/message-pack-packer/time-formatter.rb
100
+ - lib/droonga/message-pack-packer/version.rb
101
+ - test/run-test.rb
102
+ - test/test-packer.rb
103
+ - test/test-time-formatter.rb
104
+ homepage: https://github.com/droonga/droonga-message-pack-packer-ruby
105
+ licenses:
106
+ - LGPL-2.1
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - '>='
115
+ - !ruby/object:Gem::Version
116
+ version: 1.9.3
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.0.14
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: A MessagePack packer for Droonga message
128
+ test_files:
129
+ - test/run-test.rb
130
+ - test/test-packer.rb
131
+ - test/test-time-formatter.rb
132
+ has_rdoc: