acts_as_railable 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c78756ddbf5d7766d77bf22d256cef16e2f283d65e67a0e8b0a166ab530ba440
4
- data.tar.gz: ea8ebf6d556b81eb532098a29735cce81ce64f3f92b5315ca22761f5f2531692
3
+ metadata.gz: 566e969945d5fe9cb3c6e124626419490ad8a6bc2278def29d61b28d29826231
4
+ data.tar.gz: 6eb4c7a8fcc9ba9249adb7d1323dc9f2d8820f4b646770f5f734c3bdd82b08e2
5
5
  SHA512:
6
- metadata.gz: 52f287a70f5beaaa1a2cbe20da7522637c3a9d44aa2f6533cee285b91f52f9e57ceb6a1633326881f1f872b27cc3a8f2e6da40cbe11379ec0d4379e993531623
7
- data.tar.gz: fb7ee2c57767a3f1a70a98a6c28d5fc9c9bb93ec9414be1fba17ae46613991b83b94c7caf897ca3b4418eed447575acb5bdfe2af533183d6ff37b06ce9ec1785
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 human_action_name action, views="defaults"
11
- I18n.t("#{views}.action.#{action}", model: self.model_name.human)
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
- def human_enum_name(enum_name, enum_value)
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
- def human_enum_choices enum_name
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.human_enum_name(enum_name, enum_value), enum_value ] }
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
- def human_array_choices enum_name
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.human_enum_name(enum_name, enum_value), enum_value ] }
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.i18n_attribute_name attr
38
+ self.class.human_attribute_name attr
33
39
  end
34
40
 
35
- def human_enum_name enum_name
41
+ def i18n_enum_name enum_name
36
42
  enum_value = self.public_send enum_name
37
- self.class.human_enum_name enum_name, enum_value
43
+ self.class.i18n_enum_name enum_name, enum_value
38
44
  end
39
45
  end
40
46
  end
@@ -3,7 +3,7 @@ module ActsAsRailable
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  included do
6
- # database: local date
6
+ # database: date
7
7
  # parameter: local date
8
8
  scope :date_field_interval, -> (field, d1, d2) {
9
9
  tname = self.table_name
@@ -1,3 +1,3 @@
1
1
  module ActsAsRailable
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_railable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Li Qi