aop 1.0.1 → 1.0.2

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: a11ed9fc8c66d7dbf41febbfb8fc4d0205a3c937
4
- data.tar.gz: 78ecf889219aeb28e044d948a40185901475b7fc
3
+ metadata.gz: 2627d0786bc6e33b83e833b9ccd9a7fd42cd7c36
4
+ data.tar.gz: a252c109c0c138f2c64593f2f1aabb5b49051b42
5
5
  SHA512:
6
- metadata.gz: 264164d2abb7be0975a398ae799b0ddf59068d86a0194182476725babba90a2d1875c9d2c155ad6d775f3f54130c5aa7a9b6708fc295db77f0be9f61b9931259
7
- data.tar.gz: 8ab954e1e2afe9dbc5b3b7c4cf7c9b2c9311615483841b2f5c0efd2c787b2c67b5d1c1d7cdf044711abe8745e139d0d05d28950c65d72b579f3390533c789c4b
6
+ metadata.gz: 46d02c87653970b28799e3c31c2444f74b23aca494c47f997a5e69c3228d64815060240b790b473c2fb86d9027f17f29d19416f4a7d135820035b27878054bf8
7
+ data.tar.gz: 2efcc6cef881ca92868ed7060970d3a3f4a996620946619bebb1d67384494f939311a8d9da135272550128ccedafbf6d4bf45e96b7dfcbdc7feca2a6759ccf25
@@ -14,3 +14,4 @@ bundler_args: --without development
14
14
  script:
15
15
  - bundle exec rspec
16
16
  - bundle exec ruby integration/contracts.rb
17
+ - bundle exec ruby integration/contracts_pattern_matching.rb
@@ -0,0 +1,29 @@
1
+ require "aop"
2
+ require "contracts"
3
+
4
+ class BankAccount < Struct.new(:number, :amount)
5
+ include Contracts
6
+
7
+ Contract BankAccount, Num => Num
8
+ def transfer(other, amount)
9
+ self.amount -= amount
10
+ other.amount += amount
11
+ end
12
+
13
+ Contract nil, Num => Num
14
+ def transfer(_, amount)
15
+ self.amount -= amount
16
+ end
17
+ end
18
+
19
+ @actual = nil
20
+ @expected = "Transfered 100 from 12345 to cash account"
21
+
22
+ Aop["BankAccount#transfer:around"].advice do |jp, account, other, amount|
23
+ @actual = "Transfered #{amount} from #{account.number} to #{other ? other.number : "cash account"}"
24
+ jp.call
25
+ end
26
+
27
+ BankAccount[12345, 955].transfer(nil, 100)
28
+
29
+ fail "\nExpected: #{@expected}\nActual: #{@actual}" unless @expected == @actual
@@ -16,7 +16,6 @@ module Aop
16
16
  end
17
17
 
18
18
  @method_spec = spec.scan(/[#\.][^,#\.:]+/)
19
- @methods = @method_spec.map { |m| MethodReference.from(m) }
20
19
 
21
20
  @advices = spec.scan(/[^:]:([^:,]+)/).flatten
22
21
  end
@@ -37,12 +36,11 @@ module Aop
37
36
  end
38
37
 
39
38
  def generic_advice(advised, &body)
40
- methods = @methods
39
+ methods = @method_spec
41
40
  @classes.each do |klass|
42
- klass.class_eval do
43
- methods.each do |method_ref|
44
- method_ref.decorate(klass, &body[method_ref])
45
- end
41
+ methods.each do |method|
42
+ method_ref = MethodReference.from(method)
43
+ method_ref.decorate(klass, &body[method_ref])
46
44
  end
47
45
  end
48
46
  end
@@ -1,3 +1,3 @@
1
1
  module Aop
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -5,9 +5,49 @@ RSpec.describe "Advanced advices" do
5
5
 
6
6
  before do
7
7
  load_fixture("BankAccount", "bank_account")
8
+ load_fixture("OtherBankAccount", "other_bank_account")
8
9
  load_fixture("CashAccount", "cash_account")
9
10
  end
10
11
 
12
+ describe "double advice" do
13
+ before do
14
+ Aop["BankAccount#transfer:around"].advice do |joint_point, *args, &blk|
15
+ joint_point.call
16
+ end
17
+
18
+ Aop["BankAccount#transfer:around"].advice do |joint_point, *args, &blk|
19
+ joint_point.call
20
+ end
21
+ end
22
+
23
+ it "works" do
24
+ account = BankAccount.new(spy)
25
+ other = BankAccount.new(spy)
26
+ amount = 55
27
+
28
+ expect(spy).to receive(:inside).with(other, amount).ordered.once
29
+
30
+ expect(account.transfer(other, amount)).to eq(:a_result)
31
+ end
32
+ end
33
+
34
+ describe "inheritance advice" do
35
+ before do
36
+ Aop["BankAccount,OtherBankAccount#transfer:before"].advice do |joint_point, *args, &blk|
37
+ end
38
+ end
39
+
40
+ it "works" do
41
+ account = OtherBankAccount.new(spy)
42
+ other = BankAccount.new(spy)
43
+ amount = 55
44
+
45
+ expect(spy).to receive(:inside).with(other, amount).ordered.once
46
+
47
+ expect(account.transfer(other, amount)).to eq(:a_result)
48
+ end
49
+ end
50
+
11
51
  describe "class methods" do
12
52
  before do
13
53
  Aop["BankAccount.transfer:around"].advice do |joint_point, klass, *args, &blk|
@@ -0,0 +1,5 @@
1
+ class OtherBankAccount < BankAccount
2
+ def transfer(other, amount)
3
+ super
4
+ end
5
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aop
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Fedorov
@@ -55,6 +55,7 @@ files:
55
55
  - aop.gemspec
56
56
  - benchmarks/before.rb
57
57
  - integration/contracts.rb
58
+ - integration/contracts_pattern_matching.rb
58
59
  - lib/aop.rb
59
60
  - lib/aop/errors.rb
60
61
  - lib/aop/joint_point.rb
@@ -67,6 +68,7 @@ files:
67
68
  - spec/aop/before_spec.rb
68
69
  - spec/fixtures/bank_account.rb
69
70
  - spec/fixtures/cash_account.rb
71
+ - spec/fixtures/other_bank_account.rb
70
72
  - spec/spec_helper.rb
71
73
  - spec/support/loader.rb
72
74
  homepage: https://github.com/waterlink/aop
@@ -100,5 +102,6 @@ test_files:
100
102
  - spec/aop/before_spec.rb
101
103
  - spec/fixtures/bank_account.rb
102
104
  - spec/fixtures/cash_account.rb
105
+ - spec/fixtures/other_bank_account.rb
103
106
  - spec/spec_helper.rb
104
107
  - spec/support/loader.rb