Class: Context

Inherits:
Object
  • Object
show all
Defined in:
lib/shipyard/context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(manifest) ⇒ Context

Returns a new instance of Context.



5
6
7
8
9
10
# File 'lib/shipyard/context.rb', line 5

def initialize(manifest)
  @db = manifest.database
  @table = manifest.table
  @row = manifest.row
  @dataset = @db[manifest.table]
end

Instance Attribute Details

#datasetObject (readonly)

Returns the value of attribute dataset.



3
4
5
# File 'lib/shipyard/context.rb', line 3

def dataset
  @dataset
end

#dbObject (readonly)

Returns the value of attribute db.



3
4
5
# File 'lib/shipyard/context.rb', line 3

def db
  @db
end

#rowObject (readonly)

Returns the value of attribute row.



3
4
5
# File 'lib/shipyard/context.rb', line 3

def row
  @row
end

#tableObject (readonly)

Returns the value of attribute table.



3
4
5
# File 'lib/shipyard/context.rb', line 3

def table
  @table
end

Instance Method Details

#columnsObject



12
13
14
# File 'lib/shipyard/context.rb', line 12

def columns
  @db.schema(@table.to_sym).map { |arr| arr[0].to_s }
end

#columns_with_typesObject



16
17
18
# File 'lib/shipyard/context.rb', line 16

def columns_with_types
  @db.schema(@table.to_sym).inject({}) { |r, v| r[v[0].to_s] = v[1][:type]; r }
end

#get_bindingObject



24
25
26
# File 'lib/shipyard/context.rb', line 24

def get_binding
  binding
end

#primary_keyObject



20
21
22
# File 'lib/shipyard/context.rb', line 20

def primary_key
  @db.schema(@table.to_sym).select { |col_arr| col_arr[1][:primary_key] == true }.map { |col_arr| col_arr[0].to_s }.first
end