ruson 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/README.md +12 -24
- data/lib/ruson/base.rb +26 -16
- data/lib/ruson/version.rb +1 -1
- data/ruson.gemspec +9 -8
- metadata +17 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 0eaac3b601d5b1ca7e7f99852749e5a24bfe05b070945e8ff7c577d7f89f22fe
|
|
4
|
+
data.tar.gz: 75e7430384d80df1694dbf328283775b1f4fabfa1e944d0f84acd543732cf74e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a230098ac5bef3d5f0c0e010bb8f0fcc172de10a47e34a742de3da531cf2aa261c67a31fe499cf5d070ebfb3ed604906a651e512b89fc88fc071f3b3e478172d
|
|
7
|
+
data.tar.gz: c262e5d587400aa2ca8eeda57716e2228469ceff286ac46acbe6ee6550b49711f147bbe217b3e6c251fba5971a5e58a68127813be7a6005b3cf1758731cf25c5
|
data/README.md
CHANGED
|
@@ -31,11 +31,9 @@ post.json
|
|
|
31
31
|
```ruby
|
|
32
32
|
require 'ruson'
|
|
33
33
|
|
|
34
|
-
class Post < Ruson::Base
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
field :content
|
|
38
|
-
end
|
|
34
|
+
class Post < Ruson::Base
|
|
35
|
+
field :title
|
|
36
|
+
field :content
|
|
39
37
|
end
|
|
40
38
|
|
|
41
39
|
json = File.read('post.json')
|
|
@@ -58,10 +56,8 @@ post.json
|
|
|
58
56
|
require 'ruson'
|
|
59
57
|
|
|
60
58
|
class Post < Ruson::Base
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
field :url, name: 'post_url'
|
|
64
|
-
end
|
|
59
|
+
field :title
|
|
60
|
+
field :url, name: 'post_url'
|
|
65
61
|
end
|
|
66
62
|
|
|
67
63
|
json = File.read('post.json')
|
|
@@ -89,17 +85,13 @@ post.json
|
|
|
89
85
|
require 'ruson'
|
|
90
86
|
|
|
91
87
|
class Post < Ruson::Base
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
field :picture, class: Picture
|
|
95
|
-
end
|
|
88
|
+
field :title
|
|
89
|
+
field :picture, class: Picture
|
|
96
90
|
end
|
|
97
91
|
|
|
98
92
|
class Picture < Ruson::Base
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
field :url
|
|
102
|
-
end
|
|
93
|
+
field :title
|
|
94
|
+
field :url
|
|
103
95
|
end
|
|
104
96
|
|
|
105
97
|
json = File.read('post.json')
|
|
@@ -128,16 +120,12 @@ post.json
|
|
|
128
120
|
require 'ruson'
|
|
129
121
|
|
|
130
122
|
class Post < Ruson::Base
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
field :tags, each_class: Tag
|
|
134
|
-
end
|
|
123
|
+
field :title
|
|
124
|
+
field :tags, each_class: Tag
|
|
135
125
|
end
|
|
136
126
|
|
|
137
127
|
class Tag < Ruson::Base
|
|
138
|
-
|
|
139
|
-
field :name
|
|
140
|
-
end
|
|
128
|
+
field :name
|
|
141
129
|
end
|
|
142
130
|
|
|
143
131
|
json = File.read('post.json')
|
data/lib/ruson/base.rb
CHANGED
|
@@ -1,24 +1,34 @@
|
|
|
1
1
|
require 'json'
|
|
2
|
+
require 'active_support'
|
|
3
|
+
require 'active_support/core_ext'
|
|
2
4
|
|
|
3
5
|
module Ruson
|
|
4
6
|
class Base
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
fields
|
|
10
|
-
end
|
|
7
|
+
class << self
|
|
8
|
+
def field(attr, options = {})
|
|
9
|
+
add_accessor attr.to_s, options
|
|
10
|
+
end
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
def add_accessor(name, options)
|
|
13
|
+
instance_eval("attr_accessor :#{name}")
|
|
14
|
+
@accessors ||= {}
|
|
15
|
+
@accessors.merge!({ name.to_sym => options })
|
|
16
|
+
end
|
|
13
17
|
|
|
18
|
+
def accessors
|
|
19
|
+
@accessors
|
|
20
|
+
end
|
|
14
21
|
end
|
|
15
22
|
|
|
16
|
-
def
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
def initialize(json, options = {})
|
|
24
|
+
params = convert(json)
|
|
25
|
+
params = params[options[:root].to_s] unless options[:root].nil?
|
|
26
|
+
@params = params
|
|
27
|
+
|
|
28
|
+
self.class.accessors.each do |key, options|
|
|
29
|
+
val = get_val(options[:name] || key, options)
|
|
30
|
+
set_attribute(key, val)
|
|
31
|
+
end
|
|
22
32
|
end
|
|
23
33
|
|
|
24
34
|
private
|
|
@@ -51,8 +61,8 @@ module Ruson
|
|
|
51
61
|
end
|
|
52
62
|
|
|
53
63
|
def convert(json)
|
|
54
|
-
return json if json.class ==
|
|
55
|
-
JSON.parse(json)
|
|
64
|
+
return json if json.class == ActiveSupport::HashWithIndifferentAccess
|
|
65
|
+
(json.class == Hash ? json : JSON.parse(json)).with_indifferent_access
|
|
56
66
|
end
|
|
57
67
|
end
|
|
58
|
-
end
|
|
68
|
+
end
|
data/lib/ruson/version.rb
CHANGED
data/ruson.gemspec
CHANGED
|
@@ -4,15 +4,15 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
|
4
4
|
require "ruson/version"
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |spec|
|
|
7
|
-
spec.name
|
|
8
|
-
spec.version
|
|
9
|
-
spec.authors
|
|
10
|
-
spec.email
|
|
7
|
+
spec.name = "ruson"
|
|
8
|
+
spec.version = Ruson::VERSION
|
|
9
|
+
spec.authors = ["klriutsa"]
|
|
10
|
+
spec.email = ["hiroya.kurushima@litalico.co.jp"]
|
|
11
11
|
|
|
12
|
-
spec.summary
|
|
13
|
-
spec.description
|
|
14
|
-
spec.homepage
|
|
15
|
-
spec.license
|
|
12
|
+
spec.summary = %q{ruby json library.}
|
|
13
|
+
spec.description = %q{ruby json library.}
|
|
14
|
+
spec.homepage = "https://github.com/klriutsa/ruson"
|
|
15
|
+
spec.license = "MIT"
|
|
16
16
|
|
|
17
17
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
18
18
|
f.match(%r{^(test|spec|features)/})
|
|
@@ -24,4 +24,5 @@ Gem::Specification.new do |spec|
|
|
|
24
24
|
spec.add_development_dependency "bundler", "~> 1.15"
|
|
25
25
|
spec.add_development_dependency "rake", "~> 10.0"
|
|
26
26
|
spec.add_development_dependency "rspec", "~> 3.0"
|
|
27
|
+
spec.add_development_dependency 'activesupport'
|
|
27
28
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ruson
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- klriutsa
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2018-08-28 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -52,6 +52,20 @@ dependencies:
|
|
|
52
52
|
- - "~>"
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
54
|
version: '3.0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: activesupport
|
|
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'
|
|
55
69
|
description: ruby json library.
|
|
56
70
|
email:
|
|
57
71
|
- hiroya.kurushima@litalico.co.jp
|
|
@@ -93,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
93
107
|
version: '0'
|
|
94
108
|
requirements: []
|
|
95
109
|
rubyforge_project:
|
|
96
|
-
rubygems_version: 2.
|
|
110
|
+
rubygems_version: 2.7.7
|
|
97
111
|
signing_key:
|
|
98
112
|
specification_version: 4
|
|
99
113
|
summary: ruby json library.
|