bjallen-hit_me_back 1.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.
- data/LICENSE +20 -0
- data/README +0 -0
- data/README.rdoc +7 -0
- data/Rakefile +57 -0
- data/VERSION +1 -0
- data/hit_me_back.gemspec +50 -0
- data/lib/hit_me_back/event.rb +10 -0
- data/lib/hit_me_back.rb +29 -0
- data/pkg/hit_me_back-0.0.0.gem +0 -0
- data/pkg/hit_me_back-1.0.0.gem +0 -0
- data/test/hit_me_back_test.rb +58 -0
- data/test/test_helper.rb +48 -0
- metadata +67 -0
data/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2009 B.J. Allen
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
|
File without changes
|
data/README.rdoc
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
= hit_me_back
|
|
2
|
+
|
|
3
|
+
Hit Me Back is a simple subscribe/notify observer pattern framework. It has no dependencies which allows it to work well in situations where you are packaging up self-contained applications that may or may not be using their own embedded ruby vm.
|
|
4
|
+
|
|
5
|
+
== Copyright
|
|
6
|
+
|
|
7
|
+
Copyright (c) 2009 B.J. Allen. See LICENSE for details.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'rake'
|
|
3
|
+
|
|
4
|
+
begin
|
|
5
|
+
require 'jeweler'
|
|
6
|
+
Jeweler::Tasks.new do |gem|
|
|
7
|
+
gem.name = "hit_me_back"
|
|
8
|
+
gem.summary = %Q{Hit Me Back is a simple subscribe/notify observer pattern framework.}
|
|
9
|
+
gem.description = %Q{Simple subscribe/notify observer pattern framework for Ruby projects}
|
|
10
|
+
gem.email = "bjallen@mac.com"
|
|
11
|
+
gem.homepage = "http://github.com/bjallen/hit_me_back"
|
|
12
|
+
gem.authors = ["B.J. Allen"]
|
|
13
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
rescue LoadError
|
|
17
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
require 'rake/testtask'
|
|
21
|
+
Rake::TestTask.new(:test) do |test|
|
|
22
|
+
test.libs << 'lib' << 'test'
|
|
23
|
+
test.pattern = 'test/**/*_test.rb'
|
|
24
|
+
test.verbose = true
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
begin
|
|
28
|
+
require 'rcov/rcovtask'
|
|
29
|
+
Rcov::RcovTask.new do |test|
|
|
30
|
+
test.libs << 'test'
|
|
31
|
+
test.pattern = 'test/**/*_test.rb'
|
|
32
|
+
test.verbose = true
|
|
33
|
+
end
|
|
34
|
+
rescue LoadError
|
|
35
|
+
task :rcov do
|
|
36
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
task :default => :test
|
|
42
|
+
|
|
43
|
+
require 'rake/rdoctask'
|
|
44
|
+
Rake::RDocTask.new do |rdoc|
|
|
45
|
+
if File.exist?('VERSION.yml')
|
|
46
|
+
config = YAML.load(File.read('VERSION.yml'))
|
|
47
|
+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
|
48
|
+
else
|
|
49
|
+
version = ""
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
rdoc.rdoc_dir = 'rdoc'
|
|
53
|
+
rdoc.title = "hit_me_back #{version}"
|
|
54
|
+
rdoc.rdoc_files.include('README*')
|
|
55
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
56
|
+
end
|
|
57
|
+
|
data/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
1.0.1
|
data/hit_me_back.gemspec
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
Gem::Specification.new do |s|
|
|
4
|
+
s.name = %q{hit_me_back}
|
|
5
|
+
s.version = "1.0.1"
|
|
6
|
+
|
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
8
|
+
s.authors = ["B.J. Allen"]
|
|
9
|
+
s.date = %q{2009-07-03}
|
|
10
|
+
s.description = %q{Simple subscribe/notify observer pattern framework for Ruby projects}
|
|
11
|
+
s.email = %q{bjallen@mac.com}
|
|
12
|
+
s.extra_rdoc_files = [
|
|
13
|
+
"LICENSE",
|
|
14
|
+
"README",
|
|
15
|
+
"README.rdoc"
|
|
16
|
+
]
|
|
17
|
+
s.files = [
|
|
18
|
+
"LICENSE",
|
|
19
|
+
"README",
|
|
20
|
+
"README.rdoc",
|
|
21
|
+
"Rakefile",
|
|
22
|
+
"VERSION",
|
|
23
|
+
"hit_me_back.gemspec",
|
|
24
|
+
"lib/hit_me_back.rb",
|
|
25
|
+
"lib/hit_me_back/event.rb",
|
|
26
|
+
"pkg/hit_me_back-0.0.0.gem",
|
|
27
|
+
"pkg/hit_me_back-1.0.0.gem",
|
|
28
|
+
"test/hit_me_back_test.rb",
|
|
29
|
+
"test/test_helper.rb"
|
|
30
|
+
]
|
|
31
|
+
s.homepage = %q{http://github.com/bjallen/hit_me_back}
|
|
32
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
|
33
|
+
s.require_paths = ["lib"]
|
|
34
|
+
s.rubygems_version = %q{1.3.3}
|
|
35
|
+
s.summary = %q{Hit Me Back is a simple subscribe/notify observer pattern framework.}
|
|
36
|
+
s.test_files = [
|
|
37
|
+
"test/hit_me_back_test.rb",
|
|
38
|
+
"test/test_helper.rb"
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
if s.respond_to? :specification_version then
|
|
42
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
|
43
|
+
s.specification_version = 3
|
|
44
|
+
|
|
45
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
|
46
|
+
else
|
|
47
|
+
end
|
|
48
|
+
else
|
|
49
|
+
end
|
|
50
|
+
end
|
data/lib/hit_me_back.rb
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module HitMeBack
|
|
2
|
+
|
|
3
|
+
attr_accessor :events
|
|
4
|
+
|
|
5
|
+
def add_listener(event_name, listener)
|
|
6
|
+
@events = [] if @events.nil?
|
|
7
|
+
matching_events = @events.find_all { |event| event.name == event_name }
|
|
8
|
+
|
|
9
|
+
if matching_events.empty?
|
|
10
|
+
@events << Event.new(event_name, listener)
|
|
11
|
+
else
|
|
12
|
+
matching_events.first.listeners << listener
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def remove_listener(event_name, listener)
|
|
17
|
+
event = @events.find { |x| x.name == event_name }
|
|
18
|
+
event.listeners.reject! { |x| x == listener } unless event.nil?
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def notify_listeners(event_name)
|
|
22
|
+
event = @events.find { |x| x.name == event_name }
|
|
23
|
+
event.listeners.each do |listener|
|
|
24
|
+
listener.send(event.name, self) if listener.respond_to?(event.name)
|
|
25
|
+
end unless event.nil?
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
require 'hit_me_back/event'
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class HitMeBackTest < Test::Unit::TestCase
|
|
4
|
+
|
|
5
|
+
def setup
|
|
6
|
+
@ac = AppController.new
|
|
7
|
+
@bp = BackgroundProcess.new
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def test_for_addition_of_module_methods
|
|
11
|
+
x = PlainClass.new
|
|
12
|
+
methods_to_check_for = ['events','add_listener','remove_listener','notify_listeners']
|
|
13
|
+
common_methods_before = methods_to_check_for & x.methods
|
|
14
|
+
x.extend(HitMeBack)
|
|
15
|
+
common_methods_after = methods_to_check_for & x.methods
|
|
16
|
+
assert_equal common_methods_after.size, common_methods_before.size + methods_to_check_for.size
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def test_for_ability_to_add_an_event
|
|
20
|
+
@bp.add_listener(:something_happened, @ac)
|
|
21
|
+
assert !@bp.events.find { |x| x.name == :something_happened }.nil?
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def test_for_ability_to_add_listener
|
|
25
|
+
@bp.add_listener(:something_happened, @ac)
|
|
26
|
+
event = @bp.events.find { |x| x.name == :something_happened }
|
|
27
|
+
flunk 'the event called :something_happened was not found' if event.nil?
|
|
28
|
+
listeners = event.listeners.find_all { |x| x.class == AppController }
|
|
29
|
+
assert_equal listeners.size, 1
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def test_for_ability_to_remove_listener
|
|
33
|
+
@bp.add_listener(:something_happened, @ac)
|
|
34
|
+
@bp.remove_listener(:something_happened, @ac)
|
|
35
|
+
event = @bp.events.find { |x| x.name == :something_happened }
|
|
36
|
+
flunk 'the event called :something_happened was not found' if event.nil?
|
|
37
|
+
listeners = event.listeners.find_all { |x| x.class == AppController }
|
|
38
|
+
assert_equal listeners.size, 0
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def test_that_correct_method_is_called_on_listener
|
|
42
|
+
@bp.add_listener(:something_happened, @ac)
|
|
43
|
+
@bp.add_listener(:process_completed, @ac)
|
|
44
|
+
flunk 'the notified flag was true too early' if @ac.notified_of_completion
|
|
45
|
+
@bp.notify_listeners(:something_happened)
|
|
46
|
+
flunk 'the notified flag was set for the wrong event' if @ac.notified_of_completion
|
|
47
|
+
@bp.notify_listeners(:process_completed)
|
|
48
|
+
assert @ac.notified_of_completion
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def test_that_the_notifier_is_passed_to_the_listener
|
|
52
|
+
@bp.name = 'my process 1234'
|
|
53
|
+
@bp.add_listener(:process_completed, @ac)
|
|
54
|
+
@bp.notify_listeners(:process_completed)
|
|
55
|
+
assert_equal @ac.notifier.name, 'my process 1234'
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
end
|
data/test/test_helper.rb
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'test/unit'
|
|
3
|
+
|
|
4
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
5
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
6
|
+
require 'hit_me_back'
|
|
7
|
+
|
|
8
|
+
class Test::Unit::TestCase
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
class AppController
|
|
12
|
+
attr_accessor :process_started, :notified_of_completion
|
|
13
|
+
attr_accessor :notifier
|
|
14
|
+
def initialize
|
|
15
|
+
@process_started = false
|
|
16
|
+
@notified_of_completion = false
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def start_process
|
|
20
|
+
@process_started = true
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def process_completed(obj)
|
|
24
|
+
@notified_of_completion = true
|
|
25
|
+
@notifier = obj
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
class BackgroundProcess
|
|
30
|
+
include HitMeBack
|
|
31
|
+
attr_accessor :process_started, :notified_of_completion
|
|
32
|
+
attr_accessor :name
|
|
33
|
+
def initialize
|
|
34
|
+
@process_started = false
|
|
35
|
+
@notified_of_completion = false
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def start_process
|
|
39
|
+
@process_started = true
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def process_completed
|
|
43
|
+
@notified_of_completion = true
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
class PlainClass
|
|
48
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: bjallen-hit_me_back
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- B.J. Allen
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2009-07-03 00:00:00 -07:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies: []
|
|
15
|
+
|
|
16
|
+
description: Simple subscribe/notify observer pattern framework for Ruby projects
|
|
17
|
+
email: bjallen@mac.com
|
|
18
|
+
executables: []
|
|
19
|
+
|
|
20
|
+
extensions: []
|
|
21
|
+
|
|
22
|
+
extra_rdoc_files:
|
|
23
|
+
- LICENSE
|
|
24
|
+
- README
|
|
25
|
+
- README.rdoc
|
|
26
|
+
files:
|
|
27
|
+
- LICENSE
|
|
28
|
+
- README
|
|
29
|
+
- README.rdoc
|
|
30
|
+
- Rakefile
|
|
31
|
+
- VERSION
|
|
32
|
+
- hit_me_back.gemspec
|
|
33
|
+
- lib/hit_me_back.rb
|
|
34
|
+
- lib/hit_me_back/event.rb
|
|
35
|
+
- pkg/hit_me_back-0.0.0.gem
|
|
36
|
+
- pkg/hit_me_back-1.0.0.gem
|
|
37
|
+
- test/hit_me_back_test.rb
|
|
38
|
+
- test/test_helper.rb
|
|
39
|
+
has_rdoc: false
|
|
40
|
+
homepage: http://github.com/bjallen/hit_me_back
|
|
41
|
+
post_install_message:
|
|
42
|
+
rdoc_options:
|
|
43
|
+
- --charset=UTF-8
|
|
44
|
+
require_paths:
|
|
45
|
+
- lib
|
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
47
|
+
requirements:
|
|
48
|
+
- - ">="
|
|
49
|
+
- !ruby/object:Gem::Version
|
|
50
|
+
version: "0"
|
|
51
|
+
version:
|
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
53
|
+
requirements:
|
|
54
|
+
- - ">="
|
|
55
|
+
- !ruby/object:Gem::Version
|
|
56
|
+
version: "0"
|
|
57
|
+
version:
|
|
58
|
+
requirements: []
|
|
59
|
+
|
|
60
|
+
rubyforge_project:
|
|
61
|
+
rubygems_version: 1.2.0
|
|
62
|
+
signing_key:
|
|
63
|
+
specification_version: 3
|
|
64
|
+
summary: Hit Me Back is a simple subscribe/notify observer pattern framework.
|
|
65
|
+
test_files:
|
|
66
|
+
- test/hit_me_back_test.rb
|
|
67
|
+
- test/test_helper.rb
|