acting 0.0.2 → 0.0.4

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: 22283894c1dc87a10cdf0f6d806b11d07098bd3d
4
- data.tar.gz: e95812f00bf97328e93afa6c3c5f46a993a5e5d0
3
+ metadata.gz: 0e8637547a3c5b66fcd5eb1830bda1c2b175ac00
4
+ data.tar.gz: 997ad024e8c181a3ceeb2a5406de997d28694f96
5
5
  SHA512:
6
- metadata.gz: fd619483fc20e9e961b3c7f4dc5759f03e07bdb41bd2a96dc57b5e3bf07923a647e2c6a1d9c730c8d72d4d4d5deab88d93dc1c6e129c2346f42c70ddcaa25db5
7
- data.tar.gz: c4000ebd6ad3871a3009b594a17c1d6a12dcfcbb7d0a958375ae6ac5e51edda4c732f400d403ff878537c5d43b72e0e6bfaf2aaf60d212a5e8f91e5a2d2cbe29
6
+ metadata.gz: 8d9d5819b629b44b53e26cc787d93a8eb105bb800ce6f2715f6c4a23acd9e0cde78ce92113ddf847e5543aa43884ce4086c51ca07255df396bb33e4220eafc83
7
+ data.tar.gz: 54973853ef5620f40e224e65e02e9e541cb5c3eb79e194d4209082a0733c7e041657011c122be0b53e363093fe87f77b62d545f250f214341542c56706f9c1e2
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- acting (0.0.2)
4
+ acting (0.0.4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -26,20 +26,74 @@ Or install it yourself as:
26
26
  It is as simple as this:
27
27
 
28
28
  ```ruby
29
- module Positivist
30
- def speak; 'YES'; end
31
- end
29
+ class User
30
+ include Acting::Cast
32
31
 
33
- module Negativist
34
- def speak; 'NO'; end
35
- end
32
+ attr_accessor :name
33
+ end
36
34
 
37
- Acting.new(user1 => Positivist, user2 => Negativist).play do
38
- model1.speak # => 'YES'
39
- model2.speak # => 'NO'
40
- end
35
+ user1 = User.new
36
+ user2 = User.new
41
37
 
42
- model1.speak # => NoMethodError
38
+ module Positivist
39
+ def speak; 'YES'; end
40
+ end
41
+
42
+ module Negativist
43
+ def speak; 'NO'; end
44
+ end
45
+
46
+ Acting.new(user1 => Positivist, user2 => Negativist).play do
47
+ user1.speak # => 'YES'
48
+ user2.speak # => 'NO'
49
+ end
50
+
51
+ user1.speak # => NoMethodError
52
+ ```
53
+
54
+ ## Nested Usage
55
+
56
+ Different actings can also be nested, the defined role-methods will
57
+ be safely overridden and restored:
58
+
59
+ ```ruby
60
+ # assume the already defined constants
61
+ user = User.new
62
+
63
+ Acting.new(user => Positivist).play do
64
+ user.speak # => 'YES'
65
+
66
+ Acting.new(user => Negativist).play do
67
+ user.speak # => 'NO'
68
+ end
69
+
70
+ user.speak # => 'YES'
71
+ end
72
+
73
+ user.speak # => NoMethodError
74
+ ```
75
+
76
+ ## Usage without a block
77
+
78
+ The acting can also be manually started/quit. This can come in handy
79
+ if you need more control over the program flow or want to use the
80
+ actual roles later:
81
+
82
+ ```ruby
83
+ # assume the already defined constants
84
+ user = User.new
85
+
86
+ acting = Acting.new(user => Positivist)
87
+
88
+ user.speak # => NoMethodError
89
+
90
+ acting.play
91
+
92
+ user.speak # => 'YES'
93
+
94
+ acting.quit
95
+
96
+ user.speak # => NoMethodError
43
97
  ```
44
98
 
45
99
  ## TODO:
@@ -47,8 +101,8 @@ It is as simple as this:
47
101
  For now, we are only running on MRI 1.9.2/1.9.3/2.0.0.
48
102
  jRuby and RBX need to be configured.
49
103
 
50
- There is the case of overriding a previously define method by a role, that
51
- needs to be fixed, too.
104
+ Already defined methods won't be overridden due to the implementation
105
+ with method_missing. It's to discuss whether this is a bug or a feature.
52
106
 
53
107
  ## Contributing
54
108
 
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Jakob Holderbaum"]
10
10
  spec.email = ["jakob@featurefabrik.de"]
11
11
  spec.summary = %q{Let your objects play an acting - just for a while}
12
- spec.homepage = ""
12
+ spec.homepage = "https://github.com/featurefabrik/acting"
13
13
  spec.license = "MIT"
14
14
 
15
15
  spec.files = `git ls-files`.split($/)
@@ -30,22 +30,24 @@ class Acting
30
30
  private
31
31
  def __inject_methods__(methods)
32
32
  methods.each do |method|
33
- __injected_methods__[method.name] = method
33
+ __injected_methods__[method.name] << method
34
34
  end
35
35
  end
36
36
 
37
37
  def __remove_methods__(methods)
38
38
  methods.each do |method|
39
- __injected_methods__.delete method.name
39
+ __injected_methods__[method.name].pop
40
40
  end
41
41
  end
42
42
 
43
43
  def __injected_methods__
44
- @__injected_methods__ ||= {}
44
+ @__injected_methods__ ||= Hash.new do |hash, key|
45
+ hash[key] = []
46
+ end
45
47
  end
46
48
 
47
49
  def method_missing(meth, *args, &blk)
48
- method = __injected_methods__[meth]
50
+ method = __injected_methods__[meth].last
49
51
  if method
50
52
  method.bind(self).call(*args)
51
53
  else
@@ -1,3 +1,3 @@
1
1
  class Acting
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -56,6 +56,46 @@ describe Acting do
56
56
  assert_match(/kind of Acting::Cast/, error.message)
57
57
  end
58
58
 
59
+ it 'does not affect method_missing' do
60
+ cls = Class.new do
61
+ include Acting::Cast
62
+ attr_reader :test_called
63
+
64
+ def method_missing(meth, *args, &blk)
65
+ if meth == :test
66
+ @test_called = :true
67
+ else
68
+ super
69
+ end
70
+ end
71
+ end
72
+
73
+ model = cls.new
74
+
75
+ Acting.new(model => Positivist).play do
76
+ model.test
77
+ assert_equal 'YES', model.speak
78
+ end
79
+
80
+ assert model.test_called
81
+ end
82
+
83
+ it 'allows stacking of actings' do
84
+ model = new_model
85
+
86
+ Acting.new(model => Positivist).play do
87
+ assert_equal 'YES', model.speak
88
+
89
+ Acting.new(model => Positivist).play do
90
+ assert_equal 'YES', model.speak
91
+ end
92
+
93
+ assert_equal 'YES', model.speak
94
+ end
95
+
96
+ refute model.respond_to?(:speak)
97
+ end
98
+
59
99
  private
60
100
  def new_model
61
101
  model = Object.new
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acting
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakob Holderbaum
@@ -56,7 +56,7 @@ files:
56
56
  - lib/acting/version.rb
57
57
  - spec/acting_spec.rb
58
58
  - spec/helper.rb
59
- homepage: ''
59
+ homepage: https://github.com/featurefabrik/acting
60
60
  licenses:
61
61
  - MIT
62
62
  metadata: {}