simple_set 1.0.1 → 1.0.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: 9ac5283b146313f3608674a583ccb44b71a94278
4
- data.tar.gz: f823e20306eebae24a9fe94183afbf535b845b0f
3
+ metadata.gz: a27bd4248194e50184ad285ba8262e9a387736b9
4
+ data.tar.gz: 2ca6d88cf8768a74047770d076ea06b0a5290808
5
5
  SHA512:
6
- metadata.gz: 2c7b61ab0020e2c6f688e3ac16370a3bdc71c192c7cf1116103cb2353a74ae1c43c9f1ffe396d8fc293d78c81576c157e2cc7a354844d75b1d71b92a83d41b63
7
- data.tar.gz: 32a46d29080020a5e02d3724efb6a1d581d619802d4ca210cb6748655295695385bf9364849ca6babb2e242009407a4783f6cf8b390c742be733db899f0109c4
6
+ metadata.gz: be3ac07d3ca2b6814adb9a0654ec8320b9be02229beb668885c4185d5e8cdb831f2d3bd7fca53dede9228ca4949b5871487c36935b186e7617a2c3faa0e10ff7
7
+ data.tar.gz: 7871a706ad62f15b1d05839b76c9274070a60bd1b2e5700edb580b05cc57656ad0415a669b400e2e8e870035d518c11218c9bde59c9ddfdbd6bb6199c943d6dc
@@ -109,7 +109,7 @@ module SimpleSet
109
109
  if options[:slim] != true then
110
110
  prefix = options[:prefix] && "#{options[:prefix] == true ? set_cd.to_s.singularize : options[:prefix]}_"
111
111
  values.each do |k,code|
112
- sym = ::SimpleEnum::EnumHash.symbolize(k)
112
+ sym = k.to_sym
113
113
 
114
114
  define_method("#{prefix}#{sym}?") do
115
115
  current = send(options[:column]) || 0
@@ -1,26 +1,23 @@
1
- require 'simple_enum/enum_hash'
2
-
3
1
  module SimpleSet
4
2
  class SetHash < ::ActiveSupport::OrderedHash
5
- def initialize(args = [], strings = false)
3
+ def initialize(args = [])
6
4
  super()
7
5
 
8
- if args.is_a?(Hash) then
6
+ args = if args.is_a?(Hash) then
9
7
  args.each { |k,v| set_value_for_reverse_lookup(k, v) }
8
+ elsif args.is_a?(Array) && !args.first.is_a?(Array) then
9
+ args.each_with_index.map { |x,y| [x, 2**y] }
10
10
  else
11
- ary = args.send(args.respond_to?(:enum_with_index) ? :enum_with_index : :each_with_index).map { |x,y| [ x, 2**y ] } unless args.first.respond_to?(:map)
12
- ary = args.map { |e| [e, 2**e.id] } if args.first.respond_to?(:map) && !args.first.is_a?(Array)
13
- ary ||= args
14
- ary.each { |e| set_value_for_reverse_lookup(e[0], strings ? e[0].to_s : e[1]) }
11
+ raise Exception.new()
15
12
  end
13
+ args.each { |e| set_value_for_reverse_lookup(e[0], e[1]) }
16
14
 
17
15
  freeze
18
16
  end
19
17
 
20
18
  private
21
19
  def set_value_for_reverse_lookup(key, value)
22
- sym = ::SimpleEnum::EnumHash.symbolize(key)
23
- self[key] = value
20
+ self[key.to_sym] = value
24
21
  end
25
22
  end
26
23
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleSet
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -17,11 +17,9 @@ Gem::Specification.new do |spec|
17
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
18
  spec.require_paths = ["lib"]
19
19
 
20
- spec.add_dependency "simple_enum", "~> 1.6.8"
21
-
22
- spec.add_development_dependency "bundler", "~> 1.3"
23
- spec.add_development_dependency "rake"
24
- spec.add_development_dependency "rspec"
25
- spec.add_development_dependency "activerecord", ">= 3.0.0"
26
- spec.add_development_dependency "sqlite3"
20
+ spec.add_development_dependency 'bundler', '~> 1.3'
21
+ spec.add_development_dependency 'rake', '~> 10.3'
22
+ spec.add_development_dependency 'rspec', '~> 3.0.0'
23
+ spec.add_development_dependency 'activerecord', '>= 3.0.0'
24
+ spec.add_development_dependency 'sqlite3', '~> 1.3'
27
25
  end
@@ -17,12 +17,12 @@ describe SimpleSet do
17
17
  as_set :values, [:a, :b, :c, :d, :e, :f]
18
18
  end
19
19
 
20
- InitWithArrayOfSymbol.a.should == 1
21
- InitWithArrayOfSymbol.b.should == 2
22
- InitWithArrayOfSymbol.c.should == 4
23
- InitWithArrayOfSymbol.d.should == 8
24
- InitWithArrayOfSymbol.e.should == 16
25
- InitWithArrayOfSymbol.f.should == 32
20
+ expect(InitWithArrayOfSymbol.a).to eq(1)
21
+ expect(InitWithArrayOfSymbol.b).to eq(2)
22
+ expect(InitWithArrayOfSymbol.c).to eq(4)
23
+ expect(InitWithArrayOfSymbol.d).to eq(8)
24
+ expect(InitWithArrayOfSymbol.e).to eq(16)
25
+ expect(InitWithArrayOfSymbol.f).to eq(32)
26
26
  end
27
27
 
28
28
  it 'should accept a hash' do
@@ -30,23 +30,23 @@ describe SimpleSet do
30
30
  as_set :values, { a: 1, b: 2, c: 4, d: 8, all: 15 }
31
31
  end
32
32
 
33
- InitWithHash.a.should == 1
34
- InitWithHash.b.should == 2
35
- InitWithHash.c.should == 4
36
- InitWithHash.d.should == 8
37
- InitWithHash.all.should == 15
33
+ expect(InitWithHash.a).to eq(1)
34
+ expect(InitWithHash.b).to eq(2)
35
+ expect(InitWithHash.c).to eq(4)
36
+ expect(InitWithHash.d).to eq(8)
37
+ expect(InitWithHash.all).to eq(15)
38
38
 
39
39
  sample = InitWithHash.new
40
40
  sample.all = true
41
- sample.a?.should be_true
42
- sample.b?.should be_true
43
- sample.c?.should be_true
44
- sample.d?.should be_true
45
- sample.all?.should be_true
41
+ expect(sample.a?).to be_truthy
42
+ expect(sample.b?).to be_truthy
43
+ expect(sample.c?).to be_truthy
44
+ expect(sample.d?).to be_truthy
45
+ expect(sample.all?).to be_truthy
46
46
  sample.b = false
47
- sample.all?.should be_false
47
+ expect(sample.all?).to be_falsey
48
48
  sample.b = true
49
- sample.all?.should be_true
49
+ expect(sample.all?).to be_truthy
50
50
  end
51
51
 
52
52
  it 'should distinguish nil from empty set' do
@@ -56,25 +56,25 @@ describe SimpleSet do
56
56
 
57
57
  sample = NilOrEmpty.new
58
58
 
59
- sample.a?.should be_false
60
- sample.b?.should be_false
61
- sample.values_cd.should == nil
62
- sample.values.should == nil
59
+ expect(sample.a?).to be_falsey
60
+ expect(sample.b?).to be_falsey
61
+ expect(sample.values_cd).to eq(nil)
62
+ expect(sample.values).to eq(nil)
63
63
 
64
64
  sample.values = [:a]
65
- sample.values.should == [:a]
65
+ expect(sample.values).to eq([:a])
66
66
  sample.values = nil
67
- sample.values.should == nil
67
+ expect(sample.values).to eq(nil)
68
68
 
69
69
  sample.a = true
70
- sample.values.should == [:a]
70
+ expect(sample.values).to eq([:a])
71
71
  sample.a = false
72
- sample.values.should == []
72
+ expect(sample.values).to eq([])
73
73
 
74
74
  sample.values = nil
75
- sample.values.should == nil
75
+ expect(sample.values).to eq(nil)
76
76
  sample.a = false
77
- sample.values.should == []
77
+ expect(sample.values).to eq([])
78
78
  end
79
79
 
80
80
  it 'should support fields with a default value' do
@@ -83,11 +83,11 @@ describe SimpleSet do
83
83
  end
84
84
 
85
85
  sample = FieldWithDefaultValue.new
86
- sample.values_with_default_cd.should == 2
87
- sample.values_with_default.should == [:y]
86
+ expect(sample.values_with_default_cd).to eq(2)
87
+ expect(sample.values_with_default).to eq([:y])
88
88
 
89
89
  sample.values_with_default = nil
90
- sample.values_with_default.should == nil
90
+ expect(sample.values_with_default).to eq(nil)
91
91
  end
92
92
 
93
93
  it 'should work outside activerecord' do
@@ -99,7 +99,7 @@ describe SimpleSet do
99
99
 
100
100
  sample = FruitsEater.new
101
101
  sample.fruits_i_like = [:apples, :pinaple]
102
- sample.fruits_i_like_cd.should == 5
102
+ expect(sample.fruits_i_like_cd).to eq(5)
103
103
  end
104
104
 
105
105
  it 'should return acceptable values' do
@@ -107,7 +107,7 @@ describe SimpleSet do
107
107
  as_set :spoken_languages, [:english, :french, :german, :japanese]
108
108
  end
109
109
 
110
- AcceptableValues.spoken_languages.should == [:english, :french, :german, :japanese]
110
+ expect(AcceptableValues.spoken_languages).to eq([:english, :french, :german, :japanese])
111
111
  end
112
112
 
113
113
  it 'should support Rails assignment' do
@@ -117,7 +117,7 @@ describe SimpleSet do
117
117
 
118
118
  sample = User.new
119
119
  sample.values = ["foo_manager", "baz_manager", ""]
120
- sample.values.should == [:foo_manager, :baz_manager]
120
+ expect(sample.values).to eq([:foo_manager, :baz_manager])
121
121
  end
122
122
 
123
123
  # ___ _ _
@@ -143,11 +143,11 @@ describe SimpleSet do
143
143
 
144
144
  sample = TestOptionColumn1.new
145
145
  sample.languages = [:french, :german]
146
- sample.english?.should be_false
147
- sample.french?.should be_true
148
- sample.german?.should be_true
149
- sample.japanese?.should be_false
150
- sample.custom_name.should == 6
146
+ expect(sample.english?).to be_falsey
147
+ expect(sample.french?).to be_truthy
148
+ expect(sample.german?).to be_truthy
149
+ expect(sample.japanese?).to be_falsey
150
+ expect(sample.custom_name).to eq(6)
151
151
  end
152
152
  end
153
153
 
@@ -164,22 +164,22 @@ describe SimpleSet do
164
164
  end
165
165
 
166
166
  sample = TestOptionPrefix1.new
167
- sample.should respond_to(:spoken_language_english?)
168
- sample.should respond_to(:spoken_language_french?)
169
- sample.should respond_to(:spoken_language_german?)
170
- sample.should respond_to(:spoken_language_japanese?)
171
-
172
- sample.should respond_to(:spoken_language_english=)
173
- sample.should respond_to(:spoken_language_french=)
174
- sample.should respond_to(:spoken_language_german=)
175
- sample.should respond_to(:spoken_language_japanese=)
176
-
177
- TestOptionPrefix1.should respond_to(:spoken_language_english)
178
- TestOptionPrefix1.should respond_to(:spoken_language_french)
179
- TestOptionPrefix1.should respond_to(:spoken_language_german)
180
- TestOptionPrefix1.should respond_to(:spoken_language_japanese)
181
-
182
- sample.should_not respond_to(:japanese?)
167
+ expect(sample).to respond_to(:spoken_language_english?)
168
+ expect(sample).to respond_to(:spoken_language_french?)
169
+ expect(sample).to respond_to(:spoken_language_german?)
170
+ expect(sample).to respond_to(:spoken_language_japanese?)
171
+
172
+ expect(sample).to respond_to(:spoken_language_english=)
173
+ expect(sample).to respond_to(:spoken_language_french=)
174
+ expect(sample).to respond_to(:spoken_language_german=)
175
+ expect(sample).to respond_to(:spoken_language_japanese=)
176
+
177
+ expect(TestOptionPrefix1).to respond_to(:spoken_language_english)
178
+ expect(TestOptionPrefix1).to respond_to(:spoken_language_french)
179
+ expect(TestOptionPrefix1).to respond_to(:spoken_language_german)
180
+ expect(TestOptionPrefix1).to respond_to(:spoken_language_japanese)
181
+
182
+ expect(sample).to_not respond_to(:japanese?)
183
183
  end
184
184
 
185
185
  it "should support custom prefix in getters and setters" do
@@ -188,22 +188,22 @@ describe SimpleSet do
188
188
  end
189
189
 
190
190
  sample = TestOptionPrefix2.new
191
- sample.should respond_to(:speaks_english?)
192
- sample.should respond_to(:speaks_french?)
193
- sample.should respond_to(:speaks_german?)
194
- sample.should respond_to(:speaks_japanese?)
195
-
196
- sample.should respond_to(:speaks_english=)
197
- sample.should respond_to(:speaks_french=)
198
- sample.should respond_to(:speaks_german=)
199
- sample.should respond_to(:speaks_japanese=)
200
-
201
- TestOptionPrefix2.should respond_to(:speaks_english)
202
- TestOptionPrefix2.should respond_to(:speaks_french)
203
- TestOptionPrefix2.should respond_to(:speaks_german)
204
- TestOptionPrefix2.should respond_to(:speaks_japanese)
205
-
206
- sample.should_not respond_to(:japanese?)
191
+ expect(sample).to respond_to(:speaks_english?)
192
+ expect(sample).to respond_to(:speaks_french?)
193
+ expect(sample).to respond_to(:speaks_german?)
194
+ expect(sample).to respond_to(:speaks_japanese?)
195
+
196
+ expect(sample).to respond_to(:speaks_english=)
197
+ expect(sample).to respond_to(:speaks_french=)
198
+ expect(sample).to respond_to(:speaks_german=)
199
+ expect(sample).to respond_to(:speaks_japanese=)
200
+
201
+ expect(TestOptionPrefix2).to respond_to(:speaks_english)
202
+ expect(TestOptionPrefix2).to respond_to(:speaks_french)
203
+ expect(TestOptionPrefix2).to respond_to(:speaks_german)
204
+ expect(TestOptionPrefix2).to respond_to(:speaks_japanese)
205
+
206
+ expect(sample).to_not respond_to(:japanese?)
207
207
  end
208
208
  end
209
209
 
@@ -219,21 +219,21 @@ describe SimpleSet do
219
219
  as_set :spoken_languages, [:english, :french, :german, :japanese], slim: true
220
220
  end
221
221
 
222
- TestOptionSlim1.should_not respond_to(:english)
223
- TestOptionSlim1.should_not respond_to(:french)
224
- TestOptionSlim1.should_not respond_to(:german)
225
- TestOptionSlim1.should_not respond_to(:japanese)
222
+ expect(TestOptionSlim1).to_not respond_to(:english)
223
+ expect(TestOptionSlim1).to_not respond_to(:french)
224
+ expect(TestOptionSlim1).to_not respond_to(:german)
225
+ expect(TestOptionSlim1).to_not respond_to(:japanese)
226
226
 
227
227
  sample = TestOptionSlim1.new
228
- sample.should_not respond_to(:english?)
229
- sample.should_not respond_to(:french?)
230
- sample.should_not respond_to(:german?)
231
- sample.should_not respond_to(:japanese?)
232
-
233
- sample.should_not respond_to(:english=)
234
- sample.should_not respond_to(:french=)
235
- sample.should_not respond_to(:german=)
236
- sample.should_not respond_to(:japanese=)
228
+ expect(sample).to_not respond_to(:english?)
229
+ expect(sample).to_not respond_to(:french?)
230
+ expect(sample).to_not respond_to(:german?)
231
+ expect(sample).to_not respond_to(:japanese?)
232
+
233
+ expect(sample).to_not respond_to(:english=)
234
+ expect(sample).to_not respond_to(:french=)
235
+ expect(sample).to_not respond_to(:german=)
236
+ expect(sample).to_not respond_to(:japanese=)
237
237
  end
238
238
 
239
239
  it 'should only generate instance members when :class is passed' do
@@ -241,21 +241,21 @@ describe SimpleSet do
241
241
  as_set :spoken_languages, [:english, :french, :german, :japanese], slim: :class
242
242
  end
243
243
 
244
- TestOptionSlim2.should_not respond_to(:english)
245
- TestOptionSlim2.should_not respond_to(:french)
246
- TestOptionSlim2.should_not respond_to(:german)
247
- TestOptionSlim2.should_not respond_to(:japanese)
244
+ expect(TestOptionSlim2).to_not respond_to(:english)
245
+ expect(TestOptionSlim2).to_not respond_to(:french)
246
+ expect(TestOptionSlim2).to_not respond_to(:german)
247
+ expect(TestOptionSlim2).to_not respond_to(:japanese)
248
248
 
249
249
  sample = TestOptionSlim2.new
250
- sample.should respond_to(:english?)
251
- sample.should respond_to(:french?)
252
- sample.should respond_to(:german?)
253
- sample.should respond_to(:japanese?)
254
-
255
- sample.should respond_to(:english=)
256
- sample.should respond_to(:french=)
257
- sample.should respond_to(:german=)
258
- sample.should respond_to(:japanese=)
250
+ expect(sample).to respond_to(:english?)
251
+ expect(sample).to respond_to(:french?)
252
+ expect(sample).to respond_to(:german?)
253
+ expect(sample).to respond_to(:japanese?)
254
+
255
+ expect(sample).to respond_to(:english=)
256
+ expect(sample).to respond_to(:french=)
257
+ expect(sample).to respond_to(:german=)
258
+ expect(sample).to respond_to(:japanese=)
259
259
  end
260
260
  end
261
261
 
@@ -273,7 +273,7 @@ describe SimpleSet do
273
273
 
274
274
  sample = TestOptionWhiny1.new
275
275
  expect { sample.spoken_languages = [:french, :italian, :japanese] }.to_not raise_error
276
- sample.spoken_languages.should == [:french, :japanese]
276
+ expect(sample.spoken_languages).to eq([:french, :japanese])
277
277
  end
278
278
  end
279
279
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_set
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Romain Tartière
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-03 00:00:00.000000000 Z
11
+ date: 2014-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: simple_enum
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ~>
18
- - !ruby/object:Gem::Version
19
- version: 1.6.8
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ~>
25
- - !ruby/object:Gem::Version
26
- version: 1.6.8
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: bundler
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -42,30 +28,30 @@ dependencies:
42
28
  name: rake
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
- - - '>='
31
+ - - ~>
46
32
  - !ruby/object:Gem::Version
47
- version: '0'
33
+ version: '10.3'
48
34
  type: :development
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
- - - '>='
38
+ - - ~>
53
39
  - !ruby/object:Gem::Version
54
- version: '0'
40
+ version: '10.3'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: rspec
57
43
  requirement: !ruby/object:Gem::Requirement
58
44
  requirements:
59
- - - '>='
45
+ - - ~>
60
46
  - !ruby/object:Gem::Version
61
- version: '0'
47
+ version: 3.0.0
62
48
  type: :development
63
49
  prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
66
- - - '>='
52
+ - - ~>
67
53
  - !ruby/object:Gem::Version
68
- version: '0'
54
+ version: 3.0.0
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: activerecord
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -84,16 +70,16 @@ dependencies:
84
70
  name: sqlite3
85
71
  requirement: !ruby/object:Gem::Requirement
86
72
  requirements:
87
- - - '>='
73
+ - - ~>
88
74
  - !ruby/object:Gem::Version
89
- version: '0'
75
+ version: '1.3'
90
76
  type: :development
91
77
  prerelease: false
92
78
  version_requirements: !ruby/object:Gem::Requirement
93
79
  requirements:
94
- - - '>='
80
+ - - ~>
95
81
  - !ruby/object:Gem::Version
96
- version: '0'
82
+ version: '1.3'
97
83
  description:
98
84
  email:
99
85
  - romain@blogreen.org