requisite 0.3.0 → 0.4.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: 718f7a0ac2ca20c100cf6e5c119c4a9b4bafd5f4
4
- data.tar.gz: 0da1427c7209923071d6667610ddc6473a2464fa
3
+ metadata.gz: d6b64e1b0c71c849d17375adc03eb2704586aa34
4
+ data.tar.gz: fb200944d39969a6b5d3e61d76e37803812ed98b
5
5
  SHA512:
6
- metadata.gz: c5b84bf2d04e682405cb7aac06bb6ef786b12c6976cda1bed69fa7aefbba941b4e97e6bbe8ca0c0bf3e84cab14d3ef637a65cbf5bdade19dfeac39c9e373b761
7
- data.tar.gz: 5c218d74d921330a280d908bc5cf7683408ad0a32e9685b5f95a99c8961de0fba6f03f8dddbb1e7d7f4411ef5302e203de045bf7361cd5291777c8f1e886adb7
6
+ metadata.gz: d6cf2087d2ee9dae26585859335529305b3e3852ec977f1814d8db1e919f47143e5a70a8e488f5df36ca2fda329a3a0e6e3111375aa10319897bc8163c54febc
7
+ data.tar.gz: 5800a2eb21bb387067cfad863a654fde52d988f0a11084e3e946b60755ac1b5c1ad2da5ef8edba1d8c23a96a74985f33b00ea89108d717eab1e145b85ca86048
data/Gemfile.lock ADDED
@@ -0,0 +1,63 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ requisite (0.4.0)
5
+ actionpack (>= 4.2.0)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ actionpack (5.1.5)
11
+ actionview (= 5.1.5)
12
+ activesupport (= 5.1.5)
13
+ rack (~> 2.0)
14
+ rack-test (>= 0.6.3)
15
+ rails-dom-testing (~> 2.0)
16
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
17
+ actionview (5.1.5)
18
+ activesupport (= 5.1.5)
19
+ builder (~> 3.1)
20
+ erubi (~> 1.4)
21
+ rails-dom-testing (~> 2.0)
22
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
23
+ activesupport (5.1.5)
24
+ concurrent-ruby (~> 1.0, >= 1.0.2)
25
+ i18n (~> 0.7)
26
+ minitest (~> 5.1)
27
+ tzinfo (~> 1.1)
28
+ builder (3.2.3)
29
+ concurrent-ruby (1.0.5)
30
+ crass (1.0.3)
31
+ erubi (1.7.1)
32
+ i18n (0.9.5)
33
+ concurrent-ruby (~> 1.0)
34
+ loofah (2.2.1)
35
+ crass (~> 1.0.2)
36
+ nokogiri (>= 1.5.9)
37
+ mini_portile2 (2.3.0)
38
+ minitest (5.11.3)
39
+ nokogiri (1.8.2)
40
+ mini_portile2 (~> 2.3.0)
41
+ rack (2.0.4)
42
+ rack-test (0.8.3)
43
+ rack (>= 1.0, < 3)
44
+ rails-dom-testing (2.0.3)
45
+ activesupport (>= 4.2.0)
46
+ nokogiri (>= 1.6)
47
+ rails-html-sanitizer (1.0.3)
48
+ loofah (~> 2.0)
49
+ rake (12.3.0)
50
+ thread_safe (0.3.6)
51
+ tzinfo (1.2.5)
52
+ thread_safe (~> 0.1)
53
+
54
+ PLATFORMS
55
+ ruby
56
+
57
+ DEPENDENCIES
58
+ minitest
59
+ rake
60
+ requisite!
61
+
62
+ BUNDLED WITH
63
+ 1.16.1
data/lib/requisite.rb CHANGED
@@ -4,3 +4,4 @@ require 'requisite/boolean'
4
4
  require 'requisite/api_model'
5
5
  require 'requisite/bad_request_error'
6
6
  require 'requisite/bad_type_error'
7
+ require 'action_controller'
@@ -5,7 +5,14 @@ module Requisite
5
5
  attr_reader :model
6
6
 
7
7
  def initialize(model={})
8
- @model = model.kind_of?(Hash) ? Hash[model.map{ |k, v| [k.to_sym, v] }] : model
8
+ @model = case model
9
+ when ActionController::Parameters
10
+ Hash[model.to_unsafe_h.map { |k, v| [k.to_sym, v] }]
11
+ when Hash
12
+ Hash[model.map { |k, v| [k.to_sym, v] }]
13
+ else
14
+ model
15
+ end
9
16
  end
10
17
 
11
18
  def convert(name)
@@ -28,9 +35,9 @@ module Requisite
28
35
  def to_hash(show_nil: false)
29
36
  preprocess_model
30
37
  {}.tap do |result|
31
- self.class.attribute_keys_with_inheritance.each do |meth|
32
- value = self.send(meth)
33
- result.merge!({meth => value}) if show_nil || !value.nil?
38
+ self.class.attribute_keys_with_inheritance.each do |key|
39
+ value = self.send(key)
40
+ result[key] = value if show_nil || !value.nil?
34
41
  end
35
42
  end
36
43
  end
@@ -88,7 +95,6 @@ module Requisite
88
95
  nil
89
96
  end
90
97
 
91
-
92
98
  def model_responds_to_attribute_query?(name)
93
99
  if @model.kind_of?(Hash)
94
100
  @model[name] != nil
@@ -97,10 +103,6 @@ module Requisite
97
103
  end
98
104
  end
99
105
 
100
- def merge_attribute_if_exists!(to_merge, attribute_name)
101
- attribute_from_model(attribute_name) ? to_merge.merge!(attribute_from_model(attribute_name)) : to_merge
102
- end
103
-
104
106
  def preprocess_model
105
107
  # noop
106
108
  end
@@ -15,7 +15,7 @@ module Requisite
15
15
  result
16
16
  end
17
17
  end
18
-
18
+
19
19
  def attribute!(name, options={})
20
20
  attribute_keys << name
21
21
  define_method(name) do
@@ -29,7 +29,7 @@ module Requisite
29
29
  result
30
30
  end
31
31
  end
32
-
32
+
33
33
  def serialized_attributes(&block)
34
34
  @attribute_keys = []
35
35
  instance_eval(&block)
@@ -45,10 +45,10 @@ module Requisite
45
45
  end
46
46
 
47
47
  private
48
-
48
+
49
49
  self.singleton_class.send(:alias_method, :a, :attribute)
50
50
  self.singleton_class.send(:alias_method, :a!, :attribute!)
51
-
51
+
52
52
  def raise_bad_type_if_type_mismatch(value, desired_type)
53
53
  raise BadTypeError.new(value, desired_type) unless (value.kind_of?(desired_type)) || ((value.kind_of?(TrueClass) || value.kind_of?(TrueClass)) && desired_type == Requisite::Boolean)
54
54
  end
@@ -56,7 +56,7 @@ module Requisite
56
56
  def raise_not_implemented_for_attribute(name)
57
57
  raise NotImplementedError.new("'#{name}' method not implemented")
58
58
  end
59
-
59
+
60
60
  def empty_result?(result)
61
61
  result.nil? || result == {}
62
62
  end
@@ -1,3 +1,3 @@
1
1
  module Requisite
2
- VERSION = '0.3.0'
2
+ VERSION = '0.4.0'
3
3
  end
data/requisite.gemspec CHANGED
@@ -13,6 +13,8 @@ Gem::Specification.new do |gem|
13
13
  gem.homepage = 'https://www.intercom.io'
14
14
  gem.license = 'Apache License Version 2.0'
15
15
  gem.add_development_dependency "minitest"
16
+ gem.add_development_dependency "rake"
17
+ gem.add_runtime_dependency "actionpack", ">= 4.2.0"
16
18
  gem.files = `git ls-files`.split($/)
17
19
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
20
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
@@ -180,6 +180,13 @@ module Requisite
180
180
  response.to_hash.must_equal(:num => 12)
181
181
  end
182
182
 
183
+ it 'works with ActionController::Parameters' do
184
+ DummyApiModel.serialized_attributes { attribute :num }
185
+ params = ActionController::Parameters.new(num: 12)
186
+ response = DummyApiModel.new(params)
187
+ response.to_hash.must_equal(:num => 12)
188
+ end
189
+
183
190
  describe 'with nested structures' do
184
191
 
185
192
  describe 'with typed arrays' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: requisite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Osler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-15 00:00:00.000000000 Z
11
+ date: 2018-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -24,6 +24,34 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
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: actionpack
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 4.2.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 4.2.0
27
55
  description: " Requisite is an elegant way of strongly defining request and response
28
56
  models for serialization "
29
57
  email:
@@ -35,6 +63,7 @@ files:
35
63
  - ".gitignore"
36
64
  - CHANGES.md
37
65
  - Gemfile
66
+ - Gemfile.lock
38
67
  - LICENCE.txt
39
68
  - README.md
40
69
  - Rakefile
@@ -70,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
99
  version: '0'
71
100
  requirements: []
72
101
  rubyforge_project:
73
- rubygems_version: 2.2.2
102
+ rubygems_version: 2.5.2.2
74
103
  signing_key:
75
104
  specification_version: 4
76
105
  summary: Strongly defined models for HTTP APIs
@@ -79,4 +108,3 @@ test_files:
79
108
  - test/requisite/api_model_test.rb
80
109
  - test/requisite/api_user_test.rb
81
110
  - test/test_helper.rb
82
- has_rdoc: