Module: EventAttribute::ClassMethods

Defined in:
lib/event_attribute.rb

Instance Method Summary collapse

Instance Method Details

#event_attribute(column, options = {}) ⇒ Object

Configuration options

  • attribute - name of the attribute that will be created in the model that returns true/false (default: column name minus ‘_at’ or ‘_on’)

  • nil_equals - whether or not the attribute should return true or false if the column is nil (default: false)



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/event_attribute.rb', line 61

def event_attribute(column, options = {})
  unless respond_to?(:event_attribute_attrs)
    class_attribute :event_attributes
    class_attribute :event_attribute_attrs
    self.event_attributes, self.event_attribute_attrs = {}, {}
  end
  
  attribute = (options[:attribute] || (column.to_s =~ /_at|_on/ ? column.to_s[0...-3] : raise("Unable to create default attribute name"))).to_sym
  
  nil_equals = options[:nil_equals] || false
  
  self.event_attribute_attrs[attribute] = column
  self.event_attributes[column] = nil_equals
  
  create_attribute_accessors(attribute, column, nil_equals)
end