Class: ActiveRecord::Bixformer::Attribute::Boolean
- Defined in:
- lib/activerecord-bixformer/attribute/boolean.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
#initialize, #should_be_included
Constructor Details
This class inherits a constructor from ActiveRecord::Bixformer::Attribute::Base
Instance Method Details
#export(record) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/activerecord-bixformer/attribute/boolean.rb', line 5 def export(record) true_value = (@options.is_a?(::Hash) && @options[:true]) || 'true' false_value = (@options.is_a?(::Hash) && @options[:false]) || 'false' record_attribute_value(record).present? ? true_value : false_value end |
#import(value) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/activerecord-bixformer/attribute/boolean.rb', line 12 def import(value) return nil if value.blank? true_value = (@options.is_a?(::Hash) && @options[:true]) || 'true' false_value = (@options.is_a?(::Hash) && @options[:false]) || 'false' case value when true_value true when false_value false else raise ::ActiveRecord::Bixformer::AttributeError.new(self, value) if @options[:raise] end end |