module ModelX::Boolean::ClassMethods
Public Instance Methods
boolean(*attributes)
click to toggle source
# File lib/model_x/boolean.rb, line 36 def boolean(*attributes) attributes.each do |attribute| # An attribute must already exist. unless instance_methods.include?(:"#{attribute}=") raise ArgumentError, "cannot add boolean attribute #{attribute} - no existing attribute exists" end # Override the writer and add a ? version. class_eval <<-RUBY, __FILE__, __LINE__+1 def #{attribute}_with_model_x_boolean=(value) self.#{attribute}_without_model_x_boolean = ModelX::Boolean.convert(value) end alias_method_chain :#{attribute}=, :model_x_boolean alias_method :#{attribute}?, :#{attribute} RUBY end end