unobservable 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/VERSION +1 -1
  2. data/lib/unobservable.rb +30 -4
  3. metadata +3 -3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.5.0
data/lib/unobservable.rb CHANGED
@@ -6,19 +6,28 @@ module Unobservable
6
6
  # not that module includes the Unobservable::ModuleSupport mixin. If
7
7
  # include_supers = true, then the list will also contain instance events
8
8
  # defined by superclasses and included modules. By default, include_supers = true
9
- def self.instance_events_for(mod, include_supers = true)
9
+ def self.instance_events_for(mod, all = true)
10
10
  raise TypeError, "Only modules and classes can have instance_events" unless mod.is_a? Module
11
11
 
12
12
  contributors = [mod]
13
- if include_supers
13
+ if all
14
14
  contributors += mod.included_modules
15
- contributors += mod.ancestors[1...-1] if mod.is_a? Class
15
+ if mod.is_a? Class
16
+ ancestors = mod.ancestors
17
+ if ancestors[0] == mod
18
+ contributors += ancestors[1..-1]
19
+ else
20
+ contributors += ancestors
21
+ end
22
+ end
16
23
  end
17
24
 
18
25
  self.collect_instance_events_defined_by(contributors)
19
26
  end
20
27
 
21
28
 
29
+ # Produces a list of instance events that are explicitly defined by at least
30
+ # one of the specified modules.
22
31
  def self.collect_instance_events_defined_by(contributors)
23
32
  retval = Set.new
24
33
 
@@ -68,15 +77,23 @@ module Unobservable
68
77
 
69
78
  module Support
70
79
 
80
+ # When an individual object EXTENDS the Support module, then
81
+ # we must ensure that the object's singleton class EXTENDS
82
+ # ModuleSupport.
71
83
  def self.extended(obj)
72
84
  obj.singleton_class.extend ModuleSupport
73
85
  end
74
86
 
87
+ # When a class/module INCLUDES the Support module, then we
88
+ # must ensure that the class/module also EXTENDS ModuleSupport.
75
89
  def self.included(other_mod)
76
90
  other_mod.extend ModuleSupport
77
91
  end
78
92
 
79
93
 
94
+ # Obtains the list of events that are unique to this object.
95
+ # If all = true, then this list will also include events that
96
+ # were defined within a module that the object extended.
80
97
  def singleton_events(all = true)
81
98
  if all
82
99
  contributors = self.singleton_class.included_modules
@@ -88,15 +105,21 @@ module Unobservable
88
105
  end
89
106
  end
90
107
 
91
-
108
+ # Defines an event directly on the object.
92
109
  def define_singleton_event(*name)
93
110
  self.singleton_class.send(:attr_event, *name)
94
111
  end
95
112
 
113
+ # Obtains the names of the events that are supported by this object. If
114
+ # all = false, then this list will only contain the names of the instance
115
+ # events that are explicitly defined by the object's class.
96
116
  def events(all = true)
97
117
  self.singleton_class.instance_events(all)
98
118
  end
99
119
 
120
+
121
+ # Returns the Event that has the specified name. A NameError will be raised
122
+ # if the object does not define any event that has the given name.
100
123
  def event(name)
101
124
  @unobservable_events_map ||= {}
102
125
  e = @unobservable_events_map[name]
@@ -112,6 +135,9 @@ module Unobservable
112
135
  end
113
136
 
114
137
  private
138
+
139
+ # Calls the Event that has the specified name. A NameError will be raised
140
+ # if the object does not define any event that has the given name.
115
141
  def raise_event(name, *args, &block)
116
142
  event(name).call(*args, &block)
117
143
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unobservable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-21 00:00:00.000000000 Z
12
+ date: 2012-11-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: shoulda
@@ -108,7 +108,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
108
108
  version: '0'
109
109
  segments:
110
110
  - 0
111
- hash: -2089249244928206460
111
+ hash: 4239055306913314612
112
112
  required_rubygems_version: !ruby/object:Gem::Requirement
113
113
  none: false
114
114
  requirements: