api-model 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/api-model.gemspec +1 -1
- data/lib/api_model/instance_methods.rb +7 -1
- data/spec/api-model/api_model_spec.rb +7 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 441ff23f2ba1d0707bea80f456c2caf35c41dc54
|
4
|
+
data.tar.gz: ed85061b54a94ec9926fc751cdf463d4375f8ec5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3e73a8350c7cd81d6ac243df0b730787fad37bf0d37fa31e7a9b2c4a3342fd8b00911f50edd2b6abbb0e02cab9b38c033faab27d45498e219db6a4866e3be47
|
7
|
+
data.tar.gz: 37c55e14a6d3d580a91904737155964388759c96d5d858b2cf063c1be4bd09825024da52b7f9207beb249e26917f69267d37c75bc95d0d6778957f6dfa0450bc
|
data/Gemfile.lock
CHANGED
data/api-model.gemspec
CHANGED
@@ -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.
|
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-
|
11
|
+
date: 2014-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|