sequel_enum 0.1.0 → 0.1.1

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: '09d1193b9cc43bff32889c4ab0f3aea15a44c2de'
4
- data.tar.gz: af7d9423ae0458790b4433b8c1f72e00bc5876a4
3
+ metadata.gz: 387f4ad3dc225c8e4e437c1a3e070ee4e9ff7181
4
+ data.tar.gz: 7ce3158c97bfd0712f0eec6d8fa4e139a948aad3
5
5
  SHA512:
6
- metadata.gz: f757ee8c49dae3678ee838f180eaca8e81c14fc60fae40372bfc238a4369b266bbbb94d63425777b5102f4e1133e9108c3e457fd11e1a7025423cd4ca55278d2
7
- data.tar.gz: 5ed11d2377ccbad5282d5f57c88e0104a53c61735af225ff25502062e035d52b54fdd338662b16649c5339c1fa3263a2c441879e10937b1bc314eb3af098599a
6
+ metadata.gz: 99d71e7a509081b9ae3bcc1c67cbecf847e4998dab1f33738f9e53ccafce93a35923c03d5adbef1bb99a453655c156d66ba01a88f77a0f325518519fb7e7287f
7
+ data.tar.gz: 8d519bdb2bd0c65e95f42f92d35086d6e427353be8fb37bba8b14d7bbdefc82668e54fea35fb61e3ac7889f98736bc783d947bc534a7a898fc73cecdb2c6909c
data/README.md CHANGED
@@ -27,25 +27,34 @@ end
27
27
  item = Item.new
28
28
  item.condition = :mint
29
29
 
30
- item.condition #> :mint
31
- item.mint? #> true
32
- item.good? #> false
30
+ print item.condition #> :mint
31
+ print item.mint? #> true
32
+ print item.good? #> false
33
+
34
+ item.update(:condition => :good)
35
+
36
+ print item.good? #> true
33
37
  ```
34
38
 
35
- ```#enum``` accepts a hash like ```{ index => value }``` as well:
39
+ ```#enum``` accepts a hash like ```{ :alias => value }``` as well:
36
40
 
37
41
  ```ruby
38
42
  class Item < Sequel::Model
39
43
  plugin :enum
40
- enum :condition, {10 => :mint, 11 => :good, 15 => :poor}
44
+ enum :condition, { mint: 10, good: 11, poor: 15 }
41
45
  end
42
46
 
43
- item = Item.new
44
- item.condition = :mint
47
+ item = Item.create(:condition => :mint)
45
48
 
46
- item[:condition] #> 10
49
+ print item[:condition] #> 10
47
50
  ```
48
51
 
52
+ You can set the raw value through the []= accessor:
53
+
54
+ ```ruby
55
+ item[:condition] = 15
56
+ print item.condition #> :poor
57
+ ```
49
58
 
50
59
  ## Contributing
51
60
 
@@ -23,11 +23,13 @@ module Sequel
23
23
  end
24
24
 
25
25
  define_method "#{column}=" do |value|
26
- self[column] = self.class.enums[column].assoc(value.to_sym)&.last
26
+ val = self.class.enums[column].assoc(value.to_sym)
27
+ self[column] = val && val.last
27
28
  end
28
29
 
29
30
  define_method "#{column}" do
30
- self.class.enums[column].rassoc(self[column])&.first
31
+ val = self.class.enums[column].rassoc(self[column])
32
+ val && val.first
31
33
  end
32
34
 
33
35
  values.each do |key, value|
@@ -1,3 +1,3 @@
1
1
  module SequelEnum
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -18,8 +18,6 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.required_ruby_version = '>= 2.3'
22
-
23
21
  spec.add_runtime_dependency "sequel"
24
22
 
25
23
  spec.add_development_dependency "rake"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel_enum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrià Planas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-12 00:00:00.000000000 Z
11
+ date: 2017-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel
@@ -110,7 +110,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
110
110
  requirements:
111
111
  - - ">="
112
112
  - !ruby/object:Gem::Version
113
- version: '2.3'
113
+ version: '0'
114
114
  required_rubygems_version: !ruby/object:Gem::Requirement
115
115
  requirements:
116
116
  - - ">="