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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +2 -7
- data/lib/rails_column_enumerator/version.rb +1 -1
- data/lib/rails_column_enumerator.rb +3 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cdd8e9b9674ef635e4ca3c28f0e1ce612df79377
|
4
|
+
data.tar.gz: 115862de8b7427aa5ccd7b3a4afc95c51d9aded7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d68e201a398535a731961df29626491d1410849f2dd8ff7806aa84c809c1b409b9ac5897e9469d00efc8172e23beb729fef0b28332a41de25a7ab0f562176bda
|
7
|
+
data.tar.gz: 7c0a57d2c988d76fcbe852e4565ab0dcc46ffc66942eaa149b7dd62e50efcc2672b8d7c55c5bf3ad34484e631b41c82e841264a07a3a0369c44cc693753e1b70
|
data/Gemfile.lock
CHANGED
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
|
45
|
-
#
|
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
|
@@ -9,10 +9,10 @@ module RailsColumnEnumerator
|
|
9
9
|
val
|
10
10
|
end
|
11
11
|
|
12
|
-
def self.get_record(val, enum_values, valid_values,
|
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 =
|
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.
|
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.
|
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-
|
11
|
+
date: 2016-02-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|