hero 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/hero/observer.rb +21 -3
  2. data/spec/formula_spec.rb +50 -0
  3. metadata +2 -2
data/lib/hero/observer.rb CHANGED
@@ -39,12 +39,29 @@ module Hero
39
39
  # end
40
40
  # end
41
41
  #
42
- # add_step(:my_step, MyStep)
42
+ # add_step(MyStep)
43
43
  #
44
- # @param [Symbol, String] name The name of the step.
44
+ # @param optional [Symbol, String] name The name of the step.
45
45
  # @param optional [Object] step The step to be executed.
46
46
  # @block optional [Object] A block to use as the step to be executed.
47
- def add_step(name, step=nil, &block)
47
+ def add_step(*args, &block)
48
+ if block_given?
49
+ raise ArgumentError unless args.length == 1
50
+ name = args.first
51
+ step = block
52
+ else
53
+ raise ArgumentError if args.length > 2
54
+ if args.length == 1
55
+ step = args.first
56
+ elsif args.length == 2
57
+ name = args.first
58
+ step = args.last
59
+ end
60
+ end
61
+
62
+ name ||= step.name if step.is_a? Class
63
+ name ||= step.class.name
64
+
48
65
  steps.delete_if { |s| s.first == name }
49
66
  step ||= block if block_given?
50
67
  steps << [name, step]
@@ -72,6 +89,7 @@ module Hero
72
89
 
73
90
  private
74
91
 
92
+
75
93
  # Logs a step to the registered Hero.logger.
76
94
  # @note Users info for the log level.
77
95
  # @param [Symbol, String] id The identifier for the step. [:before, :after]
data/spec/formula_spec.rb CHANGED
@@ -8,6 +8,56 @@ describe Hero::Formula do
8
8
  Hero::Formula.reset
9
9
  end
10
10
 
11
+ it "should not allow anonymous steps" do
12
+ assert_raise ArgumentError do
13
+ Hero::Formula[:test_formula].add_step() {}
14
+ end
15
+ end
16
+
17
+ it "should allow unnamed Class steps" do
18
+ class MyStep
19
+ def self.call(*args); end
20
+ end
21
+ Hero::Formula[:test_formula].add_step MyStep
22
+ assert Hero::Formula[:test_formula].steps.map{|s| s.first}.include?("MyStep")
23
+ assert Hero::Formula[:test_formula].steps.map{|s| s.last}.include?(MyStep)
24
+ end
25
+
26
+ it "should allow named Class steps" do
27
+ class MyStep
28
+ def self.call(*args); end
29
+ end
30
+ Hero::Formula[:test_formula].add_step :foo, MyStep
31
+ assert Hero::Formula[:test_formula].steps.map{|s| s.first}.include?(:foo)
32
+ assert Hero::Formula[:test_formula].steps.map{|s| s.last}.include?(MyStep)
33
+ end
34
+
35
+ it "should allow unnamed instance steps" do
36
+ class MyStep
37
+ def call(*args); end
38
+ end
39
+ step = MyStep.new
40
+ Hero::Formula[:test_formula].add_step step
41
+ names = Hero::Formula[:test_formula].steps.map{|s| s.first}
42
+ steps = Hero::Formula[:test_formula].steps.map{|s| s.last}
43
+ steps.each { |s| assert s.is_a? MyStep }
44
+ assert names.include?("MyStep")
45
+ assert steps.include?(step)
46
+ end
47
+
48
+ it "should allow named instance steps" do
49
+ class MyStep
50
+ def call(*args); end
51
+ end
52
+ step = MyStep.new
53
+ Hero::Formula[:test_formula].add_step :foo, step
54
+ names = Hero::Formula[:test_formula].steps.map{|s| s.first}
55
+ steps = Hero::Formula[:test_formula].steps.map{|s| s.last}
56
+ steps.each { |s| assert s.is_a? MyStep }
57
+ assert names.include?(:foo)
58
+ assert steps.include?(step)
59
+ end
60
+
11
61
  it "should create a named class" do
12
62
  Hero::Formula[:my_formula]
13
63
  assert Object.const_defined?("HeroFormulaMyFormula")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hero
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-03 00:00:00.000000000 Z
12
+ date: 2012-09-11 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ! ' Simplify your app by effectively modeling business processes within
15
15
  it.