Class: Context
- Inherits:
-
Object
- Object
- Context
- Defined in:
- lib/shipyard/context.rb
Instance Attribute Summary collapse
-
#dataset ⇒ Object
readonly
Returns the value of attribute dataset.
-
#db ⇒ Object
readonly
Returns the value of attribute db.
-
#row ⇒ Object
readonly
Returns the value of attribute row.
-
#table ⇒ Object
readonly
Returns the value of attribute table.
Instance Method Summary collapse
- #columns ⇒ Object
- #columns_with_types ⇒ Object
- #get_binding ⇒ Object
-
#initialize(manifest) ⇒ Context
constructor
A new instance of Context.
- #primary_key ⇒ Object
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
#dataset ⇒ Object (readonly)
Returns the value of attribute dataset.
3 4 5 |
# File 'lib/shipyard/context.rb', line 3 def dataset @dataset end |
#db ⇒ Object (readonly)
Returns the value of attribute db.
3 4 5 |
# File 'lib/shipyard/context.rb', line 3 def db @db end |
#row ⇒ Object (readonly)
Returns the value of attribute row.
3 4 5 |
# File 'lib/shipyard/context.rb', line 3 def row @row end |
#table ⇒ Object (readonly)
Returns the value of attribute table.
3 4 5 |
# File 'lib/shipyard/context.rb', line 3 def table @table end |
Instance Method Details
#columns ⇒ Object
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_types ⇒ Object
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_binding ⇒ Object
24 25 26 |
# File 'lib/shipyard/context.rb', line 24 def get_binding binding end |
#primary_key ⇒ Object
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 |