json_parser 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e1c0ec98b84cd4dbc53f82baaa96fc9afd618e38
4
- data.tar.gz: 78537b728d6fa5882fa5c269a275e1b7ab7814ea
3
+ metadata.gz: ac23553db9c63acec489ac62b9195861e901dc7b
4
+ data.tar.gz: a494a82d7968db4b2586a37d3680c73de98cdab6
5
5
  SHA512:
6
- metadata.gz: f6d2d5d2de986c62f3756c508b315d2406925f67f77d76e66c40d69304a386dc52392c10928a9e2360ea7db3143929e8bc0c3c327814f1a3f3f3761a60d44b42
7
- data.tar.gz: a8dd328d05d745eec9a79ba26fdd5978aff4fe9c831164e0cddfeccf961ba3851f629702ea683bb58c0470fe48b45a2b503406e489aac021e4ca9cb1a21426f6
6
+ metadata.gz: b1ba7ad9cad67a33477b769b6cd5621838a43c51fa16a7b507553db62b858d204f7e17630e7ad6ff7c80403024ca891c34c5807b58fa2ce592d872cca549de50
7
+ data.tar.gz: fad6348f9efe83a8752ab395ce8eb6c6b7475106de46cedaf7a4d881080dd8217da57f551c0167df0af118e2ec43d124aa8c1d39ca8a426090bbc5c029ebbb2b
@@ -0,0 +1,13 @@
1
+ version: 2
2
+ jobs:
3
+ build:
4
+ docker:
5
+ - image: circleci/ruby:2.4.1
6
+ steps:
7
+ - checkout
8
+ - run: curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
9
+ - run: chmod +x ./cc-test-reporter
10
+ - run: ./cc-test-reporter before-build
11
+ - run: bundle install
12
+ - run: bundle exec rspec
13
+ - run: ./cc-test-reporter after-build --exit-code $?
data/.gitignore CHANGED
@@ -1 +1,3 @@
1
1
  coverage
2
+ Gemfile.lock
3
+
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
- The MIT License (MIT)
1
+ MIT License
2
2
 
3
- Copyright (c) 2015 Bidu.com.br
3
+ Copyright (c) 2017 Favini
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -19,4 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
22
-
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  Json Parser
2
2
  ========
3
+ [![Code Climate](https://codeclimate.com/github/darthjee/json_parser/badges/gpa.svg)](https://codeclimate.com/github/darthjee/json_parser)
4
+ [![Test Coverage](https://codeclimate.com/github/darthjee/json_parser/badges/coverage.svg)](https://codeclimate.com/github/darthjee/json_parser/coverage)
5
+ [![Issue Count](https://codeclimate.com/github/darthjee/json_parser/badges/issue_count.svg)](https://codeclimate.com/github/darthjee/json_parser)
3
6
 
4
7
  This project allows for a quick hash / json data fetching in order to avoid code
5
8
  that tries to crawl through a hash and has to constantly check for nil values or missing keys
@@ -0,0 +1,18 @@
1
+ version: '2'
2
+ services:
3
+ base: &base
4
+ image: ruby:2.4.0
5
+ working_dir: /home/app/json_parser
6
+ volumes:
7
+ - .:/home/app/json_parser
8
+ - json_parser_gems_2_4_0:/usr/local/bundle
9
+
10
+ #################### CONTAINERS ####################
11
+
12
+ json_parser:
13
+ <<: *base
14
+ container_name: json_parser
15
+ command: /bin/bash -c 'bundle install && bundle exec rspec'
16
+
17
+ volumes:
18
+ json_parser_gems_2_4_0:
@@ -17,12 +17,13 @@ Gem::Specification.new do |spec|
17
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
18
  spec.require_paths = ["lib"]
19
19
 
20
- spec.add_runtime_dependency 'activesupport'
21
- spec.add_runtime_dependency 'concern_builder'
20
+ spec.add_runtime_dependency 'activesupport', '~> 5.x'
21
+ spec.add_runtime_dependency 'sinclair'
22
22
 
23
23
  spec.add_development_dependency 'safe_attribute_assignment'
24
24
  spec.add_development_dependency "bundler", "~> 1.6"
25
- spec.add_development_dependency "rake"
26
- spec.add_development_dependency "rspec", "~> 2.14"
25
+ spec.add_development_dependency "rake", ">= 12.3.1"
26
+ spec.add_development_dependency "rspec", ">= 3.7"
27
27
  spec.add_development_dependency 'simplecov'
28
+ spec.add_development_dependency 'pry-nav'
28
29
  end
@@ -1,15 +1,14 @@
1
1
  require 'active_support'
2
2
  require 'active_support/all'
3
- require 'concern_builder'
3
+ require 'sinclair'
4
4
 
5
5
  module JsonParser
6
6
  extend ActiveSupport::Concern
7
7
 
8
- require 'json_parser/type_cast'
9
- require 'json_parser/version'
10
- require 'json_parser/crawler'
11
- require 'json_parser/wrapper'
12
- require 'json_parser/fetcher'
13
- require 'json_parser/class_methods'
14
- require 'json_parser/class_methods/builder'
8
+ autoload :TypeCast, 'json_parser/type_cast'
9
+ autoload :Crawler, 'json_parser/crawler'
10
+ autoload :Wrapper, 'json_parser/wrapper'
11
+ autoload :Fetcher, 'json_parser/fetcher'
12
+ autoload :ClassMethods, 'json_parser/class_methods'
13
+ autoload :Builder, 'json_parser/builder'
15
14
  end
@@ -0,0 +1,74 @@
1
+ class JsonParser::Builder < Sinclair
2
+
3
+ attr_reader :attr_names
4
+
5
+ def initialize(attr_names, clazz, options)
6
+ super(clazz, {
7
+ path: nil,
8
+ json: :json,
9
+ full_path: nil,
10
+ cached: false,
11
+ class: nil,
12
+ compact: false,
13
+ flatten: false,
14
+ after: false,
15
+ case: :lower_camel,
16
+ type: :none
17
+ }.merge(options.symbolize_keys))
18
+
19
+ @attr_names = attr_names
20
+ init
21
+ end
22
+
23
+ private
24
+
25
+ delegate :path, :full_path, :cached, :compact,
26
+ :type, :after, to: :options_object
27
+
28
+ def init
29
+ attr_names.each do |attr|
30
+ add_attr(attr)
31
+ end
32
+ end
33
+
34
+ def json_name
35
+ options[:json]
36
+ end
37
+
38
+ def real_path(attribute)
39
+ full_path || [path, attribute].compact.join('.')
40
+ end
41
+
42
+ def wrapper_clazz
43
+ options[:class]
44
+ end
45
+
46
+ def case_type
47
+ options[:case]
48
+ end
49
+
50
+ def fetcher_options
51
+ options.slice(:compact, :after, :type, :flatten).merge({
52
+ clazz: wrapper_clazz,
53
+ case_type: case_type
54
+ })
55
+ end
56
+
57
+ def add_attr(attribute)
58
+ add_method attribute, "#{cached ? cached_fetcher(attribute) : attr_fetcher(attribute)}"
59
+ end
60
+
61
+ def attr_fetcher(attribute)
62
+ <<-CODE
63
+ ::JsonParser::Fetcher.new(
64
+ #{json_name}, '#{real_path(attribute)}', self, #{fetcher_options}
65
+ ).fetch
66
+ CODE
67
+ end
68
+
69
+ def cached_fetcher(attribute)
70
+ <<-CODE
71
+ @#{attribute} ||= #{attr_fetcher(attribute)}
72
+ CODE
73
+ end
74
+ end
@@ -1,20 +1,10 @@
1
- module JsonParser::ClassMethods
1
+ module JsonParser
2
+ module ClassMethods
3
+ def json_parse(*attr_names)
4
+ options = attr_names.extract_options!
2
5
 
3
- def json_parse(*attr_names)
4
- options = {
5
- path: nil,
6
- json: :json,
7
- full_path: nil,
8
- cached: false,
9
- class: nil,
10
- compact: false,
11
- flatten: false,
12
- after: false,
13
- case: :lower_camel,
14
- type: :none
15
- }.merge(attr_names.extract_options!)
16
-
17
- builder = Builder.new(attr_names, self, options)
18
- builder.build
6
+ builder = Builder.new(attr_names, self, options)
7
+ builder.build
8
+ end
19
9
  end
20
10
  end
@@ -1,5 +1,5 @@
1
1
  class JsonParser::Crawler
2
- include ConcernBuilder::OptionsParser
2
+ include Sinclair::OptionsParser
3
3
 
4
4
  attr_reader :post_process, :path
5
5
 
@@ -1,5 +1,5 @@
1
1
  class JsonParser::Fetcher
2
- include ConcernBuilder::OptionsParser
2
+ include Sinclair::OptionsParser
3
3
 
4
4
  attr_reader :path, :json, :instance
5
5
 
@@ -1,3 +1,3 @@
1
1
  module JsonParser
2
- VERSION = '1.1.0'
2
+ VERSION = '1.2.0'
3
3
  end
@@ -1,5 +1,5 @@
1
1
  class JsonParser::Wrapper
2
- include ConcernBuilder::OptionsParser
2
+ include Sinclair::OptionsParser
3
3
  include JsonParser::TypeCast
4
4
 
5
5
  delegate :clazz, :type, to: :options_object
@@ -0,0 +1,116 @@
1
+ require 'spec_helper'
2
+
3
+ describe JsonParser::Builder do
4
+ let(:clazz) do
5
+ Class.new.tap do |c|
6
+ c.send(:attr_reader, :json)
7
+ c.send(:define_method, :initialize) do |json={}|
8
+ @json = json
9
+ end
10
+ end
11
+ end
12
+
13
+ let(:options) { {} }
14
+ let(:name) { 'Robert' }
15
+ let(:attr_name) { :name }
16
+ let(:attr_names) { [ attr_name ] }
17
+ let(:json) { {} }
18
+ let(:instance) { clazz.new(json) }
19
+
20
+ subject do
21
+ described_class.new(attr_names, clazz, options)
22
+ end
23
+
24
+ describe '#build' do
25
+ it 'adds the reader' do
26
+ expect do
27
+ subject.build
28
+ end.to change { clazz.new.respond_to?(attr_name) }
29
+ end
30
+
31
+ context 'after building' do
32
+ before { subject.build }
33
+
34
+ context 'when building several attributes' do
35
+ let(:attr_names) { [ :id, :name, :age ] }
36
+
37
+ it 'adds all the readers' do
38
+ attr_names.each do |attr|
39
+ expect(instance).to respond_to(attr)
40
+ end
41
+ end
42
+
43
+ it 'fetches safelly empty jsons' do
44
+ expect(instance.name).to be_nil
45
+ end
46
+
47
+ context 'when json has the property' do
48
+ let(:json) { { name: name } }
49
+
50
+ it 'fetches the value' do
51
+ expect(instance.name).to eq(name)
52
+ end
53
+
54
+ context 'but key is a string' do
55
+ let(:json) { { 'name' => name } }
56
+
57
+ it 'fetches the value' do
58
+ expect(instance.name).to eq(name)
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ context 'when value is deep within the json' do
65
+ let(:json) { { user: { name: name } } }
66
+
67
+ context 'when defining a path' do
68
+ let(:options) { { path: 'user' } }
69
+
70
+ it 'fetches the value within the json' do
71
+ expect(instance.name).to eq(name)
72
+ end
73
+ end
74
+
75
+ context 'when defining a fullpath' do
76
+ let(:options) { { full_path: 'user.name' } }
77
+ let(:attr_name) { :the_name }
78
+
79
+ it 'fetches the value within the json' do
80
+ expect(instance.the_name).to eq(name)
81
+ end
82
+
83
+ context 'when option key is a string' do
84
+ let(:options) { { 'full_path' => 'user.name' } }
85
+
86
+ it 'fetches the value within the json' do
87
+ expect(instance.the_name).to eq(name)
88
+ end
89
+ end
90
+ end
91
+ end
92
+
93
+ context 'when wrapping with a class' do
94
+ let(:json) { { person: name } }
95
+ let(:options) { { class: JsonParser::Person } }
96
+ let(:attr_name) { :person }
97
+
98
+ it do
99
+ expect(instance.person).to be_a(JsonParser::Person)
100
+ end
101
+
102
+ it 'fills the new instance with the information fetched' do
103
+ expect(instance.person.name).to eq(name)
104
+ end
105
+
106
+ context 'when option key is a string' do
107
+ let(:options) { { 'class' => JsonParser::Person } }
108
+
109
+ it 'fills the new instance with the information fetched' do
110
+ expect(instance.person.name).to eq(name)
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end
116
+ end
@@ -1,54 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe JsonParser do
4
- class JsonParser::House
5
- include JsonParser
6
- include ::SafeAttributeAssignment
7
- attr_reader :json
8
-
9
- json_parse :age, :value, :floors
10
-
11
- def initialize(json)
12
- @json = json
13
- end
14
- end
15
-
16
- class JsonParser::Game
17
- include JsonParser
18
- include SafeAttributeAssignment
19
- attr_reader :json
20
-
21
- json_parse :name, :publisher
22
-
23
- def initialize(json)
24
- @json = json
25
- end
26
- end
27
-
28
- class JsonParser::Dummy
29
- include JsonParser
30
- attr_reader :json
31
-
32
- json_parse :id
33
- json_parse :name, path: 'user'
34
- json_parse :father_name, full_path: 'father.name'
35
- json_parse :age, cached: true
36
- json_parse :house, class: JsonParser::House
37
- json_parse :old_house, class: JsonParser::House, cached: true
38
- json_parse :games, class: JsonParser::Game
39
- json_parse :games_filtered, class: JsonParser::Game, after: :filter_games, full_path: 'games'
40
-
41
- def initialize(json)
42
- @json = json
43
- end
44
-
45
- def filter_games(games)
46
- games.select do |g|
47
- g.publisher != 'sega'
48
- end
49
- end
50
- end
51
-
52
4
  let(:dummy) { JsonParser::Dummy.new(json) }
53
5
  let(:json) { load_json_fixture_file('json_parser.json') }
54
6
  let(:value) { dummy.public_send(attribute) }
@@ -1,9 +1,16 @@
1
1
  require 'simplecov'
2
2
  SimpleCov.start
3
3
 
4
+ require 'pry-nav'
4
5
  require 'json_parser'
5
6
  require 'safe_attribute_assignment'
6
7
 
8
+ module JsonParser
9
+ models = File.expand_path("spec/support/models/*.rb")
10
+ Dir[models].each do |file|
11
+ autoload file.gsub(/.*\/(.*)\..*/, '\1').camelize.to_sym, file
12
+ end
13
+ end
7
14
  support_files = File.expand_path("spec/support/**/*.rb")
8
15
  Dir[support_files].each { |file| require file }
9
16
 
@@ -0,0 +1,23 @@
1
+ class JsonParser::Dummy
2
+ include JsonParser
3
+ attr_reader :json
4
+
5
+ json_parse :id
6
+ json_parse :name, path: 'user'
7
+ json_parse :father_name, full_path: 'father.name'
8
+ json_parse :age, cached: true
9
+ json_parse :house, class: JsonParser::House
10
+ json_parse :old_house, class: JsonParser::House, cached: true
11
+ json_parse :games, class: JsonParser::Game
12
+ json_parse :games_filtered, class: JsonParser::Game, after: :filter_games, full_path: 'games'
13
+
14
+ def initialize(json)
15
+ @json = json
16
+ end
17
+
18
+ def filter_games(games)
19
+ games.select do |g|
20
+ g.publisher != 'sega'
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,11 @@
1
+ class JsonParser::Game
2
+ include JsonParser
3
+ include SafeAttributeAssignment
4
+ attr_reader :json
5
+
6
+ json_parse :name, :publisher
7
+
8
+ def initialize(json)
9
+ @json = json
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ class JsonParser::House
2
+ include JsonParser
3
+ include ::SafeAttributeAssignment
4
+ attr_reader :json
5
+
6
+ json_parse :age, :value, :floors
7
+
8
+ def initialize(json)
9
+ @json = json
10
+ end
11
+ end
@@ -0,0 +1,8 @@
1
+ class JsonParser::Person
2
+ attr_reader :name
3
+
4
+ def initialize(name)
5
+ @name = name
6
+ end
7
+ end
8
+
metadata CHANGED
@@ -1,111 +1,125 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bidu Dev's Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-06 00:00:00.000000000 Z
11
+ date: 2018-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 5.x
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 5.x
27
27
  - !ruby/object:Gem::Dependency
28
- name: concern_builder
28
+ name: sinclair
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: safe_attribute_assignment
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '1.6'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.6'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 12.3.1
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: 12.3.1
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rspec
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ~>
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: '2.14'
89
+ version: '3.7'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ~>
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
- version: '2.14'
96
+ version: '3.7'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: simplecov
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - '>='
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry-nav
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
102
116
  - !ruby/object:Gem::Version
103
117
  version: '0'
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
- - - '>='
122
+ - - ">="
109
123
  - !ruby/object:Gem::Version
110
124
  version: '0'
111
125
  description: ''
@@ -115,30 +129,36 @@ executables: []
115
129
  extensions: []
116
130
  extra_rdoc_files: []
117
131
  files:
118
- - .gitignore
119
- - .rspec
132
+ - ".circleci/config.yml"
133
+ - ".gitignore"
134
+ - ".rspec"
120
135
  - Gemfile
121
- - Gemfile.lock
122
136
  - Guardfile
123
137
  - LICENSE
124
138
  - README.md
125
139
  - Rakefile
140
+ - docker-compose.yml
126
141
  - json_parser.gemspec
127
142
  - lib/json_parser.rb
143
+ - lib/json_parser/builder.rb
128
144
  - lib/json_parser/class_methods.rb
129
- - lib/json_parser/class_methods/builder.rb
130
145
  - lib/json_parser/crawler.rb
131
146
  - lib/json_parser/fetcher.rb
132
147
  - lib/json_parser/type_cast.rb
133
148
  - lib/json_parser/version.rb
134
149
  - lib/json_parser/wrapper.rb
135
150
  - spec/fixtures/json_parser.json
151
+ - spec/lib/json_parser/builder_spec.rb
136
152
  - spec/lib/json_parser/crawler_spec.rb
137
153
  - spec/lib/json_parser/fetcher_spec.rb
138
154
  - spec/lib/json_parser/wrapper_spec.rb
139
155
  - spec/lib/json_parser_spec.rb
140
156
  - spec/spec_helper.rb
141
157
  - spec/support/fixture_helpers.rb
158
+ - spec/support/models/dummy.rb
159
+ - spec/support/models/game.rb
160
+ - spec/support/models/house.rb
161
+ - spec/support/models/person.rb
142
162
  - spec/support/shared_examples/wrapper.rb
143
163
  homepage: https://github.com/Bidu/json_parser
144
164
  licenses: []
@@ -149,26 +169,31 @@ require_paths:
149
169
  - lib
150
170
  required_ruby_version: !ruby/object:Gem::Requirement
151
171
  requirements:
152
- - - '>='
172
+ - - ">="
153
173
  - !ruby/object:Gem::Version
154
174
  version: '0'
155
175
  required_rubygems_version: !ruby/object:Gem::Requirement
156
176
  requirements:
157
- - - '>='
177
+ - - ">="
158
178
  - !ruby/object:Gem::Version
159
179
  version: '0'
160
180
  requirements: []
161
181
  rubyforge_project:
162
- rubygems_version: 2.4.6
182
+ rubygems_version: 2.6.11
163
183
  signing_key:
164
184
  specification_version: 4
165
185
  summary: Json Parser
166
186
  test_files:
167
187
  - spec/fixtures/json_parser.json
188
+ - spec/lib/json_parser/builder_spec.rb
168
189
  - spec/lib/json_parser/crawler_spec.rb
169
190
  - spec/lib/json_parser/fetcher_spec.rb
170
191
  - spec/lib/json_parser/wrapper_spec.rb
171
192
  - spec/lib/json_parser_spec.rb
172
193
  - spec/spec_helper.rb
173
194
  - spec/support/fixture_helpers.rb
195
+ - spec/support/models/dummy.rb
196
+ - spec/support/models/game.rb
197
+ - spec/support/models/house.rb
198
+ - spec/support/models/person.rb
174
199
  - spec/support/shared_examples/wrapper.rb
@@ -1,54 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- json_parser (1.1.0)
5
- activesupport
6
- concern_builder
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- activesupport (4.2.1)
12
- i18n (~> 0.7)
13
- json (~> 1.7, >= 1.7.7)
14
- minitest (~> 5.1)
15
- thread_safe (~> 0.3, >= 0.3.4)
16
- tzinfo (~> 1.1)
17
- concern_builder (0.0.1)
18
- activesupport
19
- diff-lcs (1.2.5)
20
- docile (1.1.5)
21
- i18n (0.7.0)
22
- json (1.8.2)
23
- minitest (5.5.1)
24
- multi_json (1.10.1)
25
- rake (10.4.2)
26
- rspec (2.99.0)
27
- rspec-core (~> 2.99.0)
28
- rspec-expectations (~> 2.99.0)
29
- rspec-mocks (~> 2.99.0)
30
- rspec-core (2.99.2)
31
- rspec-expectations (2.99.2)
32
- diff-lcs (>= 1.1.3, < 2.0)
33
- rspec-mocks (2.99.3)
34
- safe_attribute_assignment (0.0.3)
35
- activesupport
36
- simplecov (0.9.1)
37
- docile (~> 1.1.0)
38
- multi_json (~> 1.0)
39
- simplecov-html (~> 0.8.0)
40
- simplecov-html (0.8.0)
41
- thread_safe (0.3.5)
42
- tzinfo (1.2.2)
43
- thread_safe (~> 0.1)
44
-
45
- PLATFORMS
46
- ruby
47
-
48
- DEPENDENCIES
49
- bundler (~> 1.6)
50
- json_parser!
51
- rake
52
- rspec (~> 2.14)
53
- safe_attribute_assignment (= 0.0.3)
54
- simplecov
@@ -1,57 +0,0 @@
1
- class JsonParser::ClassMethods::Builder < ConcernBuilder
2
-
3
- delegate :path, :cached, :compact, :type, :after, to: :options_object
4
-
5
- private
6
-
7
- def init
8
- attr_names.each do |attr|
9
- add_attr(attr)
10
- end
11
- end
12
-
13
- def json_name
14
- options[:json]
15
- end
16
-
17
- def full_path(attribute)
18
- options[:full_path] || [path, attribute].compact.join('.')
19
- end
20
-
21
- def clazz
22
- options[:class]
23
- end
24
-
25
- def case_type
26
- options[:case]
27
- end
28
-
29
- def fetcher_options
30
- options.slice(:compact, :after, :type, :flatten).merge({
31
- clazz: clazz,
32
- case_type: case_type
33
- })
34
- end
35
-
36
- def add_attr(attribute)
37
- @methods_def << <<-CODE
38
- def #{attribute}
39
- #{cached ? cached_fetcher(attribute) : attr_fetcher(attribute)}
40
- end
41
- CODE
42
- end
43
-
44
- def attr_fetcher(attribute)
45
- <<-CODE
46
- JsonParser::Fetcher.new(
47
- #{json_name}, '#{full_path(attribute)}', self, #{fetcher_options}
48
- ).fetch
49
- CODE
50
- end
51
-
52
- def cached_fetcher(attribute)
53
- <<-CODE
54
- @#{attribute} ||= #{attr_fetcher(attribute)}
55
- CODE
56
- end
57
- end