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: 6a1f2fc09b1f3aa4398ce4a15a126112e3dac101
4
- data.tar.gz: 9aa4a6bff6c18594e8f4dbabb3efd4abde222a94
3
+ metadata.gz: 054699326645024b55cfe93751ecb9c85148acc0
4
+ data.tar.gz: 9d33430ffa9434454764087df7fc213c48d649d1
5
5
  SHA512:
6
- metadata.gz: cfabb7c0d78aa856f3a10eda8260e1865d6ee83727ac717d0b0b9115b8d0c2dc573ebc40de763ed39641e91f2881cb1dfaac02767c470edc06afa4ef337205e3
7
- data.tar.gz: 8d08ada30d3c68e32f62e97df0a8e4795ab8f8050551e30ba9d81e10216b124ed85c99c78202d4a9cccf7ce48a3dc25951f08a79cfb9e163a299abeffda457ca
6
+ metadata.gz: 0775171ff019a3c0b73c2dd600e22a90ca024fb258722cac298673001b4c1fb21ff933733f7f3b575c0580510db51ef14d123f210213863fd91fbff6c0f8adfa
7
+ data.tar.gz: a063173c3f263b1ac375582dac5d31bf5e4837c13a220a5914b0828816082c8a8f6731eaeef738929808aa9af3064dddc8b10170d1ed1784e30ce7423a31a7d7
data/CHANGELOG.md CHANGED
@@ -1,6 +1,12 @@
1
1
  CHANGELOG
2
2
  =========
3
3
 
4
+ 2015-11-03 - v0.9.0
5
+ -------------------
6
+
7
+ ### Added
8
+ * Allow block without argument in before and after update hooks
9
+
4
10
  2015-11-03 - v0.8.3
5
11
  -------------------
6
12
 
@@ -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
- before_blk.call(record) if before_blk
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
- after_blk.call(record) if after_blk
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
@@ -1,3 +1,3 @@
1
1
  module RecordCollection
2
- VERSION = "0.8.3"
2
+ VERSION = "0.9.0"
3
3
  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.8.3
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