Class: Effective::FormLogics::ShowIf
Instance Attribute Summary
#args
Instance Method Summary
collapse
#initialize, #input_js_options, #input_js_options_method_name, #tag_name
Instance Method Details
#logic_options ⇒ Object
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
|
#options ⇒ Object
9
10
11
|
# File 'app/models/effective/form_logics/show_if.rb', line 9
def options
{ style: ('display: none;' unless show?) }
end
|
#show? ⇒ 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)
content_tag(: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
|