enum_help 0.0.5 → 0.0.6

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
  SHA1:
3
- metadata.gz: 708afd0843c9af2f77fb9d83719038ce6f848908
4
- data.tar.gz: 4a60c6dfe8183be0f0ec65120380eb0a9e333efe
3
+ metadata.gz: da7e2ccf08926cc86540d06e331f2bfe82c71634
4
+ data.tar.gz: f17dc5c72314bcc6551d68e3d737cdda82de0d0d
5
5
  SHA512:
6
- metadata.gz: 3d2a0f411ab953063b0088d88f05d8b74086dd17e1ef25f5639ed851b643f1ab7584b6a9eaf120edfb23e1eb4ce8b684c25aa53fef798f5aca06c8df0bb9bd97
7
- data.tar.gz: 099c390d3178d82208ff133d1fc9d2209b7688594d831e4d36f03571b05fc73f39e46964f00b1379b98f10e7771c65edd9f82f573ce1f62683c8ad0293fe8198
6
+ metadata.gz: 9266b252cbb1087318c363a7bba5617418060071f3063268ca61c91aab464440aafb5aad6049b066d86d58e1c2fa3545741f09856791a4eee8a73fb3086c1b5c
7
+ data.tar.gz: fd97e84192133b762a65e4bed61c2dda446aa067a9547d741ddc2c3b03c56a61d3169c717045625baac452786ef75c90a22518e24b51d3beb5680539591df64e
data/README.md CHANGED
@@ -31,7 +31,11 @@ required Rails 4.1.x
31
31
  In model file:
32
32
 
33
33
  class Order < ActiveRecord::Base
34
- enum status: { "nopayment" => 0, "finished" => 1 }
34
+ enum status: { "nopayment" => 0, "finished" => 1, "failed" => 2, "destroyed" => 3 }
35
+
36
+ def self.restricted_statuses
37
+ statuses.except :failed, :destroyed
38
+ end
35
39
  end
36
40
 
37
41
  You can call:
@@ -40,8 +44,8 @@ You can call:
40
44
  order.update_attribute :status, 0
41
45
  order.status
42
46
  # > nopayment
43
- order.status_i18n
44
- # > nopayment or 未支付
47
+ order.status_i18n # if you have an i18n file defined as following, it will return "未支付".
48
+ # > 未支付
45
49
 
46
50
  In _form.html.erb using simple form:
47
51
 
@@ -49,6 +53,12 @@ In _form.html.erb using simple form:
49
53
 
50
54
  This will generate select field with translations automaticlly.
51
55
 
56
+ And if you want to generate select except some values, then you can pass a collection option.
57
+
58
+ <%= f.input :status Order.restricted_statuses %>
59
+
60
+
61
+
52
62
  Other arguments for simple_form are supported perfectly.
53
63
 
54
64
  e.g.
@@ -67,10 +77,12 @@ I18n local file example:
67
77
  status:
68
78
  finished: 完成
69
79
  nopayment: 未支付
70
-
80
+ failed: 失败
81
+ destroyed: 已删除
71
82
 
72
83
  ## Thanks
73
84
  * [mrhead](https://github.com/mrhead)
85
+ * [Jin Lee](https://github.com/neojin)
74
86
 
75
87
  ## Contributing
76
88
 
@@ -16,7 +16,9 @@ module EnumHelp
16
16
 
17
17
  def initialize(*args)
18
18
  super
19
- raise "Attribute '#{attribute_name}' has no enum class" unless enum = object.class.send(attribute_name.to_s.pluralize)
19
+ enum = input_options[:collection] || @builder.options[:collection]
20
+ raise "Attribute '#{attribute_name}' has no enum class" unless enum ||= object.class.send(attribute_name.to_s.pluralize)
21
+
20
22
  collect = enum.collect{|k,v| [::I18n.t("enums.#{object.class.to_s.underscore}.#{attribute_name}.#{k}", default: k),k] }
21
23
  # collect.unshift [args.last[:prompt],''] if args.last.is_a?(Hash) && args.last[:prompt]
22
24
 
@@ -1,3 +1,3 @@
1
1
  module EnumHelp
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enum_help
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lester Zhao
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-11 00:00:00.000000000 Z
11
+ date: 2014-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler