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 +4 -4
- data/README.md +17 -8
- data/lib/sequel_enum.rb +4 -2
- data/lib/sequel_enum/version.rb +1 -1
- data/sequel_enum.gemspec +0 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 387f4ad3dc225c8e4e437c1a3e070ee4e9ff7181
|
4
|
+
data.tar.gz: 7ce3158c97bfd0712f0eec6d8fa4e139a948aad3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 ```{
|
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, {
|
44
|
+
enum :condition, { mint: 10, good: 11, poor: 15 }
|
41
45
|
end
|
42
46
|
|
43
|
-
item = Item.
|
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
|
|
data/lib/sequel_enum.rb
CHANGED
@@ -23,11 +23,13 @@ module Sequel
|
|
23
23
|
end
|
24
24
|
|
25
25
|
define_method "#{column}=" do |value|
|
26
|
-
|
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])
|
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|
|
data/lib/sequel_enum/version.rb
CHANGED
data/sequel_enum.gemspec
CHANGED
@@ -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.
|
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-
|
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: '
|
113
|
+
version: '0'
|
114
114
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
115
|
requirements:
|
116
116
|
- - ">="
|