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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 89190c022a1e885c4be851cacfe768892d5d0fd7
4
- data.tar.gz: ee8b544d9a48aa9e3efb09a4d7e5938723cd1ed4
3
+ metadata.gz: 1135416c25c845f72848689a96a873ebaf4f3f18
4
+ data.tar.gz: cd4fef11a999f4c936548fd1018c532126f0370e
5
5
  SHA512:
6
- metadata.gz: af3d11f0593e71acaa43d016d3957b5a0d3572a46ba71f323d3c91283f9f029607b50a0058bbe2efa553314796c9e6d2e3b56f657b105744f1aff2b17285d0c7
7
- data.tar.gz: dc1a82e176a10ce7bb4d9283d7fd10baeaf5de38ebd04d5dcb7418cf4dade935cc1b5a1a1868334351a72a9c4e57136e299b075564ac38aa01bed2ef2a99131b
6
+ metadata.gz: 159439403d58e8900f063ae189d0cf4623517ad6bd610899ebe2121d657fe0fb9f48f973ed30991fa5c49a5d055c4bc81ed0663cc8efa3982b38f2ed637a5a0e
7
+ data.tar.gz: 59b9baa10c382336a35cf07155b9ec1b98c15c57477ff0a989fc2a44e852437b81209211bdee686e191b306dcf43ec115cda721cdb10a2f712b7cf3ef0013096
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ .DS_Store
2
+ rails_column_enumerator-*.gem
data/Gemfile.lock CHANGED
@@ -1,35 +1,40 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rails_column_enumerator (0.1.0)
4
+ rails_column_enumerator (1.0.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- activemodel (3.2.11)
10
- activesupport (= 3.2.11)
11
- builder (~> 3.0.0)
12
- activerecord (3.2.11)
13
- activemodel (= 3.2.11)
14
- activesupport (= 3.2.11)
15
- arel (~> 3.0.2)
16
- tzinfo (~> 0.3.29)
17
- activesupport (3.2.11)
18
- i18n (~> 0.6)
19
- multi_json (~> 1.0)
20
- arel (3.0.3)
21
- builder (3.0.4)
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
- multi_json (1.11.2)
25
+ json (1.8.3)
26
+ minitest (5.8.3)
24
27
  mysql2 (0.3.18)
25
28
  rake (10.4.2)
26
- tzinfo (0.3.45)
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 (= 3.2.11)
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::SAMPLE_COLUMN_SYMBOLS # { 1 => "first", 2 => "second", 3 => "third" }
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/[my-github-username]/rails_column_enumerator/fork )
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`)
@@ -1,3 +1,3 @@
1
1
  module RailsColumnEnumerator
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -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 + '_SYMBOLS').to_sym
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", "3.2.11"
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.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: 3.2.11
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: 3.2.11
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