Module: MotionRecord::Persistence::ClassMethods

Defined in:
lib/motion_record/persistence.rb

Instance Method Summary collapse

Instance Method Details

#create(attributes = {}) ⇒ Object

Create a new record

attributes - a Hash of attribute values

Returns the created record



74
75
76
77
78
# File 'lib/motion_record/persistence.rb', line 74

def create(attributes={})
  record = self.new(attributes)
  record.save
  record
end

#primary_keyObject

Sybmol name of the primary key column



81
82
83
# File 'lib/motion_record/persistence.rb', line 81

def primary_key
  :id
end

#table_columnsObject



90
91
92
93
94
95
96
97
98
99
100
# File 'lib/motion_record/persistence.rb', line 90

def table_columns
  unless @table_columns
    @table_columns = get_columns_from_schema.each_with_object({}) do |column, hash|
      hash[column.name] = column
    end
    @table_columns.values.each do |column|
      define_attribute_from_column(column)
    end
  end
  @table_columns
end

#table_nameObject



85
86
87
88
# File 'lib/motion_record/persistence.rb', line 85

def table_name
  # HACK: poor-man's .pluralize
  self.to_s.downcase + "s"
end