skn_utils 3.0.1 → 3.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/skn_utils/nested_result.rb +34 -80
- data/lib/skn_utils/notifier_base.rb +33 -85
- data/lib/skn_utils/version.rb +1 -1
- data/lib/skn_utils.rb +1 -0
- data/skn_utils.gemspec +2 -8
- data/spec/lib/skn_utils/nested_result_spec.rb +45 -0
- data/spec/lib/skn_utils/notifier_base_spec.rb +66 -0
- metadata +8 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82fb6a798fdac8263ee4faa65a6dd734cf148365
|
4
|
+
data.tar.gz: 2dc5b9cc3fa76df1d7c9dbef494b8e9d2dcee707
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5d5410f5f06e63a85e054a36e27f20cd5a8c344c59453f992c36e3e28d9632ac256e10f96df6b03421649da3b64e5493808c48e42b5abbc1bce18206347b2c9
|
7
|
+
data.tar.gz: 217fc83650fff470b1a5869734747875727bfbcc374a2762e3562b1d610a90bd020505dfbb2ef2340bf09ddcc98791f2688e3095af5f6a0569eb3c86782c5219
|
@@ -95,7 +95,7 @@ module SknUtils
|
|
95
95
|
|
96
96
|
def initialize(params={})
|
97
97
|
@container = {}
|
98
|
-
|
98
|
+
initialize_for_speed(params)
|
99
99
|
end
|
100
100
|
|
101
101
|
def [](attr)
|
@@ -131,33 +131,10 @@ module SknUtils
|
|
131
131
|
#
|
132
132
|
# Returns a string containing a detailed summary of the keys and values.
|
133
133
|
#
|
134
|
-
|
135
|
-
|
136
|
-
package = to_hash
|
137
|
-
str = "#<#{self.class}"
|
138
|
-
|
139
|
-
ids = (Thread.current[InspectKey] ||= [])
|
140
|
-
if ids.include?(object_id)
|
141
|
-
return str << ' ...>'
|
142
|
-
end
|
143
|
-
|
144
|
-
ids << object_id
|
145
|
-
begin
|
146
|
-
first = true
|
147
|
-
for k,v in package
|
148
|
-
str << "," unless first
|
149
|
-
first = false
|
150
|
-
str << " #{k}=#{v.inspect}"
|
151
|
-
end
|
152
|
-
return str << '>'
|
153
|
-
ensure
|
154
|
-
ids.pop
|
155
|
-
end
|
134
|
+
def to_s
|
135
|
+
attributes.to_s
|
156
136
|
end
|
157
137
|
|
158
|
-
alias_method :to_s, :inspect
|
159
|
-
|
160
|
-
|
161
138
|
##
|
162
139
|
# Ruby basic Class methods
|
163
140
|
#
|
@@ -186,14 +163,14 @@ module SknUtils
|
|
186
163
|
#
|
187
164
|
# Use our unwrapped/original input Hash when yaml'ing
|
188
165
|
def encode_with(coder)
|
189
|
-
coder['container'] =
|
166
|
+
coder['container'] = attributes
|
190
167
|
end
|
191
168
|
|
192
169
|
# Use our hash from above to fully re-initialize this instance
|
193
170
|
def init_with(coder)
|
194
171
|
case coder.tag
|
195
|
-
when '!ruby/object:SknUtils::NestedResult'
|
196
|
-
|
172
|
+
when '!ruby/object:SknUtils::NestedResult', "!ruby/object:#{self.class.name}"
|
173
|
+
initialize_for_speed( coder.map['container'] )
|
197
174
|
end
|
198
175
|
end
|
199
176
|
|
@@ -208,7 +185,7 @@ module SknUtils
|
|
208
185
|
|
209
186
|
# Using the String from above create and return an instance of this class
|
210
187
|
def marshal_load(hash)
|
211
|
-
|
188
|
+
initialize_for_speed(hash)
|
212
189
|
end
|
213
190
|
|
214
191
|
def respond_to_missing?(method, incl_private=false)
|
@@ -237,14 +214,14 @@ module SknUtils
|
|
237
214
|
# - protected to reasonably ensure key is a symbol
|
238
215
|
def hash_from(sym)
|
239
216
|
starting_sym = key_as_sym(sym)
|
240
|
-
bundle = starting_sym == container ? container : { starting_sym => container[starting_sym] }
|
217
|
+
bundle = ((starting_sym == container) ? container : { starting_sym => container[starting_sym] })
|
241
218
|
bundle.keys.each_with_object({}) do |attr,collector|
|
242
219
|
value = bundle[attr]
|
243
220
|
case value
|
244
|
-
when Array
|
245
|
-
value = value.map {|ele| array_to_hash(ele) }
|
246
221
|
when NestedResult
|
247
222
|
value = value.to_hash
|
223
|
+
when Array
|
224
|
+
value = value.map {|ele| array_to_hash(ele) }
|
248
225
|
end
|
249
226
|
collector[attr] = value # new copy
|
250
227
|
end
|
@@ -265,6 +242,22 @@ module SknUtils
|
|
265
242
|
name
|
266
243
|
end
|
267
244
|
|
245
|
+
# Don't create methods until first access
|
246
|
+
def initialize_for_speed(hash)
|
247
|
+
hash.each_pair do |k,v|
|
248
|
+
key = key_as_sym(k)
|
249
|
+
case v
|
250
|
+
when Array
|
251
|
+
value = v.map { |element| translate_value(element) }
|
252
|
+
container.store(key, value)
|
253
|
+
when Hash
|
254
|
+
container.store(key, NestedResult.new(v))
|
255
|
+
else
|
256
|
+
container.store(key, v)
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
268
261
|
def initialize_from_hash(hash)
|
269
262
|
hash.each_pair do |k,v|
|
270
263
|
key = key_as_sym(k)
|
@@ -284,10 +277,10 @@ module SknUtils
|
|
284
277
|
# Feature: unwrap array of array-of-hashes/object
|
285
278
|
def array_to_hash(array)
|
286
279
|
case array
|
287
|
-
when Array
|
288
|
-
array.map { |element| array_to_hash(element) }
|
289
280
|
when NestedResult
|
290
281
|
array.to_hash
|
282
|
+
when Array
|
283
|
+
array.map { |element| array_to_hash(element) }
|
291
284
|
else
|
292
285
|
array
|
293
286
|
end
|
@@ -296,10 +289,10 @@ module SknUtils
|
|
296
289
|
# Feature: wrap array of array-of-hashes/object
|
297
290
|
def translate_value(value)
|
298
291
|
case value
|
299
|
-
when Array
|
300
|
-
value.map { |element| translate_value(element) }
|
301
292
|
when Hash
|
302
293
|
NestedResult.new(value)
|
294
|
+
when Array
|
295
|
+
value.map { |element| translate_value(element) }
|
303
296
|
else
|
304
297
|
value
|
305
298
|
end
|
@@ -322,18 +315,16 @@ module SknUtils
|
|
322
315
|
method_nsym = method_sym.is_a?(Symbol) ? method.to_s[0..-2].to_sym : method
|
323
316
|
|
324
317
|
|
325
|
-
if method.to_s.end_with?("=")
|
318
|
+
if method.to_s.end_with?("=") # add new key/value pair, transform value if Hash or Array
|
326
319
|
initialize_from_hash({method_nsym => args.first})
|
327
320
|
|
328
321
|
elsif container.key?(method_sym)
|
329
|
-
|
330
|
-
enable_dot_notation(method_sym) # Add Reader/Writer one first need
|
331
|
-
container[method_sym]
|
322
|
+
container[enable_dot_notation(method_sym)] # Add Reader/Writer one first need
|
332
323
|
|
333
|
-
elsif method.to_s.end_with?('?')
|
324
|
+
elsif method.to_s.end_with?('?') # order of tests is significant,
|
334
325
|
attribute?(method_nsym)
|
335
326
|
|
336
|
-
else
|
327
|
+
else # TODO: replace following with nil to match OpenStruct behavior when key not found
|
337
328
|
e = NoMethodError.new "undefined method `#{method}' for #{self.class.name}", method, args
|
338
329
|
e.set_backtrace caller(1)
|
339
330
|
raise e
|
@@ -343,40 +334,3 @@ module SknUtils
|
|
343
334
|
|
344
335
|
end # end class
|
345
336
|
end # end module
|
346
|
-
|
347
|
-
|
348
|
-
# YAML.load(str) will trigger #init_with for each type it encounters when loading
|
349
|
-
# Psych.dump ==> "--- !ruby/object:SknUtils::NestedResult\ncontainer:\n :one: 1\n :two: two\n"
|
350
|
-
#
|
351
|
-
#
|
352
|
-
# [2] pry(main)> ay = Psych.dump a
|
353
|
-
# respond_to_missing?() checking for method: :encode_with existence.
|
354
|
-
# => "--- !ruby/object:SknUtils::NestedResult\ncontainer:\n :one: 1\n :two: two\n"
|
355
|
-
# [3] pry(main)> az = Psych.load ay
|
356
|
-
# respond_to_missing?() checking for method: :init_with existence.
|
357
|
-
# respond_to_missing?() checking for method: :yaml_initialize existence.
|
358
|
-
# => #<SknUtils::NestedResult:0x007fe410993238 @container={:one=>1, :two=>"two"}>
|
359
|
-
|
360
|
-
|
361
|
-
# YAML RTM? querys
|
362
|
-
# [:encode_with, :init_with].include?(method)
|
363
|
-
|
364
|
-
|
365
|
-
# can be accessed just like a hash
|
366
|
-
# respond_to_missing?() checking for method: :encode_with existence.
|
367
|
-
# respond_to_missing?() checking for method: :encode_with existence.
|
368
|
-
# respond_to_missing?() checking for method: :encode_with existence.
|
369
|
-
# respond_to_missing?() checking for method: :encode_with existence.
|
370
|
-
# respond_to_missing?() checking for method: :encode_with existence.
|
371
|
-
# respond_to_missing?() checking for method: :encode_with existence.
|
372
|
-
# respond_to_missing?() checking for method: :encode_with existence.
|
373
|
-
# respond_to_missing?() checking for method: :encode_with existence.
|
374
|
-
# init_with() hooking into Yaml/Psych.load for codes: {:seven=>7, :eight=>"eight"}.
|
375
|
-
# init_with() hooking into Yaml/Psych.load for codes: {:four=>4, :five=>5, :six=>#<SknUtils::NestedResult:0x007fba101740e0 @container={:seven=>7, :eight=>"eight"}>, :seven=>false}.
|
376
|
-
# init_with() hooking into Yaml/Psych.load for codes: {:any_key=>#<Tuple:0x007fba101643e8 @first="foo", @second="bar">}.
|
377
|
-
# init_with() hooking into Yaml/Psych.load for codes: {:seven=>7, :eight=>"eight"}.
|
378
|
-
# init_with() hooking into Yaml/Psych.load for codes: {:four=>4, :five=>5, :six=>#<SknUtils::NestedResult:0x007fba1014f880 @container={:seven=>7, :eight=>"eight"}>}.
|
379
|
-
# init_with() hooking into Yaml/Psych.load for codes: {:nine=>9, :ten=>"ten"}.
|
380
|
-
# init_with() hooking into Yaml/Psych.load for codes: {:four=>4, :five=>5, :six=>#<SknUtils::NestedResult:0x007fba1014cd60 @container={:nine=>9, :ten=>"ten"}>}.
|
381
|
-
# init_with() hooking into Yaml/Psych.load for codes: {:one=>"one", :two=>"two", :three=>#<SknUtils::NestedResult:0x007fba10175058 @container={:four=>4, :five=>5, :six=>#<SknUtils::NestedResult:0x007fba101740e0 @container={:seven=>7, :eight=>"eight"}>, :seven=>false}>, :four=>#<SknUtils::NestedResult:0x007fba101664b8 @container={:any_key=>#<Tuple:0x007fba101643e8 @first="foo", @second="bar">}>, :five=>[4, 5, 6], :six=>[#<SknUtils::NestedResult:0x007fba10154628 @container={:four=>4, :five=>5, :six=>#<SknUtils::NestedResult:0x007fba1014f880 @container={:seven=>7, :eight=>"eight"}>}>, #<SknUtils::NestedResult:0x007fba1014d738 @container={:four=>4, :five=>5, :six=>#<SknUtils::NestedResult:0x007fba1014cd60 @container={:nine=>9, :ten=>"ten"}>}>, #<Tuple:0x007fba10146d48 @first="another", @second="tuple">], :seven=>#<Tuple:0x007fba10145a60 @first="hello", @second="world">}.
|
382
|
-
|
@@ -4,91 +4,39 @@
|
|
4
4
|
#
|
5
5
|
# Ref: https://ozone.wordpress.com/category/programming/metaprogramming/
|
6
6
|
|
7
|
-
|
8
|
-
class NotifierBase
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
old_value = instance_variable_get("@#{prop}")
|
29
|
-
return if (value == old_value)
|
30
|
-
@listeners.each { |listener|
|
31
|
-
listener.attribute_changed(prop, old_value, value)
|
7
|
+
module SknUtils
|
8
|
+
class NotifierBase
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@listeners = []
|
12
|
+
end
|
13
|
+
|
14
|
+
def register_listener(listener)
|
15
|
+
@listeners.push(listener) unless @listeners.include?(listener)
|
16
|
+
end
|
17
|
+
|
18
|
+
def unregister_listener(listener)
|
19
|
+
@listeners.delete(listener)
|
20
|
+
end
|
21
|
+
|
22
|
+
# create writer-with-notify and reader
|
23
|
+
def self.attribute(*attrs)
|
24
|
+
attrs.each do |attr|
|
25
|
+
instance_variable_set("@#{attr}", nil)
|
26
|
+
define_method(attr) {
|
27
|
+
instance_variable_get("@#{attr}")
|
32
28
|
}
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
#
|
42
|
-
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
class LoggingPropertyChangeListener
|
47
|
-
def attribute_changed(attribute, old_value, new_value)
|
48
|
-
print attribute, " changed from ",
|
49
|
-
old_value, " to ",
|
50
|
-
new_value, "\n"
|
51
|
-
end
|
29
|
+
define_method("#{attr}=") do |value|
|
30
|
+
old_value = instance_variable_get("@#{attr}")
|
31
|
+
return if (value == old_value)
|
32
|
+
@listeners.each { |listener|
|
33
|
+
listener.attribute_changed(attr, old_value, value)
|
34
|
+
}
|
35
|
+
instance_variable_set("@#{attr}", value)
|
36
|
+
end
|
37
|
+
end # loop on attrs
|
38
|
+
end # end of attribute method
|
39
|
+
|
40
|
+
end # end of NotifierBase class
|
52
41
|
end
|
53
42
|
|
54
|
-
class SimpleBean < NotifierBase
|
55
|
-
attribute :name, :firstname
|
56
|
-
|
57
|
-
def impotent_name=(new_name)
|
58
|
-
@name = new_name
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
|
63
|
-
test = TestBean.new
|
64
|
-
listener = LoggingPropertyChangeListener.new
|
65
|
-
test.register_listener(listener)
|
66
|
-
test.name = 'James Scott'
|
67
|
-
test.firstname = "Scott"
|
68
|
-
test.firstname = "James"
|
69
|
-
test.unregister_listener(listener)
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
test = SimpleBean.new
|
74
|
-
listener = LoggingPropertyChangeListener.new
|
75
|
-
test.register_listener(listener)
|
76
|
-
test.name = 'James Scott'
|
77
|
-
test.firstname = 'Scott'
|
78
|
-
test.firstname = 'James'
|
79
|
-
test.unregister_listener(listener)
|
80
|
-
|
81
|
-
|
82
|
-
# output it generates:
|
83
|
-
|
84
|
-
# ==> name changed from nil to James Scott
|
85
|
-
# ==> firstname changed from nil to Scott
|
86
|
-
# ==> firstname changed from Scott to James
|
87
|
-
|
88
|
-
|
89
|
-
#
|
90
|
-
# END
|
91
|
-
#
|
92
|
-
|
93
|
-
|
94
|
-
|
data/lib/skn_utils/version.rb
CHANGED
data/lib/skn_utils.rb
CHANGED
data/skn_utils.gemspec
CHANGED
@@ -22,7 +22,7 @@ EOF
|
|
22
22
|
This version does not include ResultBean, PageControls, or ValueBean classes.
|
23
23
|
SknUtils::NestedResult class replaces those original classes and their function.
|
24
24
|
|
25
|
-
Please update your existing code to make the above change or use the prior version 2.0.
|
25
|
+
Please update your existing code to make the above change or use the prior version 2.0.6
|
26
26
|
EOF
|
27
27
|
spec.homepage = "https://github.com/skoona/skn_utils"
|
28
28
|
spec.license = "MIT"
|
@@ -30,17 +30,11 @@ EOF
|
|
30
30
|
spec.files = `git ls-files -z`.split("\x0")
|
31
31
|
spec.executables = []
|
32
32
|
spec.test_files = spec.files.grep(%r{^(spec)/})
|
33
|
-
spec.require_paths = [
|
33
|
+
spec.require_paths = ['lib']
|
34
34
|
|
35
35
|
spec.add_development_dependency "bundler", ">= 0"
|
36
36
|
spec.add_development_dependency "rake", ">= 0"
|
37
37
|
spec.add_development_dependency "rspec", '~> 3.0'
|
38
38
|
spec.add_development_dependency "pry", ">= 0"
|
39
39
|
spec.add_development_dependency "simplecov", ">= 0"
|
40
|
-
|
41
|
-
## Make sure you can build the gem on older versions of RubyGems too:
|
42
|
-
spec.rubygems_version = "1.6.2"
|
43
|
-
spec.required_rubygems_version = Gem::Requirement.new(">= 0") if spec.respond_to? :required_rubygems_version=
|
44
|
-
spec.required_ruby_version = '~> 2.0'
|
45
|
-
spec.specification_version = 3 if spec.respond_to? :specification_version
|
46
40
|
end
|
@@ -22,6 +22,18 @@ class MyObject
|
|
22
22
|
|
23
23
|
end
|
24
24
|
|
25
|
+
class IFeature < SknUtils::NestedResult
|
26
|
+
def initialize(parms={})
|
27
|
+
super(parms)
|
28
|
+
# @some_value = 'Three'
|
29
|
+
end
|
30
|
+
|
31
|
+
def say(val='hello')
|
32
|
+
"Three #{val}s"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
|
25
37
|
RSpec.shared_examples 'plain old ruby object' do
|
26
38
|
|
27
39
|
context "Core Operations " do
|
@@ -165,6 +177,19 @@ end
|
|
165
177
|
|
166
178
|
|
167
179
|
RSpec.describe SknUtils::NestedResult, 'NestedResult class - Basic usage.' do
|
180
|
+
let(:ifeature) do
|
181
|
+
IFeature.new(one: 'one', 4201 => 'Account Code',
|
182
|
+
two: 'two',
|
183
|
+
three: { four: 4, five: 5, six: { seven: 7, eight: 'eight' }, seven: false },
|
184
|
+
four: { any_key: MyObject.new(value: ['MyObject Testing', 'Looking for Modifications']) },
|
185
|
+
five: [4, 5, 6],
|
186
|
+
six: [{ four: 4, five: 5, six: { seven: 7, eight: 'eight' } },
|
187
|
+
{ four: 4, five: 5, six: { nine: 9, ten: 'ten' } },
|
188
|
+
MyObject.new(value: ['MyObject Testing', 'Looking for Modifications'])],
|
189
|
+
seven: MyObject.new(value: ['MyObject Testing', 'Looking for Modifications']),
|
190
|
+
eight: [[{one: 'one', two: 'two'}],[{three: 'three', four: 'four'}]])
|
191
|
+
end
|
192
|
+
|
168
193
|
let(:object) do
|
169
194
|
SknUtils::NestedResult.new(one: 'one', 4201 => 'Account Code',
|
170
195
|
two: 'two',
|
@@ -227,6 +252,12 @@ RSpec.describe SknUtils::NestedResult, 'NestedResult class - Basic usage.' do
|
|
227
252
|
it_behaves_like 'plain old ruby object' do
|
228
253
|
let(:bean) { object }
|
229
254
|
end
|
255
|
+
it_behaves_like 'plain old ruby object' do
|
256
|
+
let(:bean) { ifeature }
|
257
|
+
end
|
258
|
+
it "behaves as expected when inherited" do
|
259
|
+
expect(ifeature.say('Person')).to eq('Three Persons')
|
260
|
+
end
|
230
261
|
end
|
231
262
|
|
232
263
|
context 'Marshalling to JSON' do
|
@@ -235,10 +266,24 @@ RSpec.describe SknUtils::NestedResult, 'NestedResult class - Basic usage.' do
|
|
235
266
|
end
|
236
267
|
end
|
237
268
|
|
269
|
+
context 'IFeature Basic Operations after Yaml marshaling' do
|
270
|
+
let(:dumped_object) { Psych.dump(ifeature) }
|
271
|
+
|
272
|
+
it "#encode_with exports the original hash when YAML'ed" do
|
273
|
+
expect(dumped_object).to include('ruby/object:IFeature')
|
274
|
+
expect(dumped_object[42..-1]).to_not include('ruby/object:IFeature')
|
275
|
+
end
|
276
|
+
|
277
|
+
it_behaves_like 'plain old ruby object' do
|
278
|
+
let(:bean) { Psych.load(dumped_object) }
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
238
282
|
context 'Basic Operations after Yaml marshaling' do
|
239
283
|
let(:dumped_object) { Psych.dump(object) }
|
240
284
|
|
241
285
|
it "#encode_with exports the original hash when YAML'ed" do
|
286
|
+
expect(dumped_object).to include('ruby/object:SknUtils::NestedResult')
|
242
287
|
expect(dumped_object[42..-1]).to_not include('ruby/object:SknUtils::NestedResult')
|
243
288
|
end
|
244
289
|
|
@@ -0,0 +1,66 @@
|
|
1
|
+
##
|
2
|
+
# spec/lib/skn_utils/null_object_spec.rb
|
3
|
+
#
|
4
|
+
|
5
|
+
# Create a bean from that base
|
6
|
+
class TestBean < SknUtils::NotifierBase
|
7
|
+
attribute :name, :firstname
|
8
|
+
end
|
9
|
+
|
10
|
+
class LoggingPropertyChangeListener
|
11
|
+
def attribute_changed(attribute, old_value, new_value)
|
12
|
+
print attribute, " changed from ",
|
13
|
+
old_value, " to ",
|
14
|
+
new_value, "\n"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class SimpleBean < SknUtils::NotifierBase
|
19
|
+
attribute :name, :firstname
|
20
|
+
|
21
|
+
def impotent_name=(new_name)
|
22
|
+
@name = new_name
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
RSpec.describe SknUtils::NotifierBase, "Notify feature example for Ruby " do
|
28
|
+
let(:test_obj) { TestBean.new }
|
29
|
+
let(:simple_obj) { SimpleBean.new }
|
30
|
+
let(:listener) { LoggingPropertyChangeListener.new }
|
31
|
+
|
32
|
+
context "Basic Operations" do
|
33
|
+
it "Initializes without params" do
|
34
|
+
expect(subject).to be
|
35
|
+
end
|
36
|
+
it "Can be Inherited." do
|
37
|
+
expect(test_obj).to be
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "Notify Operations" do
|
42
|
+
it "#register_listener registers listeners." do
|
43
|
+
expect(test_obj.register_listener(listener)).to include(listener)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "#unregister_listener removes listener." do
|
47
|
+
test_obj.register_listener(listener)
|
48
|
+
expect(test_obj.unregister_listener(listener)).to eq(listener)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "notifies listeners of changes when attribute writer is used." do
|
52
|
+
test_obj.register_listener(listener)
|
53
|
+
expect(listener).to receive(:attribute_changed).with(:name, nil, 'James Scott')
|
54
|
+
test_obj.name = 'James Scott'
|
55
|
+
end
|
56
|
+
|
57
|
+
it "does not notify listeners when attribute writer is not used." do
|
58
|
+
simple_obj.register_listener(listener)
|
59
|
+
expect(listener).not_to receive(:attribute_changed)
|
60
|
+
simple_obj.impotent_name = 'James Scott'
|
61
|
+
expect(simple_obj.name).to eq('James Scott')
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: skn_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Scott Jr
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -112,6 +112,7 @@ files:
|
|
112
112
|
- spec/lib/skn_utils/exploring/commander_spec.rb
|
113
113
|
- spec/lib/skn_utils/exploring/configuration_spec.rb
|
114
114
|
- spec/lib/skn_utils/nested_result_spec.rb
|
115
|
+
- spec/lib/skn_utils/notifier_base_spec.rb
|
115
116
|
- spec/lib/skn_utils/null_object_spec.rb
|
116
117
|
- spec/spec_helper.rb
|
117
118
|
homepage: https://github.com/skoona/skn_utils
|
@@ -121,15 +122,15 @@ metadata: {}
|
|
121
122
|
post_install_message: "This version does not include ResultBean, PageControls, or
|
122
123
|
ValueBean classes. \nSknUtils::NestedResult class replaces those original classes
|
123
124
|
and their function. \n\nPlease update your existing code to make the above change
|
124
|
-
or use the prior version 2.0.
|
125
|
+
or use the prior version 2.0.6\n"
|
125
126
|
rdoc_options: []
|
126
127
|
require_paths:
|
127
128
|
- lib
|
128
129
|
required_ruby_version: !ruby/object:Gem::Requirement
|
129
130
|
requirements:
|
130
|
-
- - "
|
131
|
+
- - ">="
|
131
132
|
- !ruby/object:Gem::Version
|
132
|
-
version: '
|
133
|
+
version: '0'
|
133
134
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
135
|
requirements:
|
135
136
|
- - ">="
|
@@ -139,7 +140,7 @@ requirements: []
|
|
139
140
|
rubyforge_project:
|
140
141
|
rubygems_version: 2.6.11
|
141
142
|
signing_key:
|
142
|
-
specification_version:
|
143
|
+
specification_version: 4
|
143
144
|
summary: SknUtils contains a small collection of Ruby utilities, the first being a
|
144
145
|
NestedResult a key/value container.
|
145
146
|
test_files:
|
@@ -147,5 +148,6 @@ test_files:
|
|
147
148
|
- spec/lib/skn_utils/exploring/commander_spec.rb
|
148
149
|
- spec/lib/skn_utils/exploring/configuration_spec.rb
|
149
150
|
- spec/lib/skn_utils/nested_result_spec.rb
|
151
|
+
- spec/lib/skn_utils/notifier_base_spec.rb
|
150
152
|
- spec/lib/skn_utils/null_object_spec.rb
|
151
153
|
- spec/spec_helper.rb
|