dizzy 1.0.0.alpha.1 → 1.0.0.alpha.2
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/lib/dizzy/dsl.rb +39 -26
- metadata +1 -2
- data/lib/dizzy/rule.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8498ff85f380ec402c59a51a764ab1824499e31
|
4
|
+
data.tar.gz: 59eefacc9cff7add29254feab943b8c31f420740
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3667a62381e8a0a5f0a809c852c1ad8efa69f1eb18da4eae680c0dc21894c7bcd4d82a00a2464c3b6a5a020a9a6209b48286aecdd9db5fdac36084cb48cc2cc5
|
7
|
+
data.tar.gz: 5a50bafd5e268cbfd3b2e0763f3a760e63fb62bbfb0e66d0461a7d327199af5fb5caf6643817edd0f1d50f512027f781f7036e306b401d3b997efc9ae02b148a
|
data/lib/dizzy/dsl.rb
CHANGED
@@ -1,56 +1,69 @@
|
|
1
1
|
|
2
2
|
require 'dizzy/core'
|
3
|
-
require 'dizzy/rule'
|
4
3
|
|
5
4
|
module Dizzy::DSL
|
6
5
|
|
7
6
|
class RuleContext
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
def initialize(rule)
|
12
|
-
@rule = rule
|
13
|
-
end
|
8
|
+
attr_accessor :init_proc, :wire_proc
|
14
9
|
|
15
10
|
def init(&block)
|
16
|
-
|
11
|
+
@init_proc = block
|
17
12
|
end
|
18
13
|
|
19
14
|
def wire(&block)
|
20
|
-
|
15
|
+
@wire_proc = block
|
21
16
|
end
|
22
17
|
end
|
23
18
|
|
24
19
|
|
25
|
-
def di(name, clazz = nil, *args, &block)
|
26
|
-
___method_name = name.to_sym
|
27
|
-
___variable_name = "@#{name}".to_sym
|
28
|
-
|
29
|
-
|
30
|
-
rule = Dizzy::Rule.new
|
31
20
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
else
|
36
|
-
rc = ::Dizzy::DSL::RuleContext.new(rule)
|
37
|
-
rc.instance_exec(&block)
|
21
|
+
def di_define_method(__di__method_name, __di__init_proc, __di__wire_proc)
|
22
|
+
unless __di__init_proc
|
23
|
+
raise ArgumentError.new("No init proc was specified for: #{__di__method_name}")
|
38
24
|
end
|
39
25
|
|
26
|
+
# If wire_proc wasn't specified, then just no-op
|
27
|
+
__di__wire_proc ||= lambda{|x| }
|
40
28
|
|
41
|
-
|
42
|
-
unless instance_variable_defined? ___variable_name
|
43
|
-
value = self.instance_exec(&rule.init_proc)
|
44
|
-
instance_variable_set(___variable_name, value)
|
29
|
+
__di__variable_name = "@#{__di__method_name}".to_sym
|
45
30
|
|
46
|
-
|
31
|
+
define_method __di__method_name do
|
32
|
+
unless instance_variable_defined? __di__variable_name
|
33
|
+
value = self.instance_exec(&__di__init_proc)
|
34
|
+
instance_variable_set(__di__variable_name, value)
|
35
|
+
|
36
|
+
self.instance_exec(value, &__di__wire_proc)
|
47
37
|
end
|
48
|
-
instance_variable_get(
|
38
|
+
instance_variable_get(__di__variable_name)
|
49
39
|
end
|
40
|
+
end
|
41
|
+
|
50
42
|
|
43
|
+
# Use this when you need to both init and wire
|
44
|
+
# your object.
|
45
|
+
def di(name, &block)
|
46
|
+
rc = ::Dizzy::DSL::RuleContext.new
|
47
|
+
rc.instance_exec(&block)
|
48
|
+
|
49
|
+
di_define_method(name, rc.init_proc, rc.wire_proc)
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
# Use this when you only need to init an object
|
54
|
+
def di_init(name, &block)
|
55
|
+
di_define_method(name, block, nil)
|
51
56
|
end
|
52
57
|
|
53
58
|
|
59
|
+
# Use this when the init logic is uninteresting.
|
60
|
+
# For example: you're just creating an instance
|
61
|
+
# of a class w/ a hard-coded set of arguments.
|
62
|
+
def di_wire(name, clazz, *args, &block)
|
63
|
+
init_proc = lambda{ clazz.new(*args) }
|
64
|
+
di_define_method(name, init_proc, block)
|
65
|
+
end
|
66
|
+
|
54
67
|
|
55
68
|
|
56
69
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dizzy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.alpha.
|
4
|
+
version: 1.0.0.alpha.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Lauber
|
@@ -19,7 +19,6 @@ files:
|
|
19
19
|
- lib/dizzy.rb
|
20
20
|
- lib/dizzy/core.rb
|
21
21
|
- lib/dizzy/dsl.rb
|
22
|
-
- lib/dizzy/rule.rb
|
23
22
|
homepage:
|
24
23
|
licenses:
|
25
24
|
- MIT
|