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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7078b01a38aaeae3a94e66a5fa514788bd2a0719
4
- data.tar.gz: e372d4c456670a72b566bf5e360b8917637bc0cd
3
+ metadata.gz: c9622ba5227d8436103a9b8d27c5c8c43499b81a
4
+ data.tar.gz: 47849679660a76bc72bdc824e901a4f7318c8baf
5
5
  SHA512:
6
- metadata.gz: ba6bee4551c6502e8335f161f688de7a1804b13dbbc8bb779f56f98386e5146219c67865236aca2b7756a659d673b5a810d1bfb91d1ac7578ebc55d6e4181cbf
7
- data.tar.gz: 5a0b4328ffeb3d9cc3526d7c4a32f737dd1bf17a57bb020b6cfa9dc8a39549c24f1a856168ef327f59f21af66a4f7ce447ebed50870a87d1c44a6eac30f29863
6
+ metadata.gz: 4475ff5a3264ab6b919b6f958edcbf06ba677cc267ab024206892067e6bace0776c50b815c8f46abf7a17fd5b8296c4b120b2d62eb64e7a518a4afa028979bab
7
+ data.tar.gz: 0003f2b71961aeef736f64d04b3f8347c2601e0e6ebe4e7f0d48e7d277a54e9defa592529def1abfebf6d50ce021b8ff7acf938c54958364023cd8ae7e818509
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Event::Object
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 'event-object'
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 event-object
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
@@ -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
@@ -1,11 +1,11 @@
1
1
  module EventObject
2
2
  refine Object do
3
3
  def def(method, &b)
4
- define_singleton_method method, &b
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)
@@ -1,3 +1,3 @@
1
1
  module EventObject
2
- VERSION = "0.9.0"
2
+ VERSION = "0.9.1"
3
3
  end
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.0
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: 2014-08-12 00:00:00.000000000 Z
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.1
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
@@ -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
@@ -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
@@ -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