hero 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/Gemfile +0 -0
  2. data/lib/hero.rb +16 -0
  3. data/lib/hero_observer.rb +41 -0
  4. metadata +65 -0
data/Gemfile ADDED
File without changes
data/lib/hero.rb ADDED
@@ -0,0 +1,16 @@
1
+ require 'observer'
2
+ require 'singleton'
3
+
4
+ class Hero
5
+ include Observable
6
+ include Singleton
7
+
8
+ def notify(event_name, target=nil, options={})
9
+ changed
10
+ notify_observers(event_name, target=nil, options)
11
+ end
12
+ end
13
+
14
+ InitUser.instance.notify(:before_init, {:name => "foo"})
15
+ InitUser.instance.notify(:init, {:name => "foo"})
16
+ InitUser.instance.notify(:save, {:name => "foo"})
@@ -0,0 +1,41 @@
1
+ class HeroObserver
2
+
3
+ # Constructor...
4
+ #
5
+ # @example
6
+ # events = {
7
+ # :create_user => [
8
+ # FixData,
9
+ # Validate,
10
+ # etc...
11
+ # ],
12
+ # :checkout => [
13
+ # Verify,
14
+ # Charge,
15
+ # etc...
16
+ # ]
17
+ # }
18
+ #
19
+ # HeroObserver.new(hero, events)
20
+ # @param [Hero] hero The Hero object to watch.
21
+ # @param [Hash] handlers A Hash containing event names and the handlers to run at each event.
22
+ def initialize(hero, handlers)
23
+ @handlers = handlers
24
+ hero.instance.add_observer(self)
25
+ end
26
+
27
+ # Callback invoked whenever a Hero event is triggered.
28
+ #
29
+ # @param [String] event_name The name of the event.
30
+ # @param [Object] target The target of the event.
31
+ # @param [Hash] options An options Hash that gets forwarded to the rules.
32
+ def update(event_name, target, options={})
33
+ handler = @handlers[event_name] || []
34
+ handler.each do |handler|
35
+ handler_name = handler.name
36
+ handler.call(target, options)
37
+ end
38
+ end
39
+
40
+ end
41
+
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hero
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 0
9
+ version: 0.0.0
10
+ platform: ruby
11
+ authors:
12
+ - Nathan Hopkins
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2012-08-20 00:00:00 -06:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: " Simplify your apps with Hero.\n"
22
+ email:
23
+ - natehop@gmail.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - lib/hero.rb
32
+ - lib/hero_observer.rb
33
+ - Gemfile
34
+ has_rdoc: true
35
+ homepage: http://hopsoft.github.com/hero/
36
+ licenses:
37
+ - MIT
38
+ post_install_message:
39
+ rdoc_options: []
40
+
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ segments:
48
+ - 0
49
+ version: "0"
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ segments:
55
+ - 0
56
+ version: "0"
57
+ requirements: []
58
+
59
+ rubyforge_project:
60
+ rubygems_version: 1.3.6
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: Business process modeling for the Rubyist
64
+ test_files: []
65
+