record_collection 0.8.3 → 0.9.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 054699326645024b55cfe93751ecb9c85148acc0
|
4
|
+
data.tar.gz: 9d33430ffa9434454764087df7fc213c48d649d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0775171ff019a3c0b73c2dd600e22a90ca024fb258722cac298673001b4c1fb21ff933733f7f3b575c0580510db51ef14d123f210213863fd91fbff6c0f8adfa
|
7
|
+
data.tar.gz: a063173c3f263b1ac375582dac5d31bf5e4837c13a220a5914b0828816082c8a8f6731eaeef738929808aa9af3064dddc8b10170d1ed1784e30ce7423a31a7d7
|
data/CHANGELOG.md
CHANGED
@@ -103,9 +103,21 @@ module RecordCollection
|
|
103
103
|
after_blk = self.class.after_record_update
|
104
104
|
before_blk = self.class.before_record_update
|
105
105
|
each do |record|
|
106
|
-
|
106
|
+
if before_blk
|
107
|
+
if before_blk.arity.zero?
|
108
|
+
record.instance_eval(&before_blk)
|
109
|
+
else
|
110
|
+
before_blk.call(record)
|
111
|
+
end
|
112
|
+
end
|
107
113
|
record.update changed_attributes
|
108
|
-
|
114
|
+
if after_blk
|
115
|
+
if after_blk.arity.zero?
|
116
|
+
record.instance_eval(&after_blk)
|
117
|
+
else
|
118
|
+
after_blk.call(record)
|
119
|
+
end
|
120
|
+
end
|
109
121
|
end
|
110
122
|
self
|
111
123
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
class AfterRecordUpdateNoArityCollection < RecordCollection::Base
|
3
|
+
attribute :section
|
4
|
+
attribute :admin
|
5
|
+
after_record_update{ do_a_trick }
|
6
|
+
end
|
7
|
+
|
8
|
+
RSpec.describe AfterRecordUpdateNoArityCollection do
|
9
|
+
subject { described_class.new }
|
10
|
+
it "triggers the method" do
|
11
|
+
employee = Employee.create section: 'SE1', admin: false
|
12
|
+
expect( employee ).to receive :do_a_trick
|
13
|
+
described_class.new([employee]).update({})
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
class BeforeRecordUpdateNoArityCollection < RecordCollection::Base
|
3
|
+
attribute :section
|
4
|
+
attribute :admin
|
5
|
+
before_record_update{ do_a_trick }
|
6
|
+
end
|
7
|
+
|
8
|
+
RSpec.describe BeforeRecordUpdateNoArityCollection do
|
9
|
+
subject { described_class.new }
|
10
|
+
it "triggers the method" do
|
11
|
+
employee = Employee.create section: 'SE1', admin: false
|
12
|
+
expect( employee ).to receive :do_a_trick
|
13
|
+
described_class.new([employee]).update({})
|
14
|
+
end
|
15
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: record_collection
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin ter Kuile
|
@@ -399,7 +399,9 @@ files:
|
|
399
399
|
- lib/record_collection/version.rb
|
400
400
|
- record_collection.gemspec
|
401
401
|
- spec/base/accessors_spec.rb
|
402
|
+
- spec/base/after_record_update_no_arity_spec.rb
|
402
403
|
- spec/base/after_record_update_spec.rb
|
404
|
+
- spec/base/before_record_update_no_arity_spec.rb
|
403
405
|
- spec/base/before_record_update_spec.rb
|
404
406
|
- spec/base/behaviour_spec.rb
|
405
407
|
- spec/base/finding_records_spec.rb
|
@@ -517,7 +519,9 @@ specification_version: 4
|
|
517
519
|
summary: Manage collections of records in Ruby on Rails
|
518
520
|
test_files:
|
519
521
|
- spec/base/accessors_spec.rb
|
522
|
+
- spec/base/after_record_update_no_arity_spec.rb
|
520
523
|
- spec/base/after_record_update_spec.rb
|
524
|
+
- spec/base/before_record_update_no_arity_spec.rb
|
521
525
|
- spec/base/before_record_update_spec.rb
|
522
526
|
- spec/base/behaviour_spec.rb
|
523
527
|
- spec/base/finding_records_spec.rb
|