picojson_ruby 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.gitmodules +3 -0
- data/Gemfile +13 -0
- data/LICENSE.txt +22 -0
- data/README.md +45 -0
- data/Rakefile +9 -0
- data/ext/picojson_ruby/extconf.rb +3 -0
- data/ext/picojson_ruby/picojson_ruby.cpp +40 -0
- data/ext/picojson_ruby/picojson_ruby.h +6 -0
- data/lib/picojson_ruby.rb +6 -0
- data/lib/picojson_ruby/version.rb +3 -0
- data/picojson_ruby.gemspec +28 -0
- data/spec/picojson_ruby_spec.rb +27 -0
- data/spec/spec_helper.rb +3 -0
- metadata +104 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b93d3bf2ca6e4e3a54b13e32b8e39fd44b9f8e4e
|
4
|
+
data.tar.gz: e9f69410ee2d219160da2511d8acb34168110b21
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c1549d708b02c250e542af3b94943ac29c1b8c7a0a46a2c120d41b2037a133f961b82e1938345e5838a0623eeb72fec2cb1b6fc0b6d1509c36b9f555ab342486
|
7
|
+
data.tar.gz: f920dd505c7c7004bfb362d97afecf58370d7f17720edc174a9eacb9debeeb62edae174de814a9976377aae74008bdd35963b3b92ea3bea56f9ec7ba0916107b
|
data/.gitignore
ADDED
data/.gitmodules
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in picojson_ruby.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
group :test do
|
7
|
+
gem 'simplecov', require: false
|
8
|
+
gem 'simplecov-rcov', require: false
|
9
|
+
gem 'rspec'
|
10
|
+
gem 'rspec-core'
|
11
|
+
gem 'pry'
|
12
|
+
gem 'pry-byebug'
|
13
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright 2015 haruyama-makoto
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# PicojsonRuby
|
2
|
+
|
3
|
+
Memory saving JSON merge for Ruby.
|
4
|
+
|
5
|
+
Using picojson parsing JSON.
|
6
|
+
|
7
|
+
[kazuho / picojson](https://github.com/kazuho/picojson)
|
8
|
+
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'picojson_ruby'
|
16
|
+
```
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install picojson_ruby
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
### append
|
29
|
+
Add JSON for one item.
|
30
|
+
|
31
|
+
```
|
32
|
+
p PicojsonRuby.append("{}", "key", "value")
|
33
|
+
# => "{\"key\":\"value\"}"
|
34
|
+
```
|
35
|
+
|
36
|
+
### merge
|
37
|
+
Under Development
|
38
|
+
|
39
|
+
## Contributing
|
40
|
+
|
41
|
+
1. Fork it ( https://github.com/[my-github-username]/picojson_ruby/fork )
|
42
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
43
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
44
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
45
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
#include "picojson_ruby.h"
|
2
|
+
#include "../../modules/picojson/picojson.h"
|
3
|
+
|
4
|
+
VALUE rb_cPicojsonRuby;
|
5
|
+
|
6
|
+
static VALUE rb_picojson_merge(VALUE self, VALUE base, VALUE key, VALUE value) {
|
7
|
+
picojson::value v;
|
8
|
+
std::string err;
|
9
|
+
const char* json = StringValuePtr(base);
|
10
|
+
picojson::parse(v, json, json + strlen(json), &err);
|
11
|
+
if (!err.empty()) {
|
12
|
+
rb_raise(rb_eTypeError, err.c_str());
|
13
|
+
}
|
14
|
+
|
15
|
+
const char* inserting_key = StringValuePtr(key);
|
16
|
+
picojson::object &obj = v.get<picojson::object>();
|
17
|
+
|
18
|
+
switch (TYPE(value)) {
|
19
|
+
case T_FIXNUM:
|
20
|
+
obj.insert(std::map<std::string, double>::value_type(inserting_key, FIX2INT(value)));
|
21
|
+
break;
|
22
|
+
case T_STRING:
|
23
|
+
obj.insert(std::make_pair(inserting_key, StringValuePtr(value)));
|
24
|
+
break;
|
25
|
+
default:
|
26
|
+
/* 例外を発生させる */
|
27
|
+
rb_raise(rb_eTypeError, "not valid value");
|
28
|
+
break;
|
29
|
+
}
|
30
|
+
std::string new_json = v.serialize();
|
31
|
+
const char* new_json_char = new_json.c_str();
|
32
|
+
return rb_str_new(new_json_char, strlen(new_json_char));
|
33
|
+
}
|
34
|
+
|
35
|
+
extern "C" void
|
36
|
+
Init_picojson_ruby(void)
|
37
|
+
{
|
38
|
+
rb_cPicojsonRuby = rb_define_class("PicojsonRuby", rb_cObject);
|
39
|
+
rb_define_singleton_method(rb_cPicojsonRuby, "append", RUBY_METHOD_FUNC(rb_picojson_merge), 3);
|
40
|
+
}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'picojson_ruby/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "picojson_ruby"
|
8
|
+
spec.version = PicojsonRuby::VERSION
|
9
|
+
spec.authors = ["SpringMT"]
|
10
|
+
spec.email = ["today.is.sky.blue.sky@gmail.com"]
|
11
|
+
|
12
|
+
spec.required_rubygems_version = ">= 2.0"
|
13
|
+
|
14
|
+
spec.extensions = ["ext/picojson_ruby/extconf.rb"]
|
15
|
+
spec.summary = %q{Memory saving JSON merge.}
|
16
|
+
spec.description = %q{Memory saving JSON merge. Using picojson}
|
17
|
+
spec.homepage = "https://github.com/SpringMT/picojson_ruby"
|
18
|
+
spec.license = "MIT"
|
19
|
+
|
20
|
+
spec.files = `git ls-files -z`.split("\x0")
|
21
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
22
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features|examples)/})
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
spec.add_development_dependency "rake-compiler"
|
28
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "picojson_ruby"
|
3
|
+
|
4
|
+
describe PicojsonRuby do
|
5
|
+
describe ".append" do
|
6
|
+
context 'valid appending string value' do
|
7
|
+
subject { PicojsonRuby.append("{}", "test", "test") }
|
8
|
+
it { expect(subject).to eq "{\"test\":\"test\"}" }
|
9
|
+
end
|
10
|
+
context 'valid appending string value 2' do
|
11
|
+
subject { PicojsonRuby.append("{}", "test", "1234567890") }
|
12
|
+
it { expect(subject).to eq "{\"test\":\"1234567890\"}" }
|
13
|
+
end
|
14
|
+
context 'valid appending string fixnum' do
|
15
|
+
subject { PicojsonRuby.append("{}", "test", 1234567890) }
|
16
|
+
it { expect(subject).to eq "{\"test\":1234567890}" }
|
17
|
+
end
|
18
|
+
context 'invalid with Array' do
|
19
|
+
subject { PicojsonRuby.append("{}", "test", []) }
|
20
|
+
it { expect { subject }.to raise_error TypeError }
|
21
|
+
end
|
22
|
+
context 'invalid with invalid json' do
|
23
|
+
subject { PicojsonRuby.append("{test]", "test", "test") }
|
24
|
+
it { expect { subject }.to raise_error TypeError }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: picojson_ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- SpringMT
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake-compiler
|
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
|
+
description: Memory saving JSON merge. Using picojson
|
56
|
+
email:
|
57
|
+
- today.is.sky.blue.sky@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions:
|
60
|
+
- ext/picojson_ruby/extconf.rb
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".gitmodules"
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- ext/picojson_ruby/extconf.rb
|
70
|
+
- ext/picojson_ruby/picojson_ruby.cpp
|
71
|
+
- ext/picojson_ruby/picojson_ruby.h
|
72
|
+
- lib/picojson_ruby.rb
|
73
|
+
- lib/picojson_ruby/version.rb
|
74
|
+
- picojson_ruby.gemspec
|
75
|
+
- spec/picojson_ruby_spec.rb
|
76
|
+
- spec/spec_helper.rb
|
77
|
+
homepage: https://github.com/SpringMT/picojson_ruby
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
metadata: {}
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '2.0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 2.2.2
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: Memory saving JSON merge.
|
101
|
+
test_files:
|
102
|
+
- spec/picojson_ruby_spec.rb
|
103
|
+
- spec/spec_helper.rb
|
104
|
+
has_rdoc:
|