kvo 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/README.md +24 -0
  2. data/lib/kvo.rb +1 -1
  3. data/lib/kvo/version.rb +1 -1
  4. data/spec/kvo_spec.rb +37 -1
  5. metadata +49 -70
data/README.md ADDED
@@ -0,0 +1,24 @@
1
+ Description
2
+ ===========
3
+
4
+ Key-Value Observing in ruby
5
+
6
+ ### Synopsis
7
+
8
+ Fires a [Publisher](http://atomicobject.github.com/publisher/) event whenever the variable is set.
9
+
10
+ ### How do I use it?
11
+
12
+ class Foo
13
+ include Kvo
14
+ kvo_attr_accessor :bar, :baz
15
+ end
16
+
17
+ f = Foo.new
18
+ f.when :bar_changed do |oldVal, newVal|
19
+ puts "bar was changed from #{oldVal} to #{newVal}"
20
+ end
21
+
22
+ Authors
23
+ =======
24
+ * Shawn Anderson (shawn.anderson@atomicobject.com)
data/lib/kvo.rb CHANGED
@@ -4,7 +4,7 @@ module Kvo
4
4
  def kvo_attr_accessor(*kvo_symbols)
5
5
  kvo_symbols.each do |kvo|
6
6
  class_eval <<-METHODS
7
- can_fire :#{kvo}_changed
7
+ can_fire :#{kvo}_changed unless published_events == :any_event_is_ok
8
8
  def #{kvo}
9
9
  @kvo_#{kvo}
10
10
  end
data/lib/kvo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Kvo
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/spec/kvo_spec.rb CHANGED
@@ -31,10 +31,46 @@ describe 'kvo' do
31
31
  @target.bar = :yar
32
32
  @target.instance_variable_get("@bar").should be_nil
33
33
  end
34
- end
35
34
 
35
+ describe "inheritance" do
36
+ before do
37
+ @target = SubFoo.new
38
+
39
+ @fired = nil
40
+ @target.when :bar_changed do |old, new|
41
+ @fired = {:old => old, :new => new}
42
+ end
43
+ @target.when :qux_changed do |old, new|
44
+ @qux_fired = {:old => old, :new => new}
45
+ end
46
+ end
47
+
48
+ it 'inherits kvo from parent' do
49
+ @target.bar = :old
50
+ old_val = @target.bar
51
+ @target.bar = :yar
52
+ @fired.should_not be_nil
53
+ @fired[:old].should == old_val
54
+ @fired[:new].should == :yar
55
+ end
56
+
57
+ it 'can add more kvo fields to its parents fields' do
58
+ @target.qux = :old
59
+
60
+ old_val = @target.qux
61
+ @target.qux = :yar
62
+ @qux_fired.should_not be_nil
63
+ @qux_fired[:old].should == old_val
64
+ @qux_fired[:new].should == :yar
65
+ end
66
+ end
67
+ end
36
68
 
37
69
  class Foo
38
70
  include Kvo
39
71
  kvo_attr_accessor :bar, :baz
40
72
  end
73
+
74
+ class SubFoo < Foo
75
+ kvo_attr_accessor :qux
76
+ end
metadata CHANGED
@@ -1,111 +1,90 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: kvo
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 1
9
- version: 0.0.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Shawn Anderson
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2011-01-13 00:00:00 -05:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2012-03-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: publisher
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &2157009500 !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- segments:
29
- - 0
30
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
31
22
  type: :runtime
32
- version_requirements: *id001
33
- - !ruby/object:Gem::Dependency
34
- name: rspec
35
23
  prerelease: false
36
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *2157009500
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &2157008500 !ruby/object:Gem::Requirement
37
28
  none: false
38
- requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- segments:
42
- - 0
43
- version: "0"
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
44
33
  type: :development
45
- version_requirements: *id002
46
- - !ruby/object:Gem::Dependency
47
- name: mocha
48
34
  prerelease: false
49
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *2157008500
36
+ - !ruby/object:Gem::Dependency
37
+ name: mocha
38
+ requirement: &2157007540 !ruby/object:Gem::Requirement
50
39
  none: false
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- segments:
55
- - 0
56
- version: "0"
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
57
44
  type: :development
58
- version_requirements: *id003
45
+ prerelease: false
46
+ version_requirements: *2157007540
59
47
  description: KVO in ruby.
60
- email:
48
+ email:
61
49
  - shawn42@gmail.com
62
50
  executables: []
63
-
64
51
  extensions: []
65
-
66
52
  extra_rdoc_files: []
67
-
68
- files:
53
+ files:
69
54
  - .gitignore
70
55
  - Gemfile
56
+ - README.md
71
57
  - Rakefile
72
58
  - kvo.gemspec
73
59
  - lib/kvo.rb
74
60
  - lib/kvo/version.rb
75
61
  - spec/helper.rb
76
62
  - spec/kvo_spec.rb
77
- has_rdoc: true
78
- homepage: ""
63
+ homepage: ''
79
64
  licenses: []
80
-
81
65
  post_install_message:
82
66
  rdoc_options: []
83
-
84
- require_paths:
67
+ require_paths:
85
68
  - lib
86
- required_ruby_version: !ruby/object:Gem::Requirement
69
+ required_ruby_version: !ruby/object:Gem::Requirement
87
70
  none: false
88
- requirements:
89
- - - ">="
90
- - !ruby/object:Gem::Version
91
- segments:
92
- - 0
93
- version: "0"
94
- required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
76
  none: false
96
- requirements:
97
- - - ">="
98
- - !ruby/object:Gem::Version
99
- segments:
100
- - 0
101
- version: "0"
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
102
81
  requirements: []
103
-
104
82
  rubyforge_project: kvo
105
- rubygems_version: 1.3.7
83
+ rubygems_version: 1.8.10
106
84
  signing_key:
107
85
  specification_version: 3
108
86
  summary: KVO in ruby
109
- test_files:
87
+ test_files:
110
88
  - spec/helper.rb
111
89
  - spec/kvo_spec.rb
90
+ has_rdoc: