Class: Prequel::Record

Inherits:
Tuple
  • Object
show all
Defined in:
lib/prequel/record.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Tuple

def_field_reader, #field_values, #get_field_value, #initialize, #soft_update_fields

Constructor Details

This class inherits a constructor from Prequel::Tuple

Class Method Details

.column(name, type) ⇒ Object



30
31
32
33
# File 'lib/prequel/record.rb', line 30

def column(name, type)
  relation.def_column(name, type)
  def_field_accessor(name)
end

.def_field_accessor(name) ⇒ Object



19
20
21
22
# File 'lib/prequel/record.rb', line 19

def def_field_accessor(name)
  def_field_reader(name)
  def_field_writer(name)
end

.def_field_writer(name) ⇒ Object



24
25
26
27
28
# File 'lib/prequel/record.rb', line 24

def def_field_writer(name)
  define_method("#{name}=") do |value|
    set_field_value(name, value)
  end
end

.inherited(klass) ⇒ Object



14
15
16
17
# File 'lib/prequel/record.rb', line 14

def inherited(klass)
  table_name = klass.name.demodulize.underscore.pluralize.to_sym
  klass.relation = Relations::Table.new(table_name, klass)
end

.new(field_values = {}) ⇒ Object



35
36
37
# File 'lib/prequel/record.rb', line 35

def new(field_values={})
  Prequel.session[table.name][field_values[:id]] ||= super
end

.tableObject



6
7
8
# File 'lib/prequel/record.rb', line 6

def table
  relation
end

.to_relationObject



10
11
12
# File 'lib/prequel/record.rb', line 10

def to_relation
  relation
end

Instance Method Details

#get_record(table_name) ⇒ Object



46
47
48
# File 'lib/prequel/record.rb', line 46

def get_record(table_name)
  self if table_name == table.name
end

#tableObject



40
41
42
# File 'lib/prequel/record.rb', line 40

def table
  relation
end