Module: Architect4r::Model::Properties::ClassMethods

Defined in:
lib/architect4r/model/properties.rb

Instance Method Summary collapse

Instance Method Details

#property(name, options = {}) ⇒ Object

Allow setting properties



82
83
84
85
86
# File 'lib/architect4r/model/properties.rb', line 82

def property(name, options = {})
  unless self.properties.keys.find { |p| p == name.to_s }
    define_property(name, options)
  end
end

#timestamps!Object



88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/architect4r/model/properties.rb', line 88

def timestamps!
  property(:updated_at, :cast_to => DateTime)
  property(:created_at, :cast_to => DateTime)
  
  set_callback :create, :before do |object|
    write_attribute('created_at', DateTime.now)
  end
  
  set_callback :save, :before do |object|
    write_attribute('updated_at', DateTime.now)
  end
end