rails_string_enum 0.5.2 → 0.5.3
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/README.md +1 -1
- data/lib/rails_string_enum/simple_form.rb +14 -17
- data/lib/rails_string_enum/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ffee91f4b0ce3428ba935ae14a4ef9ff25fd29f
|
4
|
+
data.tar.gz: 9c690218888e9461d46a6509d0982af6fdb70a7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e41e44d7a4d245b06c46f2b7723099105c6f1e9f2ac6ccfef39ef785a10fa6a845d8b1fe0fe9f40dbb045db409f40af5dcdf9773c86c775d86c8b39a65568390
|
7
|
+
data.tar.gz: 4222fd47916c08802755aab4ce9659ff1bf8bf8159b41c3361fc2556d56b0f0869fb0d9605d5a860609590d05be53054977a0cb7d59c9c4484059e262ce5d4bf
|
data/README.md
CHANGED
@@ -46,7 +46,7 @@ delete_enum_value :color, 'black'
|
|
46
46
|
###### Convert exist columns (int, string) to postgresql enum
|
47
47
|
```ruby
|
48
48
|
string_to_enums :product, :color, enum_name: 'product_color_enum', definitions: %w(red green blue), default: 'green'
|
49
|
-
string_to_enums :product, :color, enum_name: 'product_color_enum', definitions: Product.uniq.pluck(:color)
|
49
|
+
string_to_enums :product, :color, enum_name: 'product_color_enum', definitions: Product.unscoped.uniq.pluck(:color).compact
|
50
50
|
|
51
51
|
int_to_enums :product, :color, enum_name: 'product_color_enum', definitions: { red: 0, green: 1, blue: 2 }
|
52
52
|
```
|
@@ -1,22 +1,21 @@
|
|
1
1
|
require 'simple_form'
|
2
2
|
|
3
|
-
module
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
def default_input_type_with_enum(*args, &block)
|
8
|
-
attr_name = (args.first || @attribute_name).to_s
|
9
|
-
options = args.last
|
3
|
+
module BuilderExtensionWithEnum
|
4
|
+
def default_input_type(*args, &block)
|
5
|
+
attr_name = (args.first || @attribute_name).to_s
|
6
|
+
options = args.last
|
10
7
|
|
11
|
-
|
8
|
+
const_for_attr = object.respond_to? "#{attr_name}_i18n"
|
12
9
|
|
13
|
-
|
14
|
-
|
10
|
+
return :enum_radio_buttons if options.is_a?(Hash) && options[:as] == :radio_buttons && const_for_attr
|
11
|
+
return :enum if (options.is_a?(Hash) ? options[:as] : @options[:as]).nil? && const_for_attr
|
15
12
|
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
super(*args, &block)
|
14
|
+
end
|
15
|
+
end
|
19
16
|
|
17
|
+
module EnumHelp
|
18
|
+
module SimpleForm
|
20
19
|
module InputExtension
|
21
20
|
|
22
21
|
def initialize(*args)
|
@@ -59,11 +58,9 @@ end
|
|
59
58
|
|
60
59
|
|
61
60
|
SimpleForm::FormBuilder.class_eval do
|
62
|
-
include EnumHelp::SimpleForm::BuilderExtension
|
63
|
-
|
64
61
|
map_type :enum, :to => EnumHelp::SimpleForm::EnumInput
|
65
62
|
map_type :enum_radio_buttons, :to => EnumHelp::SimpleForm::EnumRadioButtons
|
66
63
|
alias_method :collection_enum_radio_buttons, :collection_radio_buttons
|
67
64
|
alias_method :collection_enum, :collection_select
|
68
|
-
|
69
|
-
end
|
65
|
+
prepend BuilderExtensionWithEnum
|
66
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_string_enum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ermolaev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -64,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
64
|
version: '0'
|
65
65
|
requirements: []
|
66
66
|
rubyforge_project:
|
67
|
-
rubygems_version: 2.
|
67
|
+
rubygems_version: 2.6.11
|
68
68
|
signing_key:
|
69
69
|
specification_version: 4
|
70
70
|
summary: support in rails db enums or string (using as flexible enum)
|