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



12
13
14
# File 'lib/simple_attribute/attributes/boolean.rb', line 12

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

#invert_classes?Boolean

Returns:



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

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

#render_attributeObject



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

def render_attribute
  'Yes'
end

#render_default_valueObject



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

def render_default_value
  'No'
end

#true_classObject



8
9
10
# File 'lib/simple_attribute/attributes/boolean.rb', line 8

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

#wrapper_htmlObject



16
17
18
19
20
21
# File 'lib/simple_attribute/attributes/boolean.rb', line 16

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

  super.merge(class: classes)
end