Class: Effective::FormLogics::ShowIf

Inherits:
Effective::FormLogic show all
Defined in:
app/models/effective/form_logics/show_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

#logic_optionsObject



13
14
15
# File 'app/models/effective/form_logics/show_if.rb', line 13

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

#optionsObject



9
10
11
# File 'app/models/effective/form_logics/show_if.rb', line 9

def options
  { style: ('display: none;' unless show?) }
end

#show?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'app/models/effective/form_logics/show_if.rb', line 22

def show?
  object.send(args.first) == args.second
end

#to_html(&block) ⇒ Object



5
6
7
# File 'app/models/effective/form_logics/show_if.rb', line 5

def to_html(&block)
  (:div, options.merge(input_js_options), &block)
end

#validate!(args) ⇒ Object



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

def validate!(args)
  raise 'expected two arguments' unless args.length == 2
  raise "expected object to respond to #{args.first}" unless object.respond_to?(args.first)
end