rails_column_enumerator 1.0.1 → 1.0.2

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: 1135416c25c845f72848689a96a873ebaf4f3f18
4
- data.tar.gz: cd4fef11a999f4c936548fd1018c532126f0370e
3
+ metadata.gz: c6142a21527dc7356777b36c1d29f0ecb092cbf7
4
+ data.tar.gz: 5f5af75ce9697d802da55f2afd630c79b2ff2130
5
5
  SHA512:
6
- metadata.gz: 159439403d58e8900f063ae189d0cf4623517ad6bd610899ebe2121d657fe0fb9f48f973ed30991fa5c49a5d055c4bc81ed0663cc8efa3982b38f2ed637a5a0e
7
- data.tar.gz: 59b9baa10c382336a35cf07155b9ec1b98c15c57477ff0a989fc2a44e852437b81209211bdee686e191b306dcf43ec115cda721cdb10a2f712b7cf3ef0013096
6
+ metadata.gz: f4122a21688fb8d6d72f862b1e9a1855a3d1f8877a7087d3df00a26e4c04f6edadd14c93e672fb6a5c69ad1ca9d731e90077cd1c8419517a549428fa46812635
7
+ data.tar.gz: 983bf0c595fc9bcd4e182858a459296a6327d01625f97aa127f6139591f98e68874e09547125a3c0aadf489257cea103b84691ecc3a4ef958021f11152fb2630
data/README.md CHANGED
@@ -20,46 +20,46 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- Add ```extends RailsColumnEnumerator``` to the top of whatever class you want to add an enumerated column to
23
+ Add ```extends RailsColumnEnumerator``` to the top of whatever class you want to add an enumerated column to.
24
24
 
25
- Then define the attribute with ```enumerated_column``` method
25
+ Then define the attribute with ```enumerated_column``` method.
26
26
 
27
27
  example:
28
28
  ```ruby
29
29
  class TestClass < ActiveRecord::Base
30
30
  extends RailsColumnEnumerator
31
31
 
32
- enumerated_column :sample_column, { first: 1, second: 2, third: 3 }
32
+ enumerated_column :state, { open: 1, closed: 2, failed: 3 }
33
33
  end
34
34
 
35
- # The following two consts would be added to your class (Their name is derived from the name you pass into 'enumerated_column')
36
- TestClass::SAMPLE_COLUMNS # { "first" => 1, "second" => 2, "third" => 3}
37
- TestClass::SAMPLE_COLUMN_NAMES # { 1 => "first", 2 => "second", 3 => "third" }
35
+ # The following two consts would be added to your class (Their name is derived from the attribute name you pass into 'enumerated_column')
36
+ TestClass::STATES # { "open" => 1, "closed" => 2, "failed" => 3}
37
+ TestClass::STATE_NAMES # { 1 => :open, 2 => :closed, 3 => :failed }
38
38
 
39
39
  # You can use your enumerated attribute as follows
40
40
  example = TestClass.new
41
41
 
42
- example.sample_column = :second
42
+ example.state = :closed
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"
44
+ # When accessing the attribute it will return the integer value by default, if you want to return the symbol then simply pass in a parameter of "true"
45
45
  # This is to maintain support for XML serialization of the object (to_xml) amongst other things.
46
- example.sample_column # 2
47
- example.sample_column(true) # :second
46
+ example.state # 2
47
+ example.state(true) # :closed
48
48
 
49
- example.sample_column = 3
49
+ example.state = 3
50
50
 
51
- example.sample_column # 3
52
- example.sample_column(true) # :third
51
+ example.state # 3
52
+ example.state(true) # :failed
53
53
 
54
54
  # The enumerated column will also be validated so that it must include values present in your enumerator
55
55
 
56
- example.sample_column = :fourth
57
- example.sample_column # nil
56
+ example.state = :pending
57
+ example.state # nil
58
58
 
59
- example.sample_column = 4
60
- example.sample_column # 4
59
+ example.state = 4
60
+ example.state # 4
61
61
 
62
- example.sample_column.save! # raises "ActiveRecord::RecordInvalid, 'Validation failed: Sample column is not included in the list'"
62
+ example.state.save! # raises "ActiveRecord::RecordInvalid, 'Validation failed: Sample column is not included in the list'"
63
63
  ```
64
64
 
65
65
  ## Development
@@ -1,3 +1,3 @@
1
1
  module RailsColumnEnumerator
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -1,7 +1,7 @@
1
1
  require "rails_column_enumerator/version"
2
2
 
3
3
  module RailsColumnEnumerator
4
- def enumerated_column(column_name, enumerated_values)
4
+ def enumerated_column(column_name, enumerated_values, options = {})
5
5
  enum_name = column_name.to_s.pluralize.upcase.to_sym
6
6
  enum_symbols_name = (column_name.to_s.upcase + '_NAMES').to_sym
7
7
 
@@ -21,6 +21,8 @@ module RailsColumnEnumerator
21
21
  end
22
22
  end
23
23
 
24
- validates column_name, inclusion: const_get(enum_name).values
24
+ options.merge!(inclusion: const_get(enum_name).values) unless options[:inclusion].present?
25
+
26
+ validates column_name, options
25
27
  end
26
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_column_enumerator
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
  - Brian O'Reilly
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-18 00:00:00.000000000 Z
11
+ date: 2015-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler