Class: Satis::Switch::Component

Inherits:
ApplicationComponent show all
Defined in:
app/components/satis/switch/component.rb

Instance Attribute Summary collapse

Attributes inherited from ApplicationComponent

#original_view_context

Instance Method Summary collapse

Methods inherited from ApplicationComponent

add_helper, #component_name

Constructor Details

#initialize(form:, attribute:, **options, &block) ⇒ Component

Returns a new instance of Component.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/components/satis/switch/component.rb', line 8

def initialize(form:, attribute:, **options, &block)
  super

  @form = form
  @attribute = attribute
  @options = options
  @block = block
  @icon = true
  @icon = options[:icon] if options.key?(:icon)
  @value = options.key?(:value) ? options[:value] : @form.object.send(attribute)
  @value = @value == '0' || !@value ? false : true
  options[:input_html] ||= {}
  options[:input_html] = { data: { 'satis-switch-target' => 'hiddenInput' } }.deep_merge(options[:input_html])
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



6
7
8
# File 'app/components/satis/switch/component.rb', line 6

def attribute
  @attribute
end

#formObject (readonly)

Returns the value of attribute form.



6
7
8
# File 'app/components/satis/switch/component.rb', line 6

def form
  @form
end

#iconObject (readonly)

Returns the value of attribute icon.



6
7
8
# File 'app/components/satis/switch/component.rb', line 6

def icon
  @icon
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'app/components/satis/switch/component.rb', line 6

def options
  @options
end

#urlObject (readonly)

Returns the value of attribute url.



6
7
8
# File 'app/components/satis/switch/component.rb', line 6

def url
  @url
end