hero 0.0.2 → 0.0.3
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.
- data/README.md +5 -2
- data/lib/hero/formula.rb +3 -2
- data/lib/hero/observer.rb +2 -2
- data/spec/hero_spec.rb +10 -0
- metadata +1 -1
data/README.md
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
## Its a bird, its a plane, its... its... my Hero
|
4
4
|
|
5
|
+

|
6
|
+
|
5
7
|
Ever wish that you could unwind the spaghetti and get out of the corner you've been backed into?
|
6
8
|
|
7
9
|
### Hero is here to save the day
|
@@ -19,7 +21,7 @@ One that evolved from the real world with concrete use cases and actual producti
|
|
19
21
|
|
20
22
|
The problem has always been: How to effectively model a business process within your app.
|
21
23
|
|
22
|
-
Things start simply enough but eventually edge cases force *
|
24
|
+
Things start simply enough but eventually edge cases force *gotchas* into
|
23
25
|
various libs, modules, and classes. Before you know you it,
|
24
26
|
you have a lump of spaghetti that's difficult to maintain and even harder to improve.
|
25
27
|
|
@@ -85,7 +87,7 @@ end
|
|
85
87
|
|
86
88
|
Hero approaches this problem differently.
|
87
89
|
It asks us to <a href="http://en.wikipedia.org/wiki/Decomposition_(computer_science)">decompose</a>
|
88
|
-
the login requirement into business processes
|
90
|
+
the login requirement into a business processes looks something like this.
|
89
91
|
|
90
92
|
#### Login
|
91
93
|
|
@@ -172,3 +174,4 @@ I know what you're thinking, and you're right.
|
|
172
174
|
This doesn't pass DHH's before/after test,
|
173
175
|
but lets start throwing edge cases at it and see what happens.
|
174
176
|
|
177
|
+
More soon. Stay tuned...
|
data/lib/hero/formula.rb
CHANGED
@@ -13,6 +13,7 @@ module Hero
|
|
13
13
|
def_delegator :formulas, :length, :count
|
14
14
|
|
15
15
|
def reset
|
16
|
+
formulas.values.each { |f| f.delete_observers }
|
16
17
|
@formulas = {}
|
17
18
|
end
|
18
19
|
|
@@ -40,9 +41,9 @@ module Hero
|
|
40
41
|
@observer.steps << step
|
41
42
|
end
|
42
43
|
|
43
|
-
def notify(
|
44
|
+
def notify(context=nil, options={})
|
44
45
|
changed
|
45
|
-
notify_observers(
|
46
|
+
notify_observers(context, options)
|
46
47
|
end
|
47
48
|
|
48
49
|
alias :run :notify
|
data/lib/hero/observer.rb
CHANGED
data/spec/hero_spec.rb
CHANGED
@@ -35,6 +35,16 @@ describe Hero::Formula do
|
|
35
35
|
assert_equal Hero::Formula.count, 10
|
36
36
|
end
|
37
37
|
|
38
|
+
it "should unregister formula observers on reset" do
|
39
|
+
formula = Hero::Formula[:test_formula]
|
40
|
+
assert_equal Hero::Formula.count, 1
|
41
|
+
formula.add_step {}
|
42
|
+
assert_equal formula.count_observers, 1
|
43
|
+
Hero::Formula.reset
|
44
|
+
assert_equal Hero::Formula.count, 0
|
45
|
+
assert_equal formula.count_observers, 0
|
46
|
+
end
|
47
|
+
|
38
48
|
describe "a registered formula" do
|
39
49
|
it "should support adding steps" do
|
40
50
|
Hero::Formula.register(:test_formula)
|