rails_column_enumerator 1.3.0 → 1.3.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: cab423e5aafb991c2d0078aba5a69d519c8a3455
4
- data.tar.gz: 7778867ce83935b8cdb2984dbc8f935f19a5f34d
3
+ metadata.gz: cdd8e9b9674ef635e4ca3c28f0e1ce612df79377
4
+ data.tar.gz: 115862de8b7427aa5ccd7b3a4afc95c51d9aded7
5
5
  SHA512:
6
- metadata.gz: 447ca04146e24e7221a0672a1fcb94991b9187d8f0055778d14dde68efbfe8e91ea41818031e4e22680593c35f543b4ea80ad56c84b4ea18f363bf887c46fece
7
- data.tar.gz: 0e58eabc5520c44cee57c4ff442ea6b6cf3ef8d7b7e612c22f917d3b9b90d585cf80cb2fc9422d462c170d15a214d856ed9a8b6924abbcfd6a73ad1ce2e24428
6
+ metadata.gz: d68e201a398535a731961df29626491d1410849f2dd8ff7806aa84c809c1b409b9ac5897e9469d00efc8172e23beb729fef0b28332a41de25a7ab0f562176bda
7
+ data.tar.gz: 7c0a57d2c988d76fcbe852e4565ab0dcc46ffc66942eaa149b7dd62e50efcc2672b8d7c55c5bf3ad34484e631b41c82e841264a07a3a0369c44cc693753e1b70
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rails_column_enumerator (1.3.0)
4
+ rails_column_enumerator (1.3.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -41,13 +41,8 @@ enumerated_column :state, { open: 1, closed: 2, failed: 3 }, selections: { not_f
41
41
  TestClass::NOT_FAILED # [["Open", 1], ["Closed", 2]]
42
42
  TestClass::NOT_OPEN # [["Closed", 2], ["Failed", 3]]
43
43
 
44
- # You can also add localization options for these select helper outputs. These are matched to the name of the selection.
45
- # These are optional and provide support for a default value.
46
- default_localizations = { failed: "OMG WTF BBQ!?" }
47
- all_states_localizations = { open: "I am open" }
48
-
49
- enumerated_column :state, { open: 1, closed: 2, failed: 3 }, selections: { all_states: [1, 2, 3] }, localizations: { default: default_localizations, all_states: all_states_localizations }
50
- TestClass::ALL_STATES # [["I am open", 1], ["Closed", 2], ["OMG WTF BBQ!?", 3]]
44
+ # You can also add i18n localizations for these select helper outputs.
45
+ # The gem matches values in the helpers with i18n entries under .models.class_name.column_name.scope_name(or default).key
51
46
 
52
47
  # You can use your enumerated attribute as follows
53
48
  example = TestClass.new
@@ -1,3 +1,3 @@
1
1
  module RailsColumnEnumerator
2
- VERSION = "1.3.0"
2
+ VERSION = "1.3.1"
3
3
  end
@@ -9,10 +9,10 @@ module RailsColumnEnumerator
9
9
  val
10
10
  end
11
11
 
12
- def self.get_record(val, enum_values, valid_values, localization_values, helper_name)
12
+ def self.get_record(val, enum_values, valid_values, helper_name, column_name, class_name)
13
13
  val = get_int(val, enum_values, valid_values)
14
14
  key = valid_values[val]
15
- text = localization_values[helper_name].try(:[], key) || localization_values[:default].try(:[], key) || valid_values[val].to_s.titleize
15
+ text = I18n.t(".models.#{class_name}.#{column_name}.#{helper_name}.#{key}", :default => I18n.t(".models.#{class_name}.#{column_name}.default.#{key}", :default => valid_values[val].to_s.titleize))
16
16
  [text, val]
17
17
  end
18
18
 
@@ -23,12 +23,10 @@ module RailsColumnEnumerator
23
23
  self.const_set(enum_name, enumerated_values.with_indifferent_access)
24
24
  self.const_set(enum_symbols_name, enumerated_values.invert)
25
25
 
26
- localization_options = options.delete(:localizations) || {}
27
-
28
26
  extra_select_options = options.delete(:selections)
29
27
  if extra_select_options
30
28
  extra_select_options.each do |name, options|
31
- self.const_set(name.to_s.upcase, options.map{ |key| RailsColumnEnumerator.get_record(key, self.const_get(enum_name), self.const_get(enum_symbols_name), localization_options, name) })
29
+ self.class.send(:define_method, name.to_s) { options.map{ |key| RailsColumnEnumerator.get_record(key, self.const_get(enum_name), self.const_get(enum_symbols_name), name, column_name, self.name.underscore.downcase) } }
32
30
  end
33
31
  end
34
32
 
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.3.0
4
+ version: 1.3.1
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: 2016-02-04 00:00:00.000000000 Z
11
+ date: 2016-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler