chainable_methods 0.1.0 → 0.1.1
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/.gitignore +1 -0
- data/lib/chainable_methods.rb +13 -1
- data/lib/chainable_methods/version.rb +1 -1
- 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: d4bb132eff83680c2108d026320a9651a2d8f612
|
4
|
+
data.tar.gz: fecb905cf761a1b5a43c5f5dc3307bf4450e46d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d4fa21b5a889ce08c598ead1283742050b10759e4c2ea8646ac8ff3c9e0a451e6c83dcc54491ef4e443c328003ad56d4490e63c2eb76fdeb938e8916d090664
|
7
|
+
data.tar.gz: 35efa65f538a0753db47973d30d2f799e45f7d0b4206dd88e85ce6fedab0d5fbd29ac1e458a919906f4ae7a5c1a262cf04b2cb4e4b02a3f539cc22eee6ad5bce
|
data/.gitignore
CHANGED
data/lib/chainable_methods.rb
CHANGED
@@ -5,6 +5,10 @@ module ChainableMethods
|
|
5
5
|
ChainableMethods::Link.new(initial_state, self)
|
6
6
|
end
|
7
7
|
|
8
|
+
def self.wrap(context, initial_state)
|
9
|
+
ChainableMethods::Link.new(initial_state, context)
|
10
|
+
end
|
11
|
+
|
8
12
|
class Link
|
9
13
|
attr_reader :state, :context
|
10
14
|
|
@@ -14,7 +18,12 @@ module ChainableMethods
|
|
14
18
|
end
|
15
19
|
|
16
20
|
def method_missing(name, *args, &block)
|
17
|
-
|
21
|
+
local_response = state.respond_to?(name)
|
22
|
+
context_response = context.respond_to?(name)
|
23
|
+
|
24
|
+
# if the state itself has the means to respond, delegate to it
|
25
|
+
# but if the context has the behavior, it has priority over the delegation
|
26
|
+
if local_response && !context_response
|
18
27
|
ChainableMethods::Link.new( state.send(name, *args, &block), context)
|
19
28
|
else
|
20
29
|
ChainableMethods::Link.new( context.send(name, *([state] + args), &block), context )
|
@@ -26,3 +35,6 @@ module ChainableMethods
|
|
26
35
|
end
|
27
36
|
end
|
28
37
|
end
|
38
|
+
|
39
|
+
# easier shortcut
|
40
|
+
CM ||= ChainableMethods
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chainable_methods
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- AkitaOnRails
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|