dicer 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -46,10 +46,14 @@ module Dicer
46
46
  def delegator_for(role)
47
47
  role = role.to_s.to_sym
48
48
 
49
- @delegators[role] ||= Dicer::Delegator.make(
50
- @described_class,
51
- @behaviors[role] | @behaviors.default
52
- )
49
+ if @delegators.has_key?(role)
50
+ @delegators[role]
51
+ else
52
+ @delegators[role] = Dicer::Delegator.make(
53
+ @described_class,
54
+ @behaviors[role]
55
+ )
56
+ end
53
57
  end
54
58
  end
55
59
  end
@@ -4,9 +4,13 @@ module Dicer
4
4
  delegator = Class.new(Dicer::Delegator)
5
5
  delegator.delegate_to(target_class)
6
6
  delegator.class_eval do
7
+ include Dicer::Contextable
8
+
7
9
  behaviors.each do |behavior|
8
10
  include behavior
9
11
  end
12
+
13
+ @@behaviors = behaviors
10
14
  end
11
15
 
12
16
  return delegator
@@ -18,11 +22,16 @@ module Dicer
18
22
  :__id__,
19
23
  :object_id,
20
24
  :respond_to?,
25
+ :pure,
26
+ :in_context,
27
+ :as,
28
+ :behaves_like,
21
29
  :methods,
22
30
  :public_methods,
23
31
  :private_methods,
24
32
  :protected_methods,
25
33
  :method_missing,
34
+ :behaviors,
26
35
  # for RSpec
27
36
  :should,
28
37
  :should_not
@@ -31,7 +40,10 @@ module Dicer
31
40
 
32
41
  def self.include(behavior)
33
42
  super(behavior)
34
- self.except_methods.concat(behavior.behavior_methods)
43
+
44
+ if behavior <= Dicer::Behavior
45
+ self.except_methods.concat(behavior.behavior_methods)
46
+ end
35
47
  end
36
48
 
37
49
  def self.delegate_to(klass)
@@ -53,6 +65,10 @@ module Dicer
53
65
  @delegate_object = object
54
66
  end
55
67
 
68
+ def pure
69
+ @delegate_object
70
+ end
71
+
56
72
  def respond_to?(name, private = false)
57
73
  super || @delegate_object.respond_to?(name)
58
74
  end
@@ -76,5 +92,15 @@ module Dicer
76
92
  def method_missing(name, *args, &block)
77
93
  @delegate_object.send(name, *args, &block)
78
94
  end
95
+
96
+ def behaviors
97
+ if pure.respond_to?(:behaviors)
98
+ pure.behaviors | @@behaviors
99
+ else
100
+ @@behaviors
101
+ end
102
+ end
103
+
104
+ alias_method :__class__, :class
79
105
  end
80
106
  end
@@ -23,7 +23,10 @@ module Dicer
23
23
 
24
24
  def default_contexts
25
25
  @default_contexts ||= {}.tap do |hash|
26
- hash.default = ApplicationContext if defined?(ApplicationContext)
26
+ begin
27
+ hash.default = ::ApplicationContext
28
+ rescue NameError
29
+ end
27
30
  end
28
31
  end
29
32
  end
@@ -4,7 +4,7 @@ module Dicer
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  included do
7
- subject do
7
+ subject(:extended) do
8
8
  extend_to.behaves_like(described_class)
9
9
  end
10
10
  end
data/lib/dicer/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dicer
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
@@ -5,8 +5,8 @@ describe Dicer::Context::Description do
5
5
  Dicer::Context::Description.new(Entity) do
6
6
  it_behaves_like Cleaner
7
7
 
8
- role :cleaner do
9
- it_behaves_like Cleaner
8
+ role :other do
9
+ it_behaves_like OtherBehavior
10
10
  end
11
11
  end
12
12
  end
@@ -28,10 +28,10 @@ describe Dicer::Context::Description do
28
28
  it { should include(Cleaner) }
29
29
  end
30
30
 
31
- describe '[:cleaner]' do
32
- subject { description.behaviors[:cleaner] }
31
+ describe '[:other]' do
32
+ subject { description.behaviors[:other] }
33
33
 
34
- it { should include(Cleaner) }
34
+ it { should include(OtherBehavior) }
35
35
  end
36
36
  end
37
37
 
@@ -31,4 +31,18 @@ describe Dicer::Delegator do
31
31
 
32
32
  it { should be_true }
33
33
  end
34
+
35
+ describe '#pure' do
36
+ subject(:pure) { delegated.pure }
37
+
38
+ it { should == delegated }
39
+ it { should == entity }
40
+
41
+ describe '#object_id' do
42
+ subject { pure.object_id }
43
+
44
+ it { should_not == delegated.object_id }
45
+ it { should == entity.object_id }
46
+ end
47
+ end
34
48
  end
@@ -0,0 +1,7 @@
1
+ module OtherBehavior
2
+ include Dicer::Behavior
3
+
4
+ def testable?
5
+ true
6
+ end
7
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dicer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-19 00:00:00.000000000 Z
12
+ date: 2013-01-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -214,6 +214,7 @@ files:
214
214
  - spec/support/cleaner.rb
215
215
  - spec/support/cleaning_context.rb
216
216
  - spec/support/entity.rb
217
+ - spec/support/other_behavior.rb
217
218
  - spec/support/value.rb
218
219
  homepage: ''
219
220
  licenses:
@@ -230,7 +231,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
230
231
  version: '0'
231
232
  segments:
232
233
  - 0
233
- hash: 654783733716943402
234
+ hash: 4523608799554291329
234
235
  required_rubygems_version: !ruby/object:Gem::Requirement
235
236
  none: false
236
237
  requirements:
@@ -239,7 +240,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
239
240
  version: '0'
240
241
  segments:
241
242
  - 0
242
- hash: 654783733716943402
243
+ hash: 4523608799554291329
243
244
  requirements: []
244
245
  rubyforge_project:
245
246
  rubygems_version: 1.8.23
@@ -258,4 +259,5 @@ test_files:
258
259
  - spec/support/cleaner.rb
259
260
  - spec/support/cleaning_context.rb
260
261
  - spec/support/entity.rb
262
+ - spec/support/other_behavior.rb
261
263
  - spec/support/value.rb