after_do-loader 0.1.1 → 0.2.0
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 +4 -4
- data/README.md +4 -0
- data/after_do-loader.gemspec +1 -0
- data/lib/after_do/loader/aspect_applier.rb +11 -9
- data/lib/after_do/loader/config.rb +12 -1
- data/lib/after_do/loader/version.rb +1 -1
- data/spec/after_do/loader/aspect_applier_spec.rb +12 -5
- data/spec/after_do/loader/config_spec.rb +14 -1
- data/spec/fixtures/aspect_config_with_subclass.yml +11 -0
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c6396dad629af3ba2cfb47eb8c9beae69c09f6d
|
4
|
+
data.tar.gz: d0b77c5fac65224a0d8ef39426dc96c48d395b64
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11283c6e32a5980e935171a803117548a23ceaee9de1ae3b279d76a508a624a3bbbb3a9c3e4d26a8cba2fb17dabf943c9eb9574cece14fe1e13ec160ecc2e2ba
|
7
|
+
data.tar.gz: 158b836afe0373cf094f2d1c96505f48c2d25bf5b86ba7ad5c0f5c3b81050e26b63f0e1da61e98a277f3c4abe6181d78ed955110a317968d540babb2ee2b20c8
|
data/README.md
CHANGED
data/after_do-loader.gemspec
CHANGED
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
|
20
20
|
spec.add_dependency 'after_do', '~> 0.3'
|
21
21
|
spec.add_dependency 'recursive-open-struct'
|
22
|
+
spec.add_dependency 'activesupport', '>= 3.0'
|
22
23
|
|
23
24
|
spec.add_development_dependency 'bundler', '~> 1.7'
|
24
25
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
@@ -8,27 +8,29 @@ module AfterDo
|
|
8
8
|
def apply
|
9
9
|
aspect.advices.each do |advice|
|
10
10
|
advice.targets.each do |target|
|
11
|
-
target.klass.
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
target.klass.each do |target_klass|
|
12
|
+
extend_and_apply(
|
13
|
+
target_klass, target.target_methods, aspect, advice
|
14
|
+
)
|
15
|
+
end
|
16
16
|
end
|
17
17
|
end
|
18
|
-
rescue
|
19
|
-
raise Errors::CannotApplyAspect
|
20
18
|
end
|
21
19
|
|
22
20
|
protected
|
23
21
|
|
24
22
|
attr_reader :aspect
|
25
23
|
|
26
|
-
def
|
24
|
+
def extend_and_apply(target_klass, methods, aspect, advice)
|
25
|
+
target_klass.extend(AfterDo)
|
26
|
+
|
27
27
|
methods.each do |method|
|
28
28
|
advice.names.each do |advice_name|
|
29
|
-
|
29
|
+
aspect.klass.new(target_klass).send(advice_name, method)
|
30
30
|
end
|
31
31
|
end
|
32
|
+
rescue
|
33
|
+
raise Errors::CannotApplyAspect
|
32
34
|
end
|
33
35
|
end
|
34
36
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'delegate'
|
2
|
+
require 'active_support/core_ext/class/subclasses'
|
2
3
|
|
3
4
|
module AfterDo
|
4
5
|
module Loader
|
@@ -12,6 +13,8 @@ module AfterDo
|
|
12
13
|
|
13
14
|
attr_reader :config_path
|
14
15
|
|
16
|
+
private
|
17
|
+
|
15
18
|
def parse_config
|
16
19
|
config_hash = YAML.load_file(config_path)
|
17
20
|
config = constantize_classes!(config_hash)
|
@@ -27,13 +30,21 @@ module AfterDo
|
|
27
30
|
|
28
31
|
aspect['advices'].each do |advice|
|
29
32
|
advice['targets'].each do |target|
|
30
|
-
target['klass'] =
|
33
|
+
target['klass'] = find_classes(target['klass'])
|
31
34
|
end
|
32
35
|
end
|
33
36
|
end
|
34
37
|
|
35
38
|
config_hash
|
36
39
|
end
|
40
|
+
|
41
|
+
def find_classes(target)
|
42
|
+
if target =~ />$/
|
43
|
+
AfterDo.const_get(target.gsub(/\s+>$/, '')).subclasses
|
44
|
+
else
|
45
|
+
[AfterDo.const_get(target.gsub(/\s+>$/, ''))]
|
46
|
+
end
|
47
|
+
end
|
37
48
|
end
|
38
49
|
end
|
39
50
|
end
|
@@ -1,6 +1,9 @@
|
|
1
1
|
module AfterDo
|
2
2
|
module Loader
|
3
3
|
class AdvisedClass; end
|
4
|
+
class AdvisedChild < AdvisedClass; end
|
5
|
+
class OtherAdvisedChild < AdvisedClass; end
|
6
|
+
|
4
7
|
class CoolAspect; end
|
5
8
|
|
6
9
|
describe AspectApplier do
|
@@ -8,12 +11,12 @@ module AfterDo
|
|
8
11
|
|
9
12
|
let(:aspect_config) { config.aspects.first }
|
10
13
|
let(:config) do
|
11
|
-
Config.new(fixture_path('
|
14
|
+
Config.new(fixture_path('aspect_config_with_subclass.yml'))
|
12
15
|
end
|
13
16
|
|
14
17
|
let(:aspect_instance) { CoolAspect.new }
|
15
18
|
let(:aspect_class) { CoolAspect }
|
16
|
-
let(:
|
19
|
+
let(:target_classes) { [AdvisedChild, OtherAdvisedChild] }
|
17
20
|
|
18
21
|
describe '#apply' do
|
19
22
|
subject(:apply) { applier.apply }
|
@@ -24,13 +27,17 @@ module AfterDo
|
|
24
27
|
end
|
25
28
|
|
26
29
|
it 'extends the target class with the AfterDo library' do
|
27
|
-
|
30
|
+
target_classes.each do |target_class|
|
31
|
+
expect(target_class).to receive(:extend).with(AfterDo)
|
32
|
+
end
|
28
33
|
|
29
34
|
apply
|
30
35
|
end
|
31
36
|
|
32
37
|
it 'creates an Aspect object of the correct class' do
|
33
|
-
|
38
|
+
target_classes.each do |target_class|
|
39
|
+
expect(aspect_class).to receive(:new).with(target_class)
|
40
|
+
end
|
34
41
|
|
35
42
|
apply
|
36
43
|
end
|
@@ -44,7 +51,7 @@ module AfterDo
|
|
44
51
|
|
45
52
|
context 'when applying goes wrong' do
|
46
53
|
before do
|
47
|
-
allow(
|
54
|
+
allow(AdvisedClass).to receive(:extend).and_raise(StandardError)
|
48
55
|
end
|
49
56
|
|
50
57
|
it { expect { apply }.to raise_error(Errors::CannotApplyAspect) }
|
@@ -2,6 +2,8 @@ module AfterDo
|
|
2
2
|
module Loader
|
3
3
|
class AdvisedClass; end
|
4
4
|
class CoolAspect; end
|
5
|
+
class AdvisedChild < AdvisedClass; end
|
6
|
+
class OtherAdvisedChild < AdvisedClass; end
|
5
7
|
|
6
8
|
describe Config do
|
7
9
|
subject(:config) { Config.new(config_path) }
|
@@ -21,7 +23,7 @@ target classes",
|
|
21
23
|
'names' => %w(add_callback),
|
22
24
|
'targets' => [
|
23
25
|
{
|
24
|
-
'klass' =>
|
26
|
+
'klass' => target_klasses,
|
25
27
|
'target_methods' => %w(initialize merge)
|
26
28
|
}
|
27
29
|
]
|
@@ -31,10 +33,13 @@ target classes",
|
|
31
33
|
]
|
32
34
|
}
|
33
35
|
end
|
36
|
+
|
34
37
|
let(:config_os) do
|
35
38
|
RecursiveOpenStruct.new(config_hash, recurse_over_arrays: true)
|
36
39
|
end
|
37
40
|
|
41
|
+
let(:target_klasses) { [AdvisedClass] }
|
42
|
+
|
38
43
|
it { expect(config.aspects).to eq(config_os.aspects) }
|
39
44
|
|
40
45
|
context 'when parsing goes wrong' do
|
@@ -42,6 +47,14 @@ target classes",
|
|
42
47
|
|
43
48
|
it { expect { config }.to raise_error(Errors::InvalidConfig) }
|
44
49
|
end
|
50
|
+
|
51
|
+
context 'when advised class has subclasses' do
|
52
|
+
let(:config_path) { fixture_path('aspect_config_with_subclass.yml') }
|
53
|
+
|
54
|
+
let(:target_klasses) { [AdvisedChild, OtherAdvisedChild] }
|
55
|
+
|
56
|
+
it { expect(config.aspects).to eq(config_os.aspects) }
|
57
|
+
end
|
45
58
|
end
|
46
59
|
end
|
47
60
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
aspects:
|
2
|
+
- name: CoolAspect
|
3
|
+
klass: AfterDo::Loader::CoolAspect
|
4
|
+
description: This aspect adds after_do callbacks to its target classes
|
5
|
+
advices:
|
6
|
+
- names: [add_callback]
|
7
|
+
targets:
|
8
|
+
- klass: AfterDo::Loader::AdvisedClass >
|
9
|
+
target_methods:
|
10
|
+
- initialize
|
11
|
+
- merge
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: after_do-loader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Renan Ranelli
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-09-
|
12
|
+
date: 2014-09-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: after_do
|
@@ -39,6 +39,20 @@ dependencies:
|
|
39
39
|
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: activesupport
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '3.0'
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '3.0'
|
42
56
|
- !ruby/object:Gem::Dependency
|
43
57
|
name: bundler
|
44
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -165,6 +179,7 @@ files:
|
|
165
179
|
- spec/after_do/loader/config_spec.rb
|
166
180
|
- spec/after_do/loader_spec.rb
|
167
181
|
- spec/fixtures/aspect_config.yml
|
182
|
+
- spec/fixtures/aspect_config_with_subclass.yml
|
168
183
|
- spec/spec_helper.rb
|
169
184
|
homepage: ''
|
170
185
|
licenses:
|
@@ -195,5 +210,6 @@ test_files:
|
|
195
210
|
- spec/after_do/loader/config_spec.rb
|
196
211
|
- spec/after_do/loader_spec.rb
|
197
212
|
- spec/fixtures/aspect_config.yml
|
213
|
+
- spec/fixtures/aspect_config_with_subclass.yml
|
198
214
|
- spec/spec_helper.rb
|
199
215
|
has_rdoc:
|