observable_object 0.1.1 → 0.1.2

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: 849657362f62135a7a2070a2a75b2e06290a7a40
4
- data.tar.gz: 94c856a7f9dae40da13a877fa13f2acb53b9a94d
3
+ metadata.gz: 3bfbc272f929c3fd1df97e7d0743c1dbe13a5aa0
4
+ data.tar.gz: e0b5374415268dcd81c2ee0996d801fb56012870
5
5
  SHA512:
6
- metadata.gz: f343ec8238c760e0c6fbc10240ae581247b0c7dbea5552ed8383135e01e16b2d7b4ea30b5f3a4f4d46c00989d5d999b3693329b730c029845aa89460d43806d3
7
- data.tar.gz: 58b714b0e9ef908c0b632a1f9b1b21f13573b9756eaf2b18bc840c67151aec08022283aec620abfd769b3da93ec657418c5aa7fedc063d729f11689f068a739a
6
+ metadata.gz: 9c1185f702058cf2384149855567c146ee2ce51a11191a435eb6a4146ae35f18858f53d60b6a1fc2074ad3ce5c34c35d2d182a93b1a4509f7ac148e36a325701
7
+ data.tar.gz: b456bb17b23489efc2290c0df8adec4e309f163c9c68fe055888f2daa347723d55f7f8aa5709f8c98fab1ad0467008c8d228577cdcb12e2e6b1cb817cde6fcd9
@@ -102,6 +102,11 @@ module ObservableObject
102
102
  def !
103
103
  !@obj
104
104
  end
105
+
106
+ # special handling to let Array(), Hash() etc. work
107
+ %i[to_ary to_hash to_str].each do |name|
108
+ define_method(name) { @obj.__send__(name) }
109
+ end
105
110
 
106
111
  def respond_to?(mname)
107
112
  @obj.respond_to?(mname)
@@ -1,3 +1,3 @@
1
1
  module ObservableObject
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -107,6 +107,42 @@ describe ObservableObject do
107
107
  expect(event_obj_list.all? { |x| x == wrapped }).to be true
108
108
  end
109
109
 
110
+ it 'works with Array()' do
111
+ obj = [1,2,3]
112
+ wrapped = ObservableObject.deep_wrap(obj,&event)
113
+ expect( Array(wrapped) ).to eq obj
114
+ end
115
+ it 'works with Hash()' do
116
+ obj = {'a'=>1}
117
+ wrapped = ObservableObject.deep_wrap(obj,&event)
118
+ expect( Hash(wrapped) ).to eq obj
119
+ end
120
+ it 'works with String()' do
121
+ obj = 'string'
122
+ wrapped = ObservableObject.deep_wrap(obj,&event)
123
+ expect( String(wrapped) ).to eq obj
124
+ end
125
+ it 'works with Complex()' do
126
+ obj = 1+2i
127
+ wrapped = ObservableObject.deep_wrap(obj,&event)
128
+ expect( Complex(wrapped) ).to eq obj
129
+ end
130
+ it 'works with Float()' do
131
+ obj = 22.73
132
+ wrapped = ObservableObject.deep_wrap(obj,&event)
133
+ expect( Float(wrapped) ).to eq obj
134
+ end
135
+ it 'works with Integer()' do
136
+ obj = 18
137
+ wrapped = ObservableObject.deep_wrap(obj,&event)
138
+ expect( Integer(wrapped) ).to eq obj
139
+ end
140
+ it 'works with Rational()' do
141
+ obj = 2/3.to_r
142
+ wrapped = ObservableObject.deep_wrap(obj,&event)
143
+ expect( Rational(wrapped) ).to eq obj
144
+ end
145
+
110
146
  # TODO: fix the case below, if there is an efficient solution. Not a bug, annoyance.
111
147
  # it 'does not call event handler after an already deleted sub-object is modified' do
112
148
  # obj = [[1,2],[3,4]]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: observable_object
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - moonfly (Andrey Pronin)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-05 00:00:00.000000000 Z
11
+ date: 2014-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler