Class: MotionRecord::Base
Class Method Summary
collapse
Instance Method Summary
collapse
included
#delete!, #mark_persisted!, #mark_unpersisted!, #persisted?, #save!
included
Constructor Details
#initialize(attributes = {}) ⇒ Base
Returns a new instance of Base.
7
8
9
|
# File 'lib/motion_record/base.rb', line 7
def initialize(attributes={})
initialize_from_attribute_hash(attributes)
end
|
Class Method Details
.attribute_defaults ⇒ Object
47
48
49
|
# File 'lib/motion_record/base.rb', line 47
def attribute_defaults
@attribute_defaults ||= {}
end
|
.attribute_names ⇒ Object
43
44
45
|
# File 'lib/motion_record/base.rb', line 43
def attribute_names
@attribute_names ||= []
end
|
.connection ⇒ Object
51
52
53
|
# File 'lib/motion_record/base.rb', line 51
def connection
ConnectionAdapters::SQLiteAdapter.instance
end
|
.define_attribute(name, options = {}) ⇒ Object
Add attribute methods to the model
name - Symobl name of the attribute options - optional configuration Hash:
:default - default value for the attribute (nil otherwise)
35
36
37
38
39
40
41
|
# File 'lib/motion_record/base.rb', line 35
def define_attribute(name, options = {})
attr_accessor name
self.attribute_names << name.to_sym
if options[:default]
self.attribute_defaults[name.to_sym] = options[:default]
end
end
|
Instance Method Details
#connection ⇒ Object
17
18
19
|
# File 'lib/motion_record/base.rb', line 17
def connection
self.class.connection
end
|
#to_attribute_hash ⇒ Object
11
12
13
14
15
|
# File 'lib/motion_record/base.rb', line 11
def to_attribute_hash
self.class.attribute_names.each_with_object({}) do |name, hash|
hash[name] = self.instance_variable_get "@#{name}"
end
end
|