api-model 2.0.0 → 2.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6909e3c913be60c743cfef5babb4dadbe0852ece
4
- data.tar.gz: db89536d66181112df8fbf7e5ab0589f37f3c56b
3
+ metadata.gz: 441ff23f2ba1d0707bea80f456c2caf35c41dc54
4
+ data.tar.gz: ed85061b54a94ec9926fc751cdf463d4375f8ec5
5
5
  SHA512:
6
- metadata.gz: 2ae38b790d32233392a537d88cd152f39332e69fa46ae160fb1b40ac9397d8178ed379f3e459650c8a09d56ca6af61f5b1ec9e79273d5ea8f352aad23e0121f8
7
- data.tar.gz: 8c2a47a297bf712bfc3e782b55b342d9de0d311d6a9f6128358c845ba0a6678d8b12487211f4010b7829e264b9059c7891112b92fa6a3da573b837c1e515af8a
6
+ metadata.gz: b3e73a8350c7cd81d6ac243df0b730787fad37bf0d37fa31e7a9b2c4a3342fd8b00911f50edd2b6abbb0e02cab9b38c033faab27d45498e219db6a4866e3be47
7
+ data.tar.gz: 37c55e14a6d3d580a91904737155964388759c96d5d858b2cf063c1be4bd09825024da52b7f9207beb249e26917f69267d37c75bc95d0d6778957f6dfa0450bc
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- api-model (2.0.0)
4
+ api-model (2.0.1)
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.0.0"
5
+ s.version = "2.0.1"
6
6
  s.authors = ["Damien Timewell"]
7
7
  s.email = ["mail@damientimewell.com"]
8
8
  s.licenses = ['MIT']
@@ -4,12 +4,18 @@ module ApiModel
4
4
 
5
5
  included do
6
6
  extend ActiveModel::Callbacks
7
- define_model_callbacks :save, :successful_save, :unsuccessful_save
7
+ define_model_callbacks :save, :successful_save, :unsuccessful_save, :initialize
8
8
 
9
9
  attribute :persisted, Axiom::Types::Boolean, default: false
10
10
  alias_method :persisted?, :persisted
11
11
  end
12
12
 
13
+ def initialize(attributes = nil)
14
+ run_callbacks :initialize do
15
+ super attributes
16
+ end
17
+ end
18
+
13
19
  # Convenience method to handle error hashes and set them as ActiveModel errors on instances.
14
20
  # Using the `obj`, you can move the errors on to child classes if needed.
15
21
  def set_errors_from_hash(errors_hash, obj = self)
@@ -243,10 +243,12 @@ describe ApiModel do
243
243
  after_save :saved
244
244
  after_successful_save :yay_it_saved
245
245
  after_unsuccessful_save :oh_no_it_didnt_save
246
+ after_initialize :initialized
246
247
 
247
248
  def saved; end
248
249
  def yay_it_saved; end
249
250
  def oh_no_it_didnt_save; end
251
+ def initialized; end
250
252
  end
251
253
 
252
254
  it 'should run a callback around the whole save method' do
@@ -263,6 +265,11 @@ describe ApiModel do
263
265
  blog_post.should_receive(:oh_no_it_didnt_save).once
264
266
  VCR.use_cassette('posts') { blog_post.save "/post/with_errors", name: "" }
265
267
  end
268
+
269
+ it 'should run a callback on initialize' do
270
+ BlogPost.any_instance.should_receive(:initialized).once
271
+ BlogPost.new
272
+ end
266
273
  end
267
274
  end
268
275
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api-model
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damien Timewell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-10 00:00:00.000000000 Z
11
+ date: 2014-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport