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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +67 -13
- data/acting.gemspec +1 -1
- data/lib/acting.rb +6 -4
- data/lib/acting/version.rb +1 -1
- data/spec/acting_spec.rb +40 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e8637547a3c5b66fcd5eb1830bda1c2b175ac00
|
4
|
+
data.tar.gz: 997ad024e8c181a3ceeb2a5406de997d28694f96
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d9d5819b629b44b53e26cc787d93a8eb105bb800ce6f2715f6c4a23acd9e0cde78ce92113ddf847e5543aa43884ce4086c51ca07255df396bb33e4220eafc83
|
7
|
+
data.tar.gz: 54973853ef5620f40e224e65e02e9e541cb5c3eb79e194d4209082a0733c7e041657011c122be0b53e363093fe87f77b62d545f250f214341542c56706f9c1e2
|
data/Gemfile.lock
CHANGED
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
|
-
|
30
|
-
|
31
|
-
end
|
29
|
+
class User
|
30
|
+
include Acting::Cast
|
32
31
|
|
33
|
-
|
34
|
-
|
35
|
-
end
|
32
|
+
attr_accessor :name
|
33
|
+
end
|
36
34
|
|
37
|
-
|
38
|
-
|
39
|
-
model2.speak # => 'NO'
|
40
|
-
end
|
35
|
+
user1 = User.new
|
36
|
+
user2 = User.new
|
41
37
|
|
42
|
-
|
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
|
-
|
51
|
-
|
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
|
|
data/acting.gemspec
CHANGED
@@ -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($/)
|
data/lib/acting.rb
CHANGED
@@ -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]
|
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__
|
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
|
data/lib/acting/version.rb
CHANGED
data/spec/acting_spec.rb
CHANGED
@@ -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.
|
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: {}
|