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.
9 10 11 12 13 14 15 16 |
# File 'app/models/effective/form_logic.rb', line 9 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.
3 4 5 |
# File 'app/models/effective/form_logic.rb', line 3 def args @args end |
#options ⇒ Object
Returns the value of attribute options.
3 4 5 |
# File 'app/models/effective/form_logic.rb', line 3 def @options end |
Instance Method Details
#input_js_options ⇒ Object
36 37 38 |
# File 'app/models/effective/form_logic.rb', line 36 def { 'data-input-js-options' => JSON.generate({method_name: }.merge!()) } end |
#input_js_options_method_name ⇒ Object
40 41 42 |
# File 'app/models/effective/form_logic.rb', line 40 def "effective_#{self.class.name.split('::').last.underscore}" end |
#tag_name(name, multiple = false, index = nil) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/models/effective/form_logic.rb', line 23 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
18 19 20 |
# File 'app/models/effective/form_logic.rb', line 18 def validate!(args) raise 'expected one or more argument' if args.blank? end |