Class: SimpleAttribute::Attributes::Boolean

Inherits:
Base
  • Object
show all
Defined in:
lib/simple_attribute/attributes/boolean.rb

Instance Attribute Summary

Attributes inherited from Base

#attribute, #options, #record, #value

Instance Method Summary collapse

Methods inherited from Base

#attribute_name, #default_value, #defaults, #html_options, #initialize, #label_method, #method_missing, #render, #render_with_default, #render_wrapper, #renderer_name, #value?, #wrapper, #wrapper?

Constructor Details

This class inherits a constructor from SimpleAttribute::Attributes::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class SimpleAttribute::Attributes::Base

Instance Method Details

#false_classObject

False class



15
16
17
# File 'lib/simple_attribute/attributes/boolean.rb', line 15

def false_class
  invert_classes? ? options[:true] : options[:false]
end

#invert_classes?Boolean

Invert classes

Returns:



5
6
7
# File 'lib/simple_attribute/attributes/boolean.rb', line 5

def invert_classes?
  options[:invert] == true
end

#render_attributeObject

Render attribute



33
34
35
# File 'lib/simple_attribute/attributes/boolean.rb', line 33

def render_attribute
  'Yes'
end

#render_default_valueObject

Render default attribute



28
29
30
# File 'lib/simple_attribute/attributes/boolean.rb', line 28

def render_default_value
  'No'
end

#true_classObject

True class



10
11
12
# File 'lib/simple_attribute/attributes/boolean.rb', line 10

def true_class
  invert_classes? ? options[:false] : options[:true]
end

#wrapper_htmlObject

Wrapper html



20
21
22
23
24
25
# File 'lib/simple_attribute/attributes/boolean.rb', line 20

def wrapper_html
  classes = value? ? true_class : false_class
  classes = "#{super[:class]} #{classes}".strip

  super.merge(class: classes)
end