ns-options 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -116,6 +116,14 @@ module NsOptions
116
116
  self
117
117
  end
118
118
 
119
+ def ==(other_ns)
120
+ if other_ns.kind_of? Namespace
121
+ self.to_hash == other_ns.to_hash
122
+ else
123
+ super
124
+ end
125
+ end
126
+
119
127
  # There are a number of cases we want to watch for:
120
128
  # 1. A reader of a 'known' option. This case is for an option that's been defined for an
121
129
  # ancestor of this namespace but not directly for this namespace. In this case we fetch
@@ -15,19 +15,24 @@ module NsOptions::Proxy
15
15
  receiver.class_eval { extend ProxyMethods }
16
16
  receiver.class_eval { include ProxyMethods } if receiver.kind_of?(Class)
17
17
 
18
- # default initializer method
19
-
20
18
  if receiver.kind_of?(Class)
21
19
  receiver.class_eval do
22
20
 
21
+ # default initializer method
23
22
  def initialize(configs={})
24
23
  self.apply(configs || {})
25
24
  end
26
25
 
26
+ # equality method override for class-instance proxies
27
+ def ==(other_proxy_instance)
28
+ __proxy_options__ == other_proxy_instance.__proxy_options__
29
+ end
30
+
27
31
  end
28
32
  else # Module
29
33
  receiver.class_eval do
30
34
 
35
+ # default initializer method
31
36
  def self.new(configs={})
32
37
  self.apply(configs || {})
33
38
  end
@@ -76,6 +81,11 @@ module NsOptions::Proxy
76
81
  __proxy_options__.valid?(*args, &block)
77
82
  end
78
83
 
84
+ def inspect(*args, &block)
85
+ # __proxy_options__.inspect(*args, &block)
86
+ "#<#{self.class}:#{'0x%x' % (self.object_id << 1)}:#{__proxy_options__.options.key} #{__proxy_options__.to_hash.inspect}>"
87
+ end
88
+
79
89
  # for everything else, send to the proxied NAMESPACE handler
80
90
  # at this point it really just enables setting dynamic options
81
91
 
@@ -1,3 +1,3 @@
1
1
  module NsOptions
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
@@ -400,5 +400,33 @@ class NsOptions::Namespace
400
400
  end
401
401
 
402
402
 
403
+ class EqualityTests < HandlingTests
404
+ desc "when compared for equality"
405
+ setup do
406
+ @namespace.apply(@named_values)
407
+ end
408
+
409
+ should "be equal to another namespace with the same named values" do
410
+ other_ns = NsOptions::Namespace.new('other_something')
411
+ other_ns.apply(@named_values)
412
+
413
+ assert_equal other_ns, @namespace
414
+ end
415
+
416
+ should "not be equal to another namespace with different values" do
417
+ other_ns = NsOptions::Namespace.new('other_something')
418
+ other_ns.apply({:other => 'data'})
419
+
420
+ assert_not_equal other_ns, @namespace
421
+ end
422
+
423
+ should "not be equal to other things" do
424
+ assert_not_equal 1, @namespace
425
+ assert_not_equal @named_value, @namespace
426
+ end
427
+
428
+ end
429
+
430
+
403
431
 
404
432
  end
@@ -125,4 +125,23 @@ module NsOptions::Proxy
125
125
 
126
126
  end
127
127
 
128
+ class EqualityTests < InstanceLevelTests
129
+ desc "two class instance proxies with the same option values"
130
+ setup do
131
+ @proxy1 = @cls.new
132
+ @proxy2 = @cls.new
133
+
134
+ @option_values = {:test => 1, :more => 2}
135
+
136
+ @proxy1.apply(@option_values)
137
+ @proxy2.apply(@option_values)
138
+ end
139
+
140
+ should "be equal to the each other" do
141
+ assert_equal @proxy2, @proxy1
142
+ end
143
+
144
+
145
+ end
146
+
128
147
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ns-options
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 0
10
- version: 0.4.0
9
+ - 1
10
+ version: 0.4.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Collin Redding
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-05-21 00:00:00 Z
18
+ date: 2012-06-05 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  type: :development