Class: Effective::FormLogics::HideIf

Inherits:
Effective::FormLogic show all
Defined in:
app/models/effective/form_logics/hide_if.rb

Instance Attribute Summary

Attributes inherited from Effective::FormLogic

#args

Instance Method Summary collapse

Methods inherited from Effective::FormLogic

#initialize, #input_js_options, #input_js_options_method_name, #tag_name

Constructor Details

This class inherits a constructor from Effective::FormLogic

Instance Method Details

#hide?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'app/models/effective/form_logics/hide_if.rb', line 33

def hide?
  (object.send(args.first) == args.second) || (object.send(args.first).to_s == args.second.to_s)
end

#input_logic_optionsObject



25
26
27
# File 'app/models/effective/form_logics/hide_if.rb', line 25

def input_logic_options
  args.third.kind_of?(Hash) ? args.third : {}
end

#logic_optionsObject



21
22
23
# File 'app/models/effective/form_logics/hide_if.rb', line 21

def logic_options
  { name: tag_name(args.first), value: args.second.to_s }.merge(input_logic_options)
end

#optionsObject



17
18
19
# File 'app/models/effective/form_logics/hide_if.rb', line 17

def options
  { style: ('display: none;' if hide?) }
end

#to_html(&block) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'app/models/effective/form_logics/hide_if.rb', line 5

def to_html(&block)
  disabled_was = @builder.disabled

  @builder.disabled = true if hide?

  content = (:div, options.merge(input_js_options), &block)

  @builder.disabled = disabled_was

  content
end

#validate!(args) ⇒ Object



29
30
31
# File 'app/models/effective/form_logics/hide_if.rb', line 29

def validate!(args)
  raise "expected object to respond to #{args.first}" unless object.respond_to?(args.first)
end