Class: Djoini::Relation

Inherits:
Object
  • Object
show all
Includes:
Composable
Defined in:
lib/djoini/relation.rb

Overview

Hold creation of new records(rowsobjects)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Composable

#features, #method_missing, #respond_to_missing?

Constructor Details

#initialize(params) ⇒ Relation

Returns a new instance of Relation.



10
11
12
13
14
15
16
# File 'lib/djoini/relation.rb', line 10

def initialize(params)
  self.table = Table.new(name: params.fetch(:name))

  self.record_class = params.fetch(:record_class)

  features << Crud.new(self)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Djoini::Composable

Instance Attribute Details

#tableObject

Returns the value of attribute table.



18
19
20
# File 'lib/djoini/relation.rb', line 18

def table
  @table
end

Instance Method Details

#attributesObject



20
21
22
# File 'lib/djoini/relation.rb', line 20

def attributes
  table.columns.keys
end

#new_record(values) ⇒ Object



24
25
26
27
28
# File 'lib/djoini/relation.rb', line 24

def new_record(values)
  record_class.new(relation: self,
                   values: values,
                   key: values[table.primary_key])
end