eac_rails_utils 0.1.10 → 0.1.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: 19ccc8fc5f3f8b878422a8327af8faaa61e98075
4
- data.tar.gz: f8081169339acbf890d7a9c981ed561cfacb5474
3
+ metadata.gz: 326ed69f1c2d044f1d4e78a7ffe7457e7a254c13
4
+ data.tar.gz: d4cddf12d6717ad1fa54adde43c69290c73091ac
5
5
  SHA512:
6
- metadata.gz: b43a7c8a372dd670a2ad9ff13c66905859d3f2f367845f65faf52d76a548512c6589946572bc7f1ab3ea86880f4ccb4cc95d5d447f3981e7255c334212ca51eb
7
- data.tar.gz: a28be360f63ca74287b1756263c05f638e76903d636e136547ca55997675a8ae6ca25b1e2cf921107a77ea280f05508e72bb3615637e433c81251440bc4b3c76
6
+ metadata.gz: 3e8dbe272f8c609051fccad0a936b83e99f41e80db9b46fe963a932e3f80ba7b883a2718cb25b981d9b488642ee62ec770c7ce89d36bc8e1030217a314575001
7
+ data.tar.gz: 470884c138fba21d17943de842ce79f43338bfac743e6b021f956c58aa42d23c26dc478a0e3ee6dbb4ad4165d7b675d52baf50e2a08f4b72265279a69403a916
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+ module Eac
3
+ module CommonFormHelper
4
+ class FormBuilder
5
+ module SelectField
6
+ def select_field(field_name, options = {})
7
+ options = options.dup
8
+ field(field_name, options) do
9
+ form.select(field_name, select_options(field_name, options))
10
+ end
11
+ end
12
+
13
+ private
14
+
15
+ def select_options(field_name, options)
16
+ options[:options] || listable_select_options(field_name) || raise('No options found')
17
+ end
18
+
19
+ def listable_select_options(field_name)
20
+ return nil unless model_instance.class.respond_to?(:lists)
21
+ return nil unless model_instance.class.lists.respond_to?(field_name)
22
+ model_instance.class.lists.send(field_name).options
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -8,6 +8,7 @@ module Eac
8
8
  include DateField
9
9
  include RadioSelectField
10
10
  include FieldsFor
11
+ include SelectField
11
12
  include YearMonthField
12
13
 
13
14
  attr_reader :form, :helper, :field_errors_showed
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module EacRailsUtils
3
- VERSION = '0.1.10'
3
+ VERSION = '0.1.11'
4
4
  end
@@ -17,6 +17,7 @@ module EacRailsUtils
17
17
  require 'eac/common_form_helper/form_builder/fields_for'
18
18
  require 'eac/common_form_helper/form_builder/radio_select_field'
19
19
  require 'eac/common_form_helper/form_builder/searchable_association_field'
20
+ require 'eac/common_form_helper/form_builder/select_field'
20
21
  require 'eac/common_form_helper/form_builder/year_month_field'
21
22
  require 'eac/common_form_helper/form_builder'
22
23
  require 'eac/common_form_helper'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eac_rails_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - E.A.C.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-19 00:00:00.000000000 Z
11
+ date: 2018-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel-associations
@@ -147,6 +147,7 @@ files:
147
147
  - lib/eac/common_form_helper/form_builder/fields_for.rb
148
148
  - lib/eac/common_form_helper/form_builder/radio_select_field.rb
149
149
  - lib/eac/common_form_helper/form_builder/searchable_association_field.rb
150
+ - lib/eac/common_form_helper/form_builder/select_field.rb
150
151
  - lib/eac/common_form_helper/form_builder/year_month_field.rb
151
152
  - lib/eac/cpf_validator.rb
152
153
  - lib/eac/formatter_helper.rb