enum_help 0.0.10 → 0.0.11

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: d9bab58fee36f103d6dac37d93f64f56ceaa870c
4
- data.tar.gz: e6b064455eb7a58d63f568d03000d3cb458c5ec2
3
+ metadata.gz: d041b071b80798a39880cc1fa72bbd4dcf329849
4
+ data.tar.gz: f0477e5d2c29fa3dcbcf580f78b53cc4c8f7dbc7
5
5
  SHA512:
6
- metadata.gz: 090068e7311f52bb00f9b2c0c6391144d50fefdf669aa38583b609d7c3da3de422da4e00429307463a4c45539c0518f135898f6dc2df21256c75e9c1782eba9b
7
- data.tar.gz: 4079525deb12d50abce3806e0e5e14031ba0649c47a0c91cafd8a6828ef51914a100b6232e6d73c7c0d24513502a1f3e743c454fc873ebcf1614ad63a4156b21
6
+ metadata.gz: fce939611966166b5e82749f53ac2d1386780576d3010c871afcfcad31482403696f717714bd667f3b26055c2951e27bc89ee4ef7d472ded74cdd63fd50876ed
7
+ data.tar.gz: 59f664a9598971f560078870073bede73b811c03f1fdadfefe84b7baa50a86a17e40c6fd7988aa53084b3175ab1774062cbc757d79d93dcaeda51bc4beabc584
@@ -41,14 +41,10 @@ module EnumHelp
41
41
  collection_i18n_method_name = "#{collection_method_name}_i18n"
42
42
 
43
43
  klass.instance_eval <<-METHOD, __FILE__, __LINE__
44
- def #{collection_i18n_method_name}(*args)
45
- options = args.extract_options!
46
- collection = args[0] || send(:#{collection_method_name})
47
- collection.except! options[:except] if options[:except]
48
-
49
- collection.map do |label, value|
50
- [::EnumHelp::Helper.translate_enum_label(self, :#{attr_name}, label), value]
51
- end.to_h
44
+ def #{collection_i18n_method_name}
45
+ #{collection_method_name}.collect do |label, _|
46
+ [label, ::EnumHelp::Helper.translate_enum_label(self, :#{attr_name}, label)]
47
+ end.to_h.with_indifferent_access
52
48
  end
53
49
  METHOD
54
50
  end
@@ -31,7 +31,14 @@ module EnumHelp
31
31
  enum = input_options[:collection] || @builder.options[:collection]
32
32
  raise "Attribute '#{attribute_name}' has no enum class" unless enum ||= object.class.send(attribute_name.to_s.pluralize)
33
33
 
34
- collect = object.class.send("#{attribute_name.to_s.pluralize}_i18n", enum.to_h).to_a
34
+ enum = enum.keys if enum.is_a? Hash
35
+
36
+ collect = begin
37
+ collection = object.class.send("#{attribute_name.to_s.pluralize}_i18n")
38
+ collection.slice!(*enum) if enum
39
+ collection.invert.to_a
40
+ end
41
+
35
42
  # collect.unshift [args.last[:prompt],''] if args.last.is_a?(Hash) && args.last[:prompt]
36
43
 
37
44
  if respond_to?(:input_options)
@@ -1,3 +1,3 @@
1
1
  module EnumHelp
2
- VERSION = "0.0.10"
2
+ VERSION = "0.0.11"
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.10
4
+ version: 0.0.11
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-09-25 00:00:00.000000000 Z
11
+ date: 2014-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler