carry_out 1.3.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/carry_out/cloaker.rb +32 -0
- data/lib/carry_out/plan/node.rb +0 -2
- data/lib/carry_out/plan/node_context.rb +10 -2
- data/lib/carry_out/plan_builder.rb +13 -6
- data/lib/carry_out/plan_runner.rb +2 -3
- data/lib/carry_out/unit.rb +18 -1
- data/lib/carry_out/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9a566c008472e7b69aa21de4ce6c6948a272281
|
4
|
+
data.tar.gz: 854adbd99187223c1570e1a3413d1078188ba424
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 021eabede07162f55d58da20cd46026c1c1a0bc13b8a9b01c299144a6707b4b1176c3745ed9bf9b20873979a4a3abe30183b01dbd25fc7cf3217fe957ef112ef
|
7
|
+
data.tar.gz: d5737328744baa7c38dc633a93586c204ddce4d88ff7e68e84eaa805456c8e47a9c6c8cbcef773ce5d9922119fe743328b7f8c3050e9c92893d049bb94492626
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# A Closure Is Not Always A Closure In Ruby - Alan Skorkin
|
2
|
+
# http://www.skorks.com/2013/03/a-closure-is-not-always-a-closure-in-ruby/
|
3
|
+
|
4
|
+
module CarryOut
|
5
|
+
module Cloaker
|
6
|
+
def cloaker(binding = nil, &b)
|
7
|
+
meth = self.class.class_eval do
|
8
|
+
define_method :cloaker_, &b
|
9
|
+
meth = instance_method :cloaker_
|
10
|
+
remove_method :cloaker_
|
11
|
+
meth
|
12
|
+
end
|
13
|
+
|
14
|
+
with_previous_context(binding || b.binding) { meth.bind(self).call }
|
15
|
+
end
|
16
|
+
|
17
|
+
def with_previous_context(binding, &block)
|
18
|
+
@previous_context = binding.eval('self')
|
19
|
+
result = block.call
|
20
|
+
@previous_context = nil
|
21
|
+
result
|
22
|
+
end
|
23
|
+
|
24
|
+
def method_missing(method, *args, &block)
|
25
|
+
if @previous_context && @previous_context.respond_to?(method)
|
26
|
+
@previous_context.send(method, *args, &block)
|
27
|
+
else
|
28
|
+
super
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/carry_out/plan/node.rb
CHANGED
@@ -53,8 +53,6 @@ module CarryOut
|
|
53
53
|
def method_missing(method, *args, &block)
|
54
54
|
if respond_to?(method)
|
55
55
|
@messages.push({ method: method, source: block || (args.length == 0 ? true : args.first) })
|
56
|
-
else
|
57
|
-
raise NoMethodError, "undefined method `#{method}' for #{@action}"
|
58
56
|
end
|
59
57
|
end
|
60
58
|
|
@@ -1,6 +1,10 @@
|
|
1
|
+
require "carry_out/cloaker"
|
2
|
+
|
1
3
|
module CarryOut
|
2
4
|
module Plan
|
3
5
|
class NodeContext
|
6
|
+
include CarryOut::Cloaker
|
7
|
+
|
4
8
|
def initialize(node)
|
5
9
|
@node = node
|
6
10
|
end
|
@@ -10,7 +14,7 @@ module CarryOut
|
|
10
14
|
end
|
11
15
|
|
12
16
|
def context(*args)
|
13
|
-
|
17
|
+
Proc.new do |context|
|
14
18
|
args.inject(context) { |c, k| c.nil? ? nil : c[k] }
|
15
19
|
end
|
16
20
|
end
|
@@ -24,7 +28,11 @@ module CarryOut
|
|
24
28
|
end
|
25
29
|
|
26
30
|
def method_missing(method, *args, &block)
|
27
|
-
@node.
|
31
|
+
if @node.respond_to?(method)
|
32
|
+
@node.send(method, *args, &block)
|
33
|
+
else
|
34
|
+
super
|
35
|
+
end
|
28
36
|
end
|
29
37
|
|
30
38
|
def respond_to?(method)
|
@@ -3,19 +3,26 @@ require "carry_out/plan/node_context"
|
|
3
3
|
|
4
4
|
module CarryOut
|
5
5
|
class PlanBuilder
|
6
|
+
include Cloaker
|
7
|
+
|
8
|
+
attr_reader :plan
|
9
|
+
|
6
10
|
def initialize(options = {}, &block)
|
7
11
|
@plan = Plan::Node.new
|
8
|
-
@wrapper = nil
|
9
12
|
@constant_resolver = [ options[:search] ].flatten(1)
|
13
|
+
@block_binding = options[:block_binding]
|
10
14
|
|
11
15
|
configure_node(@plan, &block) if block
|
12
16
|
end
|
13
17
|
|
14
|
-
attr_reader :plan
|
15
|
-
|
16
18
|
def self.build(options = {}, &block)
|
19
|
+
options = {
|
20
|
+
block_binding: block.binding
|
21
|
+
}.merge(options)
|
22
|
+
|
17
23
|
builder = PlanBuilder.new(options)
|
18
|
-
|
24
|
+
|
25
|
+
builder.cloaker(&block)
|
19
26
|
builder.plan
|
20
27
|
end
|
21
28
|
|
@@ -36,7 +43,7 @@ module CarryOut
|
|
36
43
|
obj = find_object(method)
|
37
44
|
|
38
45
|
if obj
|
39
|
-
call(
|
46
|
+
call(obj, &block)
|
40
47
|
else
|
41
48
|
super
|
42
49
|
end
|
@@ -46,7 +53,7 @@ module CarryOut
|
|
46
53
|
attr_writer :current_node
|
47
54
|
|
48
55
|
def configure_node(node, &block)
|
49
|
-
Plan::NodeContext.new(node).
|
56
|
+
Plan::NodeContext.new(node).cloaker(@block_binding, &block)
|
50
57
|
end
|
51
58
|
|
52
59
|
def current_node
|
@@ -13,8 +13,7 @@ module CarryOut
|
|
13
13
|
if node_result.kind_of?(Plan::NodeResult)
|
14
14
|
plan_result.add(node.returns_as, node_result.value)
|
15
15
|
end
|
16
|
-
rescue
|
17
|
-
error = CarryOut::Error.new(error.message, error) unless error.kind_of?(CarryOut::Error)
|
16
|
+
rescue CarryOut::Error => error
|
18
17
|
plan_result.add node.returns_as, error
|
19
18
|
end
|
20
19
|
|
@@ -26,7 +25,7 @@ module CarryOut
|
|
26
25
|
|
27
26
|
def self.call_unit(unit, context = {}, &block)
|
28
27
|
node = Plan::Node.new(unit)
|
29
|
-
Plan::NodeContext.new(node).
|
28
|
+
Plan::NodeContext.new(node).cloaker(&block) unless block.nil?
|
30
29
|
|
31
30
|
call(node, context)
|
32
31
|
end
|
data/lib/carry_out/unit.rb
CHANGED
@@ -5,6 +5,12 @@ module CarryOut
|
|
5
5
|
raise "Expected #{self.class} to define #{self.class}#call" unless self.class == Unit
|
6
6
|
end
|
7
7
|
|
8
|
+
def initialize
|
9
|
+
self.class.parameter_defaults.each do |p, d|
|
10
|
+
instance_variable_set("@#{p}", d)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
8
14
|
def self.call(&block)
|
9
15
|
unit = self.new
|
10
16
|
yield unit if block
|
@@ -31,13 +37,24 @@ module CarryOut
|
|
31
37
|
end
|
32
38
|
end
|
33
39
|
|
34
|
-
def self.parameter(method_name, var = nil)
|
40
|
+
def self.parameter(method_name, var = nil, options = {})
|
41
|
+
if var.kind_of?(Hash)
|
42
|
+
options = var
|
43
|
+
var = nil
|
44
|
+
end
|
45
|
+
|
35
46
|
var ||= method_name
|
36
47
|
|
37
48
|
define_method(method_name.to_sym) do |*args|
|
38
49
|
instance_variable_set("@#{var}", args.length == 0 ? true : args.first)
|
39
50
|
self
|
40
51
|
end
|
52
|
+
|
53
|
+
parameter_defaults[var] = options[:default] unless options[:default].nil?
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.parameter_defaults
|
57
|
+
@parameter_defaults ||= {}
|
41
58
|
end
|
42
59
|
end
|
43
60
|
end
|
data/lib/carry_out/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: carry_out
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Fields
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -102,6 +102,7 @@ files:
|
|
102
102
|
- bin/setup
|
103
103
|
- carry_out.gemspec
|
104
104
|
- lib/carry_out.rb
|
105
|
+
- lib/carry_out/cloaker.rb
|
105
106
|
- lib/carry_out/configurator.rb
|
106
107
|
- lib/carry_out/error.rb
|
107
108
|
- lib/carry_out/plan/guard.rb
|