onfire 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -0
- data/README.textile +1 -1
- data/Rakefile +5 -57
- data/lib/onfire/version.rb +2 -2
- data/lib/onfire.rb +3 -3
- data/onfire.gemspec +19 -0
- data/test/event_table_test.rb +2 -2
- data/test/event_test.rb +11 -2
- data/test/onfire_test.rb +17 -5
- metadata +24 -15
data/Gemfile
ADDED
data/README.textile
CHANGED
@@ -108,7 +108,7 @@ Which results in
|
|
108
108
|
|
109
109
|
h2. Using the @Event@ object
|
110
110
|
|
111
|
-
Of course _bill_ wants to find out who's the subversive element, so he just
|
111
|
+
Of course _bill_ wants to find out who's the subversive element, so he just asks the revealing *Event* object.
|
112
112
|
|
113
113
|
<pre>
|
114
114
|
bill.on :thatSucks do |event| event.source.fire! end
|
data/Rakefile
CHANGED
@@ -1,62 +1,10 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'rake/testtask'
|
4
|
-
require 'rake/rdoctask'
|
5
|
-
require File.join(File.dirname(__FILE__), 'lib', 'onfire', 'version')
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
6
3
|
|
7
|
-
|
8
|
-
task :default => :test
|
4
|
+
require 'rake/testtask'
|
9
5
|
|
10
|
-
desc 'Test the onfire library.'
|
11
6
|
Rake::TestTask.new(:test) do |test|
|
12
|
-
test.libs <<
|
13
|
-
test.
|
7
|
+
test.libs << 'test'
|
8
|
+
test.test_files = FileList['test/*_test.rb']
|
14
9
|
test.verbose = true
|
15
10
|
end
|
16
|
-
|
17
|
-
|
18
|
-
# Gem managment tasks.
|
19
|
-
#
|
20
|
-
# == Bump gem version (any):
|
21
|
-
#
|
22
|
-
# rake version:bump:major
|
23
|
-
# rake version:bump:minor
|
24
|
-
# rake version:bump:patch
|
25
|
-
#
|
26
|
-
# == Generate gemspec, build & install locally:
|
27
|
-
#
|
28
|
-
# rake gemspec
|
29
|
-
# rake build
|
30
|
-
# sudo rake install
|
31
|
-
#
|
32
|
-
# == Git tag & push to origin/master
|
33
|
-
#
|
34
|
-
# rake release
|
35
|
-
#
|
36
|
-
# == Release to Gemcutter.org:
|
37
|
-
#
|
38
|
-
# rake gemcutter:release
|
39
|
-
#
|
40
|
-
begin
|
41
|
-
gem 'jeweler'
|
42
|
-
require 'jeweler'
|
43
|
-
|
44
|
-
Jeweler::Tasks.new do |spec|
|
45
|
-
spec.name = "onfire"
|
46
|
-
spec.version = ::Onfire::VERSION
|
47
|
-
spec.summary = %{Have bubbling events and observers in all your Ruby objects.}
|
48
|
-
spec.description = spec.summary
|
49
|
-
spec.homepage = "http://github.com/apotonick/onfire"
|
50
|
-
spec.authors = ["Nick Sutterer"]
|
51
|
-
spec.email = "apotonick@gmail.com"
|
52
|
-
|
53
|
-
spec.files = FileList["[A-Z]*", File.join(*%w[{lib,test} ** *]).to_s]
|
54
|
-
|
55
|
-
# spec.add_dependency 'activesupport', '>= 2.3.0' # Dependencies and minimum versions?
|
56
|
-
end
|
57
|
-
|
58
|
-
Jeweler::GemcutterTasks.new
|
59
|
-
rescue LoadError
|
60
|
-
puts "Jeweler - or one of its dependencies - is not available. " <<
|
61
|
-
"Install it with: sudo gem install jeweler -s http://gemcutter.org"
|
62
|
-
end
|
data/lib/onfire/version.rb
CHANGED
data/lib/onfire.rb
CHANGED
@@ -14,8 +14,8 @@ module Onfire
|
|
14
14
|
attach_event_handler(options[:do], table_options)
|
15
15
|
end
|
16
16
|
|
17
|
-
def fire(event_type)
|
18
|
-
bubble_event Event.new(event_type, self)
|
17
|
+
def fire(event_type, data={})
|
18
|
+
bubble_event Event.new(event_type, self, data)
|
19
19
|
end
|
20
20
|
|
21
21
|
def bubble_event(event)
|
@@ -49,4 +49,4 @@ module Onfire
|
|
49
49
|
def local_event_handlers(event)
|
50
50
|
event_table.all_handlers_for(event.type, event.source)
|
51
51
|
end
|
52
|
-
end
|
52
|
+
end
|
data/onfire.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.unshift File.expand_path("../lib", __FILE__)
|
3
|
+
require "onfire/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "onfire"
|
7
|
+
s.version = Onfire::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Nick Sutterer"]
|
10
|
+
s.email = ["apotonick@gmail.com"]
|
11
|
+
s.homepage = "http://github.com/apotonick/onfire"
|
12
|
+
s.summary = %q{Have bubbling events and observers in all your Ruby objects.}
|
13
|
+
s.description = %q{Have bubbling events and observers in all your Ruby objects.}
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
end
|
data/test/event_table_test.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'test_helper'
|
2
2
|
|
3
3
|
class EventTableTest < Test::Unit::TestCase
|
4
4
|
|
@@ -27,4 +27,4 @@ class EventTableTest < Test::Unit::TestCase
|
|
27
27
|
assert_equal [:drink, :eat, :have_desert], @head.all_handlers_for(:hungry, :stomach)
|
28
28
|
end
|
29
29
|
end
|
30
|
-
end
|
30
|
+
end
|
data/test/event_test.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'test_helper'
|
2
2
|
|
3
3
|
class EventTest < Test::Unit::TestCase
|
4
4
|
context "An event" do
|
@@ -7,6 +7,7 @@ class EventTest < Test::Unit::TestCase
|
|
7
7
|
|
8
8
|
assert_equal :click, event.type
|
9
9
|
assert_equal :source, event.source
|
10
|
+
assert_nil event.data
|
10
11
|
end
|
11
12
|
|
12
13
|
should "be fine without any parameters at all" do
|
@@ -17,6 +18,14 @@ class EventTest < Test::Unit::TestCase
|
|
17
18
|
assert_nil event.data
|
18
19
|
end
|
19
20
|
|
21
|
+
should "accept payload data" do
|
22
|
+
event = Onfire::Event.new(:drag, :source, :target => 'me')
|
23
|
+
|
24
|
+
assert_equal :drag, event.type
|
25
|
+
assert_equal :source, event.source
|
26
|
+
assert_equal({:target => 'me'}, event.data)
|
27
|
+
end
|
28
|
+
|
20
29
|
should "stop if needed" do
|
21
30
|
event = Onfire::Event.new
|
22
31
|
|
@@ -25,4 +34,4 @@ class EventTest < Test::Unit::TestCase
|
|
25
34
|
assert event.stopped?
|
26
35
|
end
|
27
36
|
end
|
28
|
-
end
|
37
|
+
end
|
data/test/onfire_test.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'test_helper'
|
2
2
|
|
3
3
|
class OnfireTest < Test::Unit::TestCase
|
4
4
|
def mock(name='my_mock')
|
@@ -39,7 +39,7 @@ class OnfireTest < Test::Unit::TestCase
|
|
39
39
|
|
40
40
|
should "invoke exactly one proc and thus push `1` onto #list" do
|
41
41
|
obj = mock
|
42
|
-
obj.event_table.add_handler(lambda { obj.list << 1 }, :event_type => :click)
|
42
|
+
obj.event_table.add_handler(lambda { |evt| obj.list << 1 }, :event_type => :click)
|
43
43
|
|
44
44
|
obj.process_event(@event)
|
45
45
|
|
@@ -48,8 +48,8 @@ class OnfireTest < Test::Unit::TestCase
|
|
48
48
|
|
49
49
|
should "not invoke procs for another event_type" do
|
50
50
|
obj = mock
|
51
|
-
obj.event_table.add_handler(lambda{obj.list << 1}, :event_type => :click)
|
52
|
-
obj.event_table.add_handler(lambda{obj.list << 2}, :event_type => :drop) # don't call me!
|
51
|
+
obj.event_table.add_handler(lambda { |evt| obj.list << 1 }, :event_type => :click)
|
52
|
+
obj.event_table.add_handler(lambda { |evt| obj.list << 2 }, :event_type => :drop) # don't call me!
|
53
53
|
|
54
54
|
obj.process_event(@event)
|
55
55
|
|
@@ -239,6 +239,18 @@ class OnfireTest < Test::Unit::TestCase
|
|
239
239
|
assert_equal ['A beer!', 'There you go.', 'Hurry up, man!', 'Thanks.'], @obj.list
|
240
240
|
end
|
241
241
|
|
242
|
+
should "allow appending arbitrary data to the event" do
|
243
|
+
# we use @obj for recording the chat.
|
244
|
+
bar = mock('bar')
|
245
|
+
|
246
|
+
bar.on :thirsty do |evt|
|
247
|
+
@obj.list << "You look like #{evt.data[:who]} need a drink."
|
248
|
+
end
|
249
|
+
|
250
|
+
bar.fire :thirsty, :who => "I"
|
251
|
+
|
252
|
+
assert_equal ["You look like I need a drink."], @obj.list
|
253
|
+
end
|
242
254
|
end
|
243
255
|
|
244
256
|
|
@@ -257,4 +269,4 @@ class OnfireTest < Test::Unit::TestCase
|
|
257
269
|
end
|
258
270
|
end
|
259
271
|
|
260
|
-
end
|
272
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: onfire
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Nick Sutterer
|
@@ -9,25 +14,28 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date:
|
17
|
+
date: 2011-01-02 00:00:00 +01:00
|
13
18
|
default_executable:
|
14
19
|
dependencies: []
|
15
20
|
|
16
21
|
description: Have bubbling events and observers in all your Ruby objects.
|
17
|
-
email:
|
22
|
+
email:
|
23
|
+
- apotonick@gmail.com
|
18
24
|
executables: []
|
19
25
|
|
20
26
|
extensions: []
|
21
27
|
|
22
|
-
extra_rdoc_files:
|
23
|
-
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
24
30
|
files:
|
31
|
+
- Gemfile
|
25
32
|
- README.textile
|
26
33
|
- Rakefile
|
27
34
|
- lib/onfire.rb
|
28
35
|
- lib/onfire/event.rb
|
29
36
|
- lib/onfire/event_table.rb
|
30
37
|
- lib/onfire/version.rb
|
38
|
+
- onfire.gemspec
|
31
39
|
- test/event_table_test.rb
|
32
40
|
- test/event_test.rb
|
33
41
|
- test/onfire_test.rb
|
@@ -37,31 +45,32 @@ homepage: http://github.com/apotonick/onfire
|
|
37
45
|
licenses: []
|
38
46
|
|
39
47
|
post_install_message:
|
40
|
-
rdoc_options:
|
41
|
-
|
48
|
+
rdoc_options: []
|
49
|
+
|
42
50
|
require_paths:
|
43
51
|
- lib
|
44
52
|
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
45
54
|
requirements:
|
46
55
|
- - ">="
|
47
56
|
- !ruby/object:Gem::Version
|
57
|
+
segments:
|
58
|
+
- 0
|
48
59
|
version: "0"
|
49
|
-
version:
|
50
60
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
51
62
|
requirements:
|
52
63
|
- - ">="
|
53
64
|
- !ruby/object:Gem::Version
|
65
|
+
segments:
|
66
|
+
- 0
|
54
67
|
version: "0"
|
55
|
-
version:
|
56
68
|
requirements: []
|
57
69
|
|
58
70
|
rubyforge_project:
|
59
|
-
rubygems_version: 1.3.
|
71
|
+
rubygems_version: 1.3.7
|
60
72
|
signing_key:
|
61
73
|
specification_version: 3
|
62
74
|
summary: Have bubbling events and observers in all your Ruby objects.
|
63
|
-
test_files:
|
64
|
-
|
65
|
-
- test/test_helper.rb
|
66
|
-
- test/event_table_test.rb
|
67
|
-
- test/event_test.rb
|
75
|
+
test_files: []
|
76
|
+
|