acts_as_railable 0.2.0 → 0.3.0
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/lib/acts_as_railable/humanable.rb +17 -11
- data/lib/acts_as_railable/interval.rb +1 -1
- data/lib/acts_as_railable/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 566e969945d5fe9cb3c6e124626419490ad8a6bc2278def29d61b28d29826231
|
4
|
+
data.tar.gz: 6eb4c7a8fcc9ba9249adb7d1323dc9f2d8820f4b646770f5f734c3bdd82b08e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 245088d2f7441d9be30703f38f728f801972af70c7941a5e2e28d7ba0da092a3aebae1efdebb4f576be3d639f78130be2d623767d983ef50d1117bc96c101620
|
7
|
+
data.tar.gz: a050465502d8540ad9949e0221b95f37ad8cb8651597ae0bab6d9783a7be96ff6d4f394c953fb640fa87d1bdc7feb35ec62902fc9760c3b903877cb885ee6f97
|
@@ -7,34 +7,40 @@ module ActsAsRailable
|
|
7
7
|
self.human_attribute_name attr
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
11
|
-
|
10
|
+
def i18n_action_name name, default_name=nil
|
11
|
+
action_key = "#{self.table_name}.action.#{name}"
|
12
|
+
default_key = "application.action.#{name}" # unless I18n.exists? key
|
13
|
+
default_name ||= name.to_s.capitalize
|
14
|
+
I18n.t(action_key, model: self.model_name.human, default: [ default_key.to_sym, default_name ])
|
12
15
|
end
|
13
16
|
|
14
|
-
|
17
|
+
# i18n_enum_name(:status, :edited)
|
18
|
+
def i18n_enum_name(enum_name, enum_value)
|
15
19
|
self.human_attribute_name "#{enum_name}.#{enum_value}"
|
16
20
|
end
|
17
21
|
|
18
|
-
|
22
|
+
# enum status: { edited: 0, published: 1, approved: 2, trashed: 3 }
|
23
|
+
# i18n_enum_choices(:status)
|
24
|
+
def i18n_enum_choices enum_name
|
19
25
|
enum_hash = self.public_send enum_name.to_s.pluralize
|
20
|
-
enum_hash.keys.map { |enum_value| [ self.
|
26
|
+
enum_hash.keys.map { |enum_value| [ self.i18n_enum_name(enum_name, enum_value), enum_value ] }
|
21
27
|
end
|
22
28
|
|
23
|
-
# constants
|
24
29
|
# CURRENCIES = %w( CNY USD EUR GBP JPY )
|
25
|
-
|
30
|
+
# i18n_array_choices(:currency)
|
31
|
+
def i18n_array_choices enum_name
|
26
32
|
array_values = self.const_get enum_name.to_s.pluralize.upcase
|
27
|
-
array_values.map { |enum_value| [ self.
|
33
|
+
array_values.map { |enum_value| [ self.i18n_enum_name(enum_name, enum_value), enum_value ] }
|
28
34
|
end
|
29
35
|
end
|
30
36
|
|
31
37
|
def i18n_attribute_name attr
|
32
|
-
self.class.
|
38
|
+
self.class.human_attribute_name attr
|
33
39
|
end
|
34
40
|
|
35
|
-
def
|
41
|
+
def i18n_enum_name enum_name
|
36
42
|
enum_value = self.public_send enum_name
|
37
|
-
self.class.
|
43
|
+
self.class.i18n_enum_name enum_name, enum_value
|
38
44
|
end
|
39
45
|
end
|
40
46
|
end
|