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
25
26
27
|
# File 'app/models/effective/form_logics/show_if.rb', line 25
def input_logic_options
args.third.kind_of?(Hash) ? args.third : {}
end
|
#logic_options ⇒ Object
21
22
23
|
# File 'app/models/effective/form_logics/show_if.rb', line 21
def logic_options
{ name: tag_name(args.first), value: args.second.to_s }.merge(input_logic_options)
end
|
#options ⇒ Object
17
18
19
|
# File 'app/models/effective/form_logics/show_if.rb', line 17
def options
{ style: ('display: none;' unless show?) }
end
|
#show? ⇒ Boolean
33
34
35
|
# File 'app/models/effective/form_logics/show_if.rb', line 33
def show?
(object.send(args.first) == args.second) || (object.send(args.first).to_s == args.second.to_s)
end
|
#to_html(&block) ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
|
# File 'app/models/effective/form_logics/show_if.rb', line 5
def to_html(&block)
disabled_was = @builder.disabled
@builder.disabled = true unless show?
content = content_tag(: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/show_if.rb', line 29
def validate!(args)
raise "expected object to respond to #{args.first}" unless object.respond_to?(args.first)
end
|