Class: Effective::FormLogic
- Inherits:
-
Object
- Object
- Effective::FormLogic
- Defined in:
- app/models/effective/form_logic.rb
Direct Known Subclasses
Effective::FormLogics::HideIf, Effective::FormLogics::ShowIf, Effective::FormLogics::ShowIfAny
Instance Attribute Summary collapse
-
#args ⇒ Object
Returns the value of attribute args.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(*args, builder:) ⇒ FormLogic
constructor
So this takes in the options for an entire form group.
- #input_js_options ⇒ Object
- #input_js_options_method_name ⇒ Object
- #tag_name(name, multiple = false, index = nil) ⇒ Object
- #validate!(args) ⇒ Object
Constructor Details
#initialize(*args, builder:) ⇒ FormLogic
So this takes in the options for an entire form group.
11 12 13 14 15 16 17 18 |
# File 'app/models/effective/form_logic.rb', line 11 def initialize(*args, builder:) @builder = builder @template = builder.template @options ||= {} validate!(args) @args = args end |
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
5 6 7 |
# File 'app/models/effective/form_logic.rb', line 5 def args @args end |
#options ⇒ Object
Returns the value of attribute options.
5 6 7 |
# File 'app/models/effective/form_logic.rb', line 5 def @options end |
Instance Method Details
#input_js_options ⇒ Object
38 39 40 |
# File 'app/models/effective/form_logic.rb', line 38 def { 'data-input-js-options' => JSON.generate({method_name: }.merge!()) } end |
#input_js_options_method_name ⇒ Object
42 43 44 |
# File 'app/models/effective/form_logic.rb', line 42 def "effective_#{self.class.name.split('::').last.underscore}" end |
#tag_name(name, multiple = false, index = nil) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/models/effective/form_logic.rb', line 25 def tag_name(name, multiple = false, index = nil) sanitized_method_name = name.to_s.sub(/\?$/, "") case when @builder.object_name.empty? "#{sanitized_method_name}#{multiple ? "[]" : ""}" when index "#{@builder.object_name}[#{index}][#{sanitized_method_name}]#{multiple ? "[]" : ""}" else "#{@builder.object_name}[#{sanitized_method_name}]#{multiple ? "[]" : ""}" end end |
#validate!(args) ⇒ Object
20 21 22 |
# File 'app/models/effective/form_logic.rb', line 20 def validate!(args) raise 'expected one or more argument' if args.blank? end |