rails_column_enumerator 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/Gemfile.lock +22 -17
- data/README.md +14 -2
- data/lib/rails_column_enumerator/version.rb +1 -1
- data/lib/rails_column_enumerator.rb +3 -1
- data/rails_column_enumerator.gemspec +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1135416c25c845f72848689a96a873ebaf4f3f18
|
4
|
+
data.tar.gz: cd4fef11a999f4c936548fd1018c532126f0370e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 159439403d58e8900f063ae189d0cf4623517ad6bd610899ebe2121d657fe0fb9f48f973ed30991fa5c49a5d055c4bc81ed0663cc8efa3982b38f2ed637a5a0e
|
7
|
+
data.tar.gz: 59b9baa10c382336a35cf07155b9ec1b98c15c57477ff0a989fc2a44e852437b81209211bdee686e191b306dcf43ec115cda721cdb10a2f712b7cf3ef0013096
|
data/.gitignore
ADDED
data/Gemfile.lock
CHANGED
@@ -1,35 +1,40 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rails_column_enumerator (
|
4
|
+
rails_column_enumerator (1.0.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
activemodel (
|
10
|
-
activesupport (=
|
11
|
-
builder (~> 3.
|
12
|
-
activerecord (
|
13
|
-
activemodel (=
|
14
|
-
activesupport (=
|
15
|
-
arel (~>
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
9
|
+
activemodel (4.2.5)
|
10
|
+
activesupport (= 4.2.5)
|
11
|
+
builder (~> 3.1)
|
12
|
+
activerecord (4.2.5)
|
13
|
+
activemodel (= 4.2.5)
|
14
|
+
activesupport (= 4.2.5)
|
15
|
+
arel (~> 6.0)
|
16
|
+
activesupport (4.2.5)
|
17
|
+
i18n (~> 0.7)
|
18
|
+
json (~> 1.7, >= 1.7.7)
|
19
|
+
minitest (~> 5.1)
|
20
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
21
|
+
tzinfo (~> 1.1)
|
22
|
+
arel (6.0.3)
|
23
|
+
builder (3.2.2)
|
22
24
|
i18n (0.7.0)
|
23
|
-
|
25
|
+
json (1.8.3)
|
26
|
+
minitest (5.8.3)
|
24
27
|
mysql2 (0.3.18)
|
25
28
|
rake (10.4.2)
|
26
|
-
|
29
|
+
thread_safe (0.3.5)
|
30
|
+
tzinfo (1.2.2)
|
31
|
+
thread_safe (~> 0.1)
|
27
32
|
|
28
33
|
PLATFORMS
|
29
34
|
ruby
|
30
35
|
|
31
36
|
DEPENDENCIES
|
32
|
-
activerecord (=
|
37
|
+
activerecord (= 4.2.5)
|
33
38
|
bundler (~> 1.8)
|
34
39
|
mysql2 (= 0.3.18)
|
35
40
|
rails_column_enumerator!
|
data/README.md
CHANGED
@@ -34,13 +34,15 @@ end
|
|
34
34
|
|
35
35
|
# The following two consts would be added to your class (Their name is derived from the name you pass into 'enumerated_column')
|
36
36
|
TestClass::SAMPLE_COLUMNS # { "first" => 1, "second" => 2, "third" => 3}
|
37
|
-
TestClass::
|
37
|
+
TestClass::SAMPLE_COLUMN_NAMES # { 1 => "first", 2 => "second", 3 => "third" }
|
38
38
|
|
39
39
|
# You can use your enumerated attribute as follows
|
40
40
|
example = TestClass.new
|
41
41
|
|
42
42
|
example.sample_column = :second
|
43
43
|
|
44
|
+
# When accessing the attribute it will return the integer value by default, if you with to return the symbol then simply pass in a parameter of "true"
|
45
|
+
# This is to maintain support for XML serialization of the object (to_xml) amongst other things.
|
44
46
|
example.sample_column # 2
|
45
47
|
example.sample_column(true) # :second
|
46
48
|
|
@@ -48,6 +50,16 @@ example.sample_column = 3
|
|
48
50
|
|
49
51
|
example.sample_column # 3
|
50
52
|
example.sample_column(true) # :third
|
53
|
+
|
54
|
+
# The enumerated column will also be validated so that it must include values present in your enumerator
|
55
|
+
|
56
|
+
example.sample_column = :fourth
|
57
|
+
example.sample_column # nil
|
58
|
+
|
59
|
+
example.sample_column = 4
|
60
|
+
example.sample_column # 4
|
61
|
+
|
62
|
+
example.sample_column.save! # raises "ActiveRecord::RecordInvalid, 'Validation failed: Sample column is not included in the list'"
|
51
63
|
```
|
52
64
|
|
53
65
|
## Development
|
@@ -58,7 +70,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
58
70
|
|
59
71
|
## Contributing
|
60
72
|
|
61
|
-
1. Fork it ( https://github.com/
|
73
|
+
1. Fork it ( https://github.com/brianclio/rails_column_enumerator/fork )
|
62
74
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
63
75
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
64
76
|
4. Push to the branch (`git push origin my-new-feature`)
|
@@ -3,7 +3,7 @@ require "rails_column_enumerator/version"
|
|
3
3
|
module RailsColumnEnumerator
|
4
4
|
def enumerated_column(column_name, enumerated_values)
|
5
5
|
enum_name = column_name.to_s.pluralize.upcase.to_sym
|
6
|
-
enum_symbols_name = (column_name.to_s.upcase + '
|
6
|
+
enum_symbols_name = (column_name.to_s.upcase + '_NAMES').to_sym
|
7
7
|
|
8
8
|
self.const_set(enum_name, enumerated_values.with_indifferent_access)
|
9
9
|
self.const_set(enum_symbols_name, enumerated_values.invert)
|
@@ -20,5 +20,7 @@ module RailsColumnEnumerator
|
|
20
20
|
write_attribute(column_name, val)
|
21
21
|
end
|
22
22
|
end
|
23
|
+
|
24
|
+
validates column_name, inclusion: const_get(enum_name).values
|
23
25
|
end
|
24
26
|
end
|
@@ -18,6 +18,6 @@ Gem::Specification.new do |spec|
|
|
18
18
|
|
19
19
|
spec.add_development_dependency "bundler", "~> 1.8"
|
20
20
|
spec.add_development_dependency "rake", "~> 10.0"
|
21
|
-
spec.add_development_dependency "activerecord", "
|
21
|
+
spec.add_development_dependency "activerecord", "4.2.5"
|
22
22
|
spec.add_development_dependency 'mysql2', '0.3.18'
|
23
23
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_column_enumerator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian O'Reilly
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - '='
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 4.2.5
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - '='
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 4.2.5
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: mysql2
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -74,6 +74,7 @@ executables:
|
|
74
74
|
extensions: []
|
75
75
|
extra_rdoc_files: []
|
76
76
|
files:
|
77
|
+
- ".gitignore"
|
77
78
|
- Gemfile
|
78
79
|
- Gemfile.lock
|
79
80
|
- README.md
|