event_object 0.9.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -11
- data/lib/event_object/class.rb +6 -2
- data/lib/event_object/object.rb +3 -3
- data/lib/event_object/version.rb +1 -1
- metadata +3 -6
- data/lib/event/array.rb +0 -16
- data/lib/event/class.rb +0 -17
- data/lib/event/object.rb +0 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9622ba5227d8436103a9b8d27c5c8c43499b81a
|
4
|
+
data.tar.gz: 47849679660a76bc72bdc824e901a4f7318c8baf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4475ff5a3264ab6b919b6f958edcbf06ba677cc267ab024206892067e6bace0776c50b815c8f46abf7a17fd5b8296c4b120b2d62eb64e7a518a4afa028979bab
|
7
|
+
data.tar.gz: 0003f2b71961aeef736f64d04b3f8347c2601e0e6ebe4e7f0d48e7d277a54e9defa592529def1abfebf6d50ce021b8ff7acf938c54958364023cd8ae7e818509
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# EventObject
|
2
2
|
|
3
3
|
EventObject - event-driven programming for ruby
|
4
4
|
|
@@ -7,7 +7,7 @@ EventObject - event-driven programming for ruby
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
9
|
```ruby
|
10
|
-
gem '
|
10
|
+
gem 'event_object'
|
11
11
|
```
|
12
12
|
|
13
13
|
And then execute:
|
@@ -16,7 +16,7 @@ And then execute:
|
|
16
16
|
|
17
17
|
Or install it yourself as:
|
18
18
|
|
19
|
-
$ gem install
|
19
|
+
$ gem install event_object
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
@@ -32,11 +32,3 @@ emitter.on :success do
|
|
32
32
|
end
|
33
33
|
p emitter.success!
|
34
34
|
```
|
35
|
-
|
36
|
-
## Contributing
|
37
|
-
|
38
|
-
1. Fork it ( https://github.com/[my-github-username]/event-object/fork )
|
39
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
40
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
41
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
42
|
-
5. Create a new Pull Request
|
data/lib/event_object/class.rb
CHANGED
@@ -4,14 +4,18 @@ module EventObject
|
|
4
4
|
define_method met, &b
|
5
5
|
end
|
6
6
|
|
7
|
+
def cdef(met, &b)
|
8
|
+
define_singleton_method met, &b
|
9
|
+
end
|
10
|
+
|
7
11
|
def events(*ev)
|
8
12
|
ev.each { |name| self.def(name) { var(name, Array) } }
|
9
13
|
ev.each { |name| self.def("#{name}!") { |*a| var(name, Array).fire(*a) } }
|
10
14
|
end
|
11
15
|
|
12
|
-
def var(name, init)
|
16
|
+
def var(name, init=nil)
|
13
17
|
key = "@#{name}"
|
14
|
-
class_variable_defined?(key) ? class_variable_get(key) : class_variable_set(key, init.new)
|
18
|
+
class_variable_defined?(key) ? class_variable_get(key) : class_variable_set(key, (init.is_a?(Class) ? init.new : init))
|
15
19
|
end
|
16
20
|
end
|
17
21
|
end
|
data/lib/event_object/object.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module EventObject
|
2
2
|
refine Object do
|
3
3
|
def def(method, &b)
|
4
|
-
|
4
|
+
define_method method, &b
|
5
5
|
end
|
6
6
|
|
7
|
-
def var(name, init)
|
8
|
-
instance_variable_get("@#{name}") || instance_variable_set("@#{name}", init.new)
|
7
|
+
def var(name, init=nil)
|
8
|
+
instance_variable_get("@#{name}") || instance_variable_set("@#{name}", (init.is_a?(Class) ? init.new : init))
|
9
9
|
end
|
10
10
|
|
11
11
|
def on(name, &b)
|
data/lib/event_object/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: event_object
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- che
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -65,9 +65,6 @@ files:
|
|
65
65
|
- README.md
|
66
66
|
- Rakefile
|
67
67
|
- event_object.gemspec
|
68
|
-
- lib/event/array.rb
|
69
|
-
- lib/event/class.rb
|
70
|
-
- lib/event/object.rb
|
71
68
|
- lib/event_object.rb
|
72
69
|
- lib/event_object/array.rb
|
73
70
|
- lib/event_object/class.rb
|
@@ -96,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
93
|
version: 2.3.0
|
97
94
|
requirements: []
|
98
95
|
rubyforge_project:
|
99
|
-
rubygems_version: 2.4.
|
96
|
+
rubygems_version: 2.4.3
|
100
97
|
signing_key:
|
101
98
|
specification_version: 4
|
102
99
|
summary: EventObject - do ruby object to be event-driven
|
data/lib/event/array.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
module EventObject
|
2
|
-
class Array
|
3
|
-
# array like event
|
4
|
-
def fire(*a, &b)
|
5
|
-
each { |h| h.call(*a, &b) }
|
6
|
-
end
|
7
|
-
|
8
|
-
def fire_for(t, *a)
|
9
|
-
each { |h| t.instance_exec(*a, &h) }
|
10
|
-
end
|
11
|
-
|
12
|
-
def off(proc=nil)
|
13
|
-
(proc) ? delete(proc) : clear
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
data/lib/event/class.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
module Event
|
2
|
-
refine Class
|
3
|
-
def def(method, &b)
|
4
|
-
define_method method, &b
|
5
|
-
end
|
6
|
-
|
7
|
-
def events(*names)
|
8
|
-
names.each { |name| self.def(name) { var(name, Array) } }
|
9
|
-
names.each { |name| self.def("#{name}!") { |*a| var(name, Array).fire(*a) } }
|
10
|
-
end
|
11
|
-
|
12
|
-
def var(name, init=nil)
|
13
|
-
key = "@#{name}"
|
14
|
-
class_variable_defined?(key) ? class_variable_get(key) : class_variable_set(key, init.new)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
data/lib/event/object.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
module Event
|
2
|
-
refine Object
|
3
|
-
def def(method, &b)
|
4
|
-
define_singleton_method method, &b
|
5
|
-
end
|
6
|
-
|
7
|
-
def var(name, init=nil)
|
8
|
-
instance_variable_get("@#{name}") || instance_variable_set("@#{name}", init.new)
|
9
|
-
end
|
10
|
-
|
11
|
-
def on(name, &b)
|
12
|
-
var(name, Array).tap { |e| e << b }; b
|
13
|
-
end
|
14
|
-
|
15
|
-
#
|
16
|
-
# obj.off(:data)
|
17
|
-
# obj.off(:data, proc)
|
18
|
-
# obj.off(target, :data, proc) => target.off(:data, proc)
|
19
|
-
def off(*a)
|
20
|
-
case a.size
|
21
|
-
when 1 then var(a[0], Array).clear
|
22
|
-
when 2 then var(a[0], Array).tap { |e| e.delete a[1] }
|
23
|
-
when 3 then a[0].off(a[1], a[2])
|
24
|
-
end
|
25
|
-
self
|
26
|
-
end
|
27
|
-
|
28
|
-
def once(name, &b)
|
29
|
-
(ev = nil).tap { |ev|
|
30
|
-
var(name, Array).tap { |e| e << (ev = ->() { b.call; e.delete(ev) }) }
|
31
|
-
}
|
32
|
-
end
|
33
|
-
|
34
|
-
def listen(object, name, meth)
|
35
|
-
object.on :name, &method(meth)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|