unobservable 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.rdoc +74 -1
  2. data/VERSION +1 -1
  3. metadata +2 -2
data/README.rdoc CHANGED
@@ -1,10 +1,83 @@
1
1
  = unobservable
2
2
 
3
3
  Ruby's Observable mixin is often characterized as an Event Handler library. In reality, it only provides basic
4
- support for "Property Changed" notifications.
4
+ support for "Property Changed" notifications.
5
5
 
6
6
  Unobservable strives to be a general-purpose Event Handler library.
7
7
 
8
+
9
+ == Usage
10
+
11
+ === Adding Event support to classes
12
+
13
+ Support for events can be added on a per-class basis by including the Unobservable::Support module in the desired classes.
14
+ For example:
15
+
16
+ require 'unobservable'
17
+
18
+ class Button
19
+ include Unobservable::Support
20
+ end
21
+
22
+ Now the Button class, as well as all of its subclasses, will have support for events. Alternatively, we might
23
+ decide that we'd like to add support for events to EVERY object. This can be achieved as follows:
24
+
25
+ require 'unobservable'
26
+
27
+ # Add event support to EVERY object
28
+ class Object
29
+ include Unobservable::Support
30
+ end
31
+
32
+
33
+ === Declaring Events
34
+
35
+ Once a class has been given support for events, you can declare events using the attr_event keyword. For instance:
36
+
37
+ require 'unobservable'
38
+
39
+ class Button
40
+ include Unobservable::Support
41
+
42
+ attr_event :clicked, :double_clicked
43
+ end
44
+
45
+
46
+ Like its cousins attr_reader and attr_accessor, attr_event does not actually instantiate any fields when it is invoked.
47
+ Instead, it just declares which events will exist on *instances* of the class:
48
+
49
+ x = Button.new
50
+ y = Button.new
51
+
52
+ # True. x.clicked returns the same Event instance
53
+ # each time it is invoked
54
+ x.clicked === x.clicked
55
+
56
+ # False. x and y each have their own instance of
57
+ # the Event.
58
+ x.clicked === y.clicked
59
+
60
+ === Accessing Events
61
+
62
+ The attr_event keyword will automatically create a getter property for each event. Therefore, you can access events
63
+ as if they were regular attributes:
64
+
65
+ > x = Button.new
66
+ => #<Button:0x007fa90c0f1e20>
67
+
68
+ > x.clicked
69
+ => #<Unobservable::Event:0x007fa90c0edeb0 @handlers=[]>
70
+
71
+ Events can also be retrieved via the Unobservable::Support#event method:
72
+
73
+ > x.event(:clicked)
74
+ => #<Unobservable::Event:0x007fa90c0edeb0 @handlers=[]>
75
+
76
+ You can retrieve a complete listing of the events supported by an object by invoking the Unobserable::Support#events method:
77
+
78
+ > x.events
79
+ => [:clicked, :double_clicked]
80
+
8
81
  == Copyright
9
82
 
10
83
  Copyright (c) 2012 Brian Lauber. See LICENSE.txt for
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
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.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -107,7 +107,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
107
107
  version: '0'
108
108
  segments:
109
109
  - 0
110
- hash: -507085936034972992
110
+ hash: 1272519931839892876
111
111
  required_rubygems_version: !ruby/object:Gem::Requirement
112
112
  none: false
113
113
  requirements: