selectable_attr 0.3.16 → 0.3.17

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.16
1
+ 0.3.17
@@ -30,6 +30,28 @@ module SelectableAttr
30
30
  entries.each(&block)
31
31
  end
32
32
 
33
+ def ==(other)
34
+ return false unless length == other.length
35
+ other_entries = other.entries
36
+ # ruby-1.8系ではEnumeratir#with_indexが使えないので1.8でも使用可能な書き方に変更しました。
37
+ # entries.map.with_index{|e, i| e == other_entries[i]}.all? # for 1.9
38
+ entries.each_with_index do |e, i|
39
+ return false unless e == other_entries[i]
40
+ end
41
+ true
42
+ end
43
+
44
+ def ===(other)
45
+ return false unless length == other.length
46
+ other_entries = other.entries
47
+ # ruby-1.8系ではEnumeratir#with_indexが使えないので1.8でも使用可能な書き方に変更しました。
48
+ # entries.map.with_index{|e, i| e === other_entries[i]}.all?
49
+ entries.each_with_index do |e, i|
50
+ return false unless e === other_entries[i]
51
+ end
52
+ true
53
+ end
54
+
33
55
  def define(id, key, name, options = nil, &block)
34
56
  entry = Entry.new(self, id, key, name, options, &block)
35
57
  entry.instance_variable_set(:@defined_in_code, true)
@@ -123,7 +145,7 @@ module SelectableAttr
123
145
 
124
146
  class Entry
125
147
  BASE_ATTRS = [:id, :key, :name]
126
- attr_reader :id, :key
148
+ attr_reader :id, :key, :options
127
149
  attr_reader :defined_in_code
128
150
  def initialize(enum, id, key, name, options = nil, &block)
129
151
  @enum = enum
@@ -149,6 +171,24 @@ module SelectableAttr
149
171
  @options === options
150
172
  end
151
173
 
174
+ def ==(other)
175
+ case other
176
+ when SelectableAttr::Enum::Entry
177
+ self.id == other.id
178
+ else
179
+ false
180
+ end
181
+ end
182
+
183
+ def ===(other)
184
+ case other
185
+ when SelectableAttr::Enum::Entry
186
+ (self.id == other.id) && (self.key == other.key)
187
+ else
188
+ false
189
+ end
190
+ end
191
+
152
192
  def null?
153
193
  false
154
194
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "selectable_attr"
8
- s.version = "0.3.16"
8
+ s.version = "0.3.17"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Takeshi Akima"]
@@ -158,4 +158,107 @@ describe SelectableAttr::Enum do
158
158
  end
159
159
  end
160
160
 
161
+ describe "SelectableAttr::Enum::Entry#==" do
162
+ context "same enum entry" do
163
+ subject{ Enum1.entry_by_id(1) } # entry 1, :book, '書籍'
164
+ it{ should == subject}
165
+ it{ should === subject}
166
+ it{ should eql(subject)}
167
+ it{ should equal(subject)}
168
+ end
169
+
170
+ context "an enum entry which has same attributes" do
171
+ subject do
172
+ enum = SelectableAttr::Enum.new{ entry(1, :book, '書籍') }
173
+ enum.entry_by_id(1)
174
+ end
175
+ before{ @other = Enum1.entry_by_id(1) }
176
+ it{ should == @other}
177
+ it{ should === @other}
178
+ it{ should_not eql(@other)}
179
+ it{ should_not equal(@other)}
180
+ end
181
+
182
+ context "an enum entry which has same id and key" do
183
+ subject do
184
+ enum = SelectableAttr::Enum.new{ entry(1, :book, '料理') }
185
+ enum.entry_by_id(1)
186
+ end
187
+ before{ @other = Enum1.entry_by_id(1) }
188
+ it{ should == @other}
189
+ it{ should === @other}
190
+ it{ should_not eql(@other)}
191
+ it{ should_not equal(@other)}
192
+ end
193
+
194
+ context "an enum entry which has same id" do
195
+ subject do
196
+ enum = SelectableAttr::Enum.new{ entry(1, :cook, '料理') }
197
+ enum.entry_by_id(1)
198
+ end
199
+ before{ @other = Enum1.entry_by_id(1) }
200
+ it{ should == @other}
201
+ it{ should_not === @other}
202
+ it{ should_not eql(@other)}
203
+ it{ should_not equal(@other)}
204
+ end
205
+ end
206
+
207
+ describe "SelectableAttr::Enum#==" do
208
+ context "same enum object" do
209
+ subject{ Enum1 }
210
+ it{ should == Enum1}
211
+ it{ should === Enum1}
212
+ it{ should eql(Enum1)}
213
+ it{ should equal(Enum1)}
214
+ end
215
+
216
+ context "an object which has same entries" do
217
+ subject do
218
+ SelectableAttr::Enum.new do
219
+ entry 1, :book, '書籍'
220
+ entry 2, :dvd, 'DVD'
221
+ entry 3, :cd, 'CD'
222
+ entry 4, :vhs, 'VHS'
223
+ end
224
+ end
225
+
226
+ it{ should == Enum1}
227
+ it{ should === Enum1}
228
+ it{ should_not eql(Enum1)}
229
+ it{ should_not equal(Enum1)}
230
+ end
231
+
232
+ context "an object which has entries with same id" do
233
+ subject do
234
+ SelectableAttr::Enum.new do
235
+ entry 1, :cook, '料理'
236
+ entry 2, :blueray, 'BD'
237
+ entry 3, :mv, 'Move Directory'
238
+ entry 4, :UHF, 'Ultra High Frequency'
239
+ end
240
+ end
241
+
242
+ it{ should == Enum1}
243
+ it{ should_not === Enum1}
244
+ it{ should_not eql(Enum1)}
245
+ it{ should_not equal(Enum1)}
246
+ end
247
+
248
+ context "an object which has same entries with different order" do
249
+ subject do
250
+ SelectableAttr::Enum.new do
251
+ entry 1, :book, '書籍'
252
+ entry 3, :cd, 'CD'
253
+ entry 4, :vhs, 'VHS'
254
+ entry 2, :dvd, 'DVD'
255
+ end
256
+ end
257
+
258
+ it{ should_not == Enum1}
259
+ it{ should_not === Enum1}
260
+ it{ should_not eql(Enum1)}
261
+ it{ should_not equal(Enum1)}
262
+ end
263
+ end
161
264
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: selectable_attr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.16
4
+ version: 0.3.17
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-05-14 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: i18n
16
- requirement: &2154121020 !ruby/object:Gem::Requirement
16
+ requirement: &2158590640 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2154121020
24
+ version_requirements: *2158590640
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &2154120540 !ruby/object:Gem::Requirement
27
+ requirement: &2158590160 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 2.6.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2154120540
35
+ version_requirements: *2158590160
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: yard
38
- requirement: &2154120060 !ruby/object:Gem::Requirement
38
+ requirement: &2158589680 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 0.7.2
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2154120060
46
+ version_requirements: *2158589680
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: bundler
49
- requirement: &2154119580 !ruby/object:Gem::Requirement
49
+ requirement: &2158589200 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.1.3
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2154119580
57
+ version_requirements: *2158589200
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: jeweler
60
- requirement: &2154119100 !ruby/object:Gem::Requirement
60
+ requirement: &2158588720 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 1.6.4
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *2154119100
68
+ version_requirements: *2158588720
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: simplecov
71
- requirement: &2154118620 !ruby/object:Gem::Requirement
71
+ requirement: &2158588240 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 0.5.3
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *2154118620
79
+ version_requirements: *2158588240
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: autotest
82
- requirement: &2154118140 !ruby/object:Gem::Requirement
82
+ requirement: &2158587760 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *2154118140
90
+ version_requirements: *2158587760
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: rdiscount
93
- requirement: &2154117660 !ruby/object:Gem::Requirement
93
+ requirement: &2158587280 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,7 +98,7 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *2154117660
101
+ version_requirements: *2158587280
102
102
  description: selectable_attr generates extra methods dynamically for attribute which
103
103
  has options
104
104
  email: akm2000@gmail.com
@@ -142,7 +142,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
142
142
  version: '0'
143
143
  segments:
144
144
  - 0
145
- hash: -3113713205006860534
145
+ hash: 4102483643633265272
146
146
  required_rubygems_version: !ruby/object:Gem::Requirement
147
147
  none: false
148
148
  requirements: