dizzy 1.0.0.alpha.1 → 1.0.0.alpha.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/dizzy/dsl.rb +39 -26
  3. metadata +1 -2
  4. data/lib/dizzy/rule.rb +0 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8c43df022ef1a289584a66cf8143b6ed7c850c4f
4
- data.tar.gz: c9659f5c7095fe456c4770412bb521df44fa7ed9
3
+ metadata.gz: d8498ff85f380ec402c59a51a764ab1824499e31
4
+ data.tar.gz: 59eefacc9cff7add29254feab943b8c31f420740
5
5
  SHA512:
6
- metadata.gz: 3bb5848677977e34edc588055da8c6d65d4a44330c2cc19f9b9f607a76e23b7af1b821f4defda0546fc08df2b6542ca9c9e8e808047f17ecb3a297d5c5422857
7
- data.tar.gz: 0f6526c2ba17d5a839a11eb78027bc38a1454e596e92b6db223deea744396089cc30d13088884269b77e402d231c169090c9d4e9a631f2c8ccc5da7125cfa2ae
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
- attr_reader :rule
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
- rule.init_proc = block
11
+ @init_proc = block
17
12
  end
18
13
 
19
14
  def wire(&block)
20
- rule.wire_proc = block
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
- if clazz
33
- rule.init_proc = lambda{ clazz.new(*args) }
34
- rule.wire_proc = block || lambda{|x| }
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
- define_method ___method_name do
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
- self.instance_exec(value, &rule.wire_proc)
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(___variable_name)
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.1
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
data/lib/dizzy/rule.rb DELETED
@@ -1,13 +0,0 @@
1
-
2
- require 'dizzy/core'
3
-
4
- class Dizzy::Rule
5
-
6
- attr_accessor :init_proc, :wire_proc
7
-
8
- def initialize(options = {})
9
- @init_proc = lambda{}
10
- @wire_proc = lambda{|x| }
11
- end
12
-
13
- end