api-model 2.3.1 → 2.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: f9c93627a25e5ed27edbdeba7fd75e973b556a17
4
- data.tar.gz: 952b794e9c4c29872063c3345381859c858509a6
3
+ metadata.gz: 1f815e2fe813c6ab61d66e7cd060c4684c38b41e
4
+ data.tar.gz: 75056c124a3c1bf7772216ddea09f824db7c1a50
5
5
  SHA512:
6
- metadata.gz: bd5b4a8a302f38b114a175ef8cd40d5d5ad7d05129c5231b950f97bdcf255d9dbf3b45cb00e4dc5143a4d73e5cfa639be86d7fad90c582062fe9c86482ee1c62
7
- data.tar.gz: 9ef3158fa99900f5c0295dba9e1b27ddb47f8f8a2bce39903b83b88309c9295ec70004cf73d05a9856e3f5a06c76eb5f3fd51f0032ecf0a98cac62af44c04a27
6
+ metadata.gz: cbfbbff8f9dea0f02b804a75d91fb697abadfef39a44e0a9531b053677f0b046b766cc66f4d410074d9bde4fb1947035ddaa33fc21ba150ffdf8022ead0df860
7
+ data.tar.gz: 695d60e37fc49ec0861516cacf1aaee650e6aa5ab5f0c3e9faf2f20d65d1a46182b4808084c4b56709219150ea8cbaac0b287596e95fd0dc52ca5833b3b64bf5
data/.travis.yml CHANGED
@@ -1,6 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
4
3
  - 2.0.0
5
4
  - 2.1.1
6
5
  - 2.1.0
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- api-model (2.3.1)
4
+ api-model (2.4.0)
5
5
  activemodel (~> 4.1)
6
6
  activesupport (~> 4.1)
7
7
  hash-pipe (~> 0.0)
data/api-model.gemspec CHANGED
@@ -2,7 +2,7 @@ $:.push File.expand_path("../lib", __FILE__)
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "api-model"
5
- s.version = "2.3.1"
5
+ s.version = "2.4.0"
6
6
  s.authors = ["Damien Timewell", "Erik Rothoff Andersson"]
7
7
  s.email = ["mail@damientimewell.com", "erik.rothoff@gmail.com"]
8
8
  s.licenses = ['MIT']
@@ -1,12 +1,21 @@
1
1
  module ApiModel
2
2
  module ClassMethods
3
3
 
4
+ def attribute_synonyms
5
+ @attribute_synonyms ||= {}
6
+ end
7
+
4
8
  def attribute_synonym(primary_method_name, *alternate_names)
5
9
  alternate_names.each do |alternate_name|
6
10
  alias_method "#{alternate_name}=".to_sym, "#{primary_method_name}=".to_sym
11
+ attribute_synonyms[alternate_name] = primary_method_name
7
12
  end
8
13
  end
9
14
 
15
+ def real_attribute_name_for(name)
16
+ attribute_synonyms[name] || name
17
+ end
18
+
10
19
  def get_json(path, params={}, options={})
11
20
  call_api :get, path, options.merge(params: params)
12
21
  end
@@ -43,7 +43,7 @@ module ApiModel
43
43
  if obj.respond_to?(field.to_sym) && obj.send(field.to_sym).respond_to?(:set_error_on_self_or_child)
44
44
  obj.send(field.to_sym).set_errors_from_hash messages
45
45
  else
46
- obj.errors.add field.to_sym, messages
46
+ obj.errors.add obj.class.real_attribute_name_for(field.to_sym), messages
47
47
  end
48
48
  end
49
49
 
@@ -83,13 +83,5 @@ module ApiModel
83
83
  end
84
84
  end
85
85
 
86
- # Returns all the defined attributes in a hash without the :persisted attribute which was added automatically.
87
- #
88
- # This is useful for when you need to pass the entire object back to an API, or if you want to serialize the object.
89
- def properties_hash
90
- ActiveSupport::Deprecation.warn "properties_hash() is deprecated and may be removed from future releases, use as_json() instead.", caller
91
- self.as_json.with_indifferent_access
92
- end
93
-
94
86
  end
95
87
  end
@@ -163,6 +163,11 @@ describe ApiModel do
163
163
  it 'should return false if errors is not a hash' do
164
164
  car.set_errors_from_hash("Foobar").should be_false
165
165
  end
166
+
167
+ it 'should set errors on the aliased method when you refer to the synonym' do
168
+ car.set_errors_from_hash numberOfDoors: "must be at least 20"
169
+ car.errors[:number_of_doors].should eq ["must be at least 20"]
170
+ end
166
171
  end
167
172
 
168
173
  describe "setting errors on nested models" do
@@ -345,25 +350,4 @@ describe ApiModel do
345
350
  end
346
351
  end
347
352
 
348
- describe "properties_hash" do
349
- let(:blog_post) { BlogPost.new title: "Foo", name: "Bar", something_else: "Baz" }
350
-
351
- it 'should return a hash' do
352
- blog_post.properties_hash.should be_a(Hash)
353
- end
354
-
355
- it 'should include attributes which are defined as properties' do
356
- blog_post.properties_hash.should have_key(:title)
357
- blog_post.properties_hash.should have_key(:name)
358
- end
359
-
360
- it 'should not include attributes which are not defined as properties' do
361
- blog_post.properties_hash.should_not have_key(:something_else)
362
- end
363
-
364
- it 'should not include the :persisted attribute, even though it is defined' do
365
- blog_post.properties_hash.should_not have_key(:persisted)
366
- end
367
- end
368
-
369
353
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api-model
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.1
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damien Timewell