observe 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rbenv-version +1 -1
- data/README.md +2 -2
- data/lib/observe.rb +18 -12
- data/observe.gemspec +1 -1
- metadata +9 -9
data/.rbenv-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.9.
|
1
|
+
1.9.3-p0
|
data/README.md
CHANGED
@@ -9,8 +9,8 @@ __OVERVIEW__
|
|
9
9
|
|
10
10
|
__DESCRIPTION__
|
11
11
|
|
12
|
-
A simple interface for adding observers to any class.
|
13
|
-
|
12
|
+
A simple interface for adding observers to any class. The interface is similar
|
13
|
+
to and takes ideas from the 'Observable' module in the Ruby standard library.
|
14
14
|
|
15
15
|
__DIFFERENCES__
|
16
16
|
|
data/lib/observe.rb
CHANGED
@@ -2,15 +2,17 @@ module Observe
|
|
2
2
|
|
3
3
|
@observer = Struct.new(:group, :object)
|
4
4
|
|
5
|
-
class << self
|
5
|
+
class << self
|
6
6
|
attr_reader :observer
|
7
7
|
end
|
8
8
|
|
9
9
|
#
|
10
|
-
# Add
|
10
|
+
# Add an observer to a class.
|
11
11
|
#
|
12
12
|
# @example
|
13
|
-
# add_observer(:group)
|
13
|
+
# add_observer(:group) do
|
14
|
+
# puts "Hello!"
|
15
|
+
# end
|
14
16
|
#
|
15
17
|
# @param [#to_sym] group
|
16
18
|
# The name of a group that an observer belongs to.
|
@@ -21,25 +23,29 @@ module Observe
|
|
21
23
|
# @return [void]
|
22
24
|
#
|
23
25
|
def add_observer group, observer=nil, &block
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
26
|
+
obj = observer || block
|
27
|
+
|
28
|
+
if obj
|
29
|
+
group = group.to_sym
|
30
|
+
observers[group] << Observe.observer.new(group, obj)
|
28
31
|
else
|
29
|
-
raise ArgumentError, "
|
32
|
+
raise ArgumentError, "Wrong number of arguments (1 for 2)"
|
30
33
|
end
|
31
34
|
end
|
32
35
|
private :add_observer
|
33
36
|
|
34
37
|
#
|
35
|
-
# Notify
|
38
|
+
# Notify an observer.
|
36
39
|
#
|
37
40
|
# @example
|
38
|
-
# notify_observers :group
|
41
|
+
# notify_observers :group, "arg1", "arg2"
|
39
42
|
#
|
40
43
|
# @param [#to_sym] group
|
41
44
|
# The name of a group
|
42
|
-
#
|
45
|
+
#
|
46
|
+
# @param [Object] *args
|
47
|
+
# A variable number of arguments to passed onto an observer.
|
48
|
+
#
|
43
49
|
# @return [void]
|
44
50
|
#
|
45
51
|
def notify_observers group, *args
|
@@ -50,7 +56,7 @@ module Observe
|
|
50
56
|
private :notify_observers
|
51
57
|
|
52
58
|
#
|
53
|
-
# Destroy
|
59
|
+
# Destroy an observer.
|
54
60
|
#
|
55
61
|
# @example
|
56
62
|
# destroy_observers :group
|
data/observe.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: observe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-02-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: minitest
|
16
|
-
requirement: &
|
16
|
+
requirement: &70127593322820 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '2.5'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70127593322820
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &70127593322320 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: 0.9.2
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70127593322320
|
36
36
|
description: A simple interface for adding observers to any class.
|
37
37
|
email:
|
38
38
|
- rob@flowof.info
|
@@ -66,7 +66,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
66
66
|
version: '0'
|
67
67
|
segments:
|
68
68
|
- 0
|
69
|
-
hash:
|
69
|
+
hash: 3926186142539624693
|
70
70
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
71
|
none: false
|
72
72
|
requirements:
|
@@ -75,10 +75,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
75
|
version: '0'
|
76
76
|
segments:
|
77
77
|
- 0
|
78
|
-
hash:
|
78
|
+
hash: 3926186142539624693
|
79
79
|
requirements: []
|
80
80
|
rubyforge_project: observe
|
81
|
-
rubygems_version: 1.8.
|
81
|
+
rubygems_version: 1.8.15
|
82
82
|
signing_key:
|
83
83
|
specification_version: 3
|
84
84
|
summary: A simple interface for adding observers to any class.
|