Module: ActiveRecord::Properties::ClassMethods

Defined in:
lib/ar_properties.rb

Instance Method Summary collapse

Instance Method Details

#belongs_to(*a, &b) ⇒ Object



29
30
31
32
# File 'lib/ar_properties.rb', line 29

def belongs_to(*a, &b)
  property "#{a.first}_id", :integer
  super
end

#columnsObject



17
18
19
# File 'lib/ar_properties.rb', line 17

def columns
  @columns ||= properties.values.map(&:to_column)
end

#propertiesObject



21
22
23
# File 'lib/ar_properties.rb', line 21

def properties
  @properties ||= {}
end

#property(*args) ⇒ Object



25
26
27
# File 'lib/ar_properties.rb', line 25

def property(*args)
  Property.new(connection, *args).tap {|x| properties[x.name.to_s] = x }
end

#timestamps(suffix = :at) ⇒ Object

Raises:



34
35
36
37
38
# File 'lib/ar_properties.rb', line 34

def timestamps(suffix=:at)
  raise PropertyError, "unknown timestamps suffix: #{suffix.inspect}" unless %w[at on].include?(suffix.to_s)
  property :"created_#{suffix}", :time
  property :"updated_#{suffix}", :time
end