beacon 0.1

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.
Files changed (7) hide show
  1. data/.gitignore +2 -0
  2. data/LICENSE +23 -0
  3. data/README.rdoc +43 -0
  4. data/Rakefile +33 -0
  5. data/beacon.gemspec +31 -0
  6. data/lib/beacon.rb +26 -0
  7. metadata +87 -0
@@ -0,0 +1,2 @@
1
+ doc
2
+ *.gem
data/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2008-2009 Nicolas Sanguinetti, entp.com
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ 'Software'), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+
@@ -0,0 +1,43 @@
1
+ = Beacon
2
+
3
+ Simple observers and notifiers for your code.
4
+
5
+ The library aims to provide the simplest implementation possible. You get
6
+ <i>beacons</i>, which are always global and can be "lit up". Whenever you
7
+ light a beacon up, everyone watching will act as instructed.
8
+
9
+ == How to use this?
10
+
11
+ Whenever you want to fire an event from your code, call <tt>Beacon.fire</tt>:
12
+
13
+ def do_something
14
+ Beacon.fire(:before_doing_something)
15
+ # do your thing
16
+ end
17
+
18
+ In order to register listeners for that event, call <tt>Beacon.watch</tt>:
19
+
20
+ Beacon.watch :before_doing_something do
21
+ logger.info "I'm about to do something"
22
+ end
23
+
24
+ Each time you call <tt>watch</tt> with a given name, you register a different
25
+ handler for that name. Each time you call <tt>fire</tt> <b>all</b> handlers
26
+ for that event are run, in the order they were registered.
27
+
28
+ == Passing arguments
29
+
30
+ If you want to pass arguments to the watchers, just pass them along in
31
+ <tt>Beacon.fire</tt>:
32
+
33
+ Beacon.fire(:an_event, "cuack", 3)
34
+
35
+ And you'll get them as arguments on the block that handles the message:
36
+
37
+ Beacon.watch :an_event do |object, index|
38
+ # here object == "cuack", index == 3
39
+ end
40
+
41
+ == License
42
+
43
+ The code is licensed under an MIT license. Check the LICENSE file for details.
@@ -0,0 +1,33 @@
1
+ require "rake/testtask"
2
+
3
+ begin
4
+ require "hanna/rdoctask"
5
+ rescue LoadError
6
+ require "rake/rdoctask"
7
+ end
8
+
9
+ begin
10
+ require "metric_fu"
11
+ rescue LoadError
12
+ end
13
+
14
+ begin
15
+ require "mg"
16
+ MG.new("beacon.gemspec")
17
+ rescue LoadError
18
+ end
19
+
20
+ desc "Default: run all tests"
21
+ task :default => :test
22
+
23
+ desc "Run web application tests"
24
+ Rake::TestTask.new(:test) do |t|
25
+ t.test_files = FileList["test/**/*_test.rb"]
26
+ end
27
+
28
+ Rake::RDocTask.new do |rd|
29
+ rd.main = "README"
30
+ rd.title = "Beacon Documentation"
31
+ rd.rdoc_files.include("README.rdoc", "LICENSE", "lib/**/*.rb")
32
+ rd.rdoc_dir = "doc"
33
+ end
@@ -0,0 +1,31 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "beacon"
3
+ s.version = "0.1"
4
+ s.date = "2009-04-22"
5
+
6
+ s.description = "Simple and straightforward observers for your code"
7
+ s.summary = "Simple and straightforward observers for your code"
8
+ s.homepage = "http://github.com/foca/beacon"
9
+
10
+ s.authors = ["Nicolás Sanguinetti"]
11
+ s.email = "contacto@nicolassanguinetti.info"
12
+
13
+ s.require_paths = ["lib"]
14
+ s.has_rdoc = true
15
+ s.rubygems_version = "1.3.1"
16
+
17
+ if s.respond_to?(:add_development_dependency)
18
+ s.add_development_dependency "sr-mg"
19
+ s.add_development_dependency "contest"
20
+ s.add_development_dependency "redgreen"
21
+ end
22
+
23
+ s.files = %w[
24
+ .gitignore
25
+ LICENSE
26
+ README.rdoc
27
+ Rakefile
28
+ beacon.gemspec
29
+ lib/beacon.rb
30
+ ]
31
+ end
@@ -0,0 +1,26 @@
1
+ module Beacon
2
+ # Fire an event to be processed by all the watchers. You pass the event name
3
+ # and any arguments you want passed to the event handlers.
4
+ #
5
+ # Beacon.fire(:some_event, "an argument", 2, "another")
6
+ def self.fire(event, *args)
7
+ events[event].each do |callback|
8
+ callback.call(*args)
9
+ end
10
+ end
11
+
12
+ # Register a callback for a given event. Each time you call <tt>fire</tt> then
13
+ # all the callbacks registered for that name will be called in order.
14
+ #
15
+ # Beacon.watch :some_event do |foo, bar, baz|
16
+ # # do stuff with foo, bar, and baz
17
+ # end
18
+ def self.watch(event, &handler)
19
+ events[event] << handler
20
+ end
21
+
22
+ def self.events
23
+ @events ||= Hash.new {|h,k| h[k] = [] }
24
+ end
25
+ private_class_method :events
26
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: beacon
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.1"
5
+ platform: ruby
6
+ authors:
7
+ - "Nicol\xC3\xA1s Sanguinetti"
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-04-22 00:00:00 -03:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: sr-mg
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: contest
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: redgreen
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ description: Simple and straightforward observers for your code
46
+ email: contacto@nicolassanguinetti.info
47
+ executables: []
48
+
49
+ extensions: []
50
+
51
+ extra_rdoc_files: []
52
+
53
+ files:
54
+ - .gitignore
55
+ - LICENSE
56
+ - README.rdoc
57
+ - Rakefile
58
+ - beacon.gemspec
59
+ - lib/beacon.rb
60
+ has_rdoc: true
61
+ homepage: http://github.com/foca/beacon
62
+ post_install_message:
63
+ rdoc_options: []
64
+
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: "0"
72
+ version:
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "0"
78
+ version:
79
+ requirements: []
80
+
81
+ rubyforge_project:
82
+ rubygems_version: 1.3.1
83
+ signing_key:
84
+ specification_version: 2
85
+ summary: Simple and straightforward observers for your code
86
+ test_files: []
87
+