Class: Humble::DatabaseTable
- Inherits:
-
Object
- Object
- Humble::DatabaseTable
- Defined in:
- lib/humble/database_table.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #add_column(name) ⇒ Object
-
#initialize ⇒ DatabaseTable
constructor
A new instance of DatabaseTable.
- #insert(item) ⇒ Object
- #named(name) ⇒ Object
- #primary_key(name, default: 0) ⇒ Object
Constructor Details
#initialize ⇒ DatabaseTable
Returns a new instance of DatabaseTable.
5 6 7 |
# File 'lib/humble/database_table.rb', line 5 def initialize @columns = [] end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/humble/database_table.rb', line 3 def name @name end |
Instance Method Details
#add_column(name) ⇒ Object
17 18 19 |
# File 'lib/humble/database_table.rb', line 17 def add_column(name) @columns << Column.new(:name => name) end |
#insert(item) ⇒ Object
21 22 23 24 25 |
# File 'lib/humble/database_table.rb', line 21 def insert(item) @columns.inject({}) do |result, column| result.merge(column.prepare_insert(item)) end end |
#named(name) ⇒ Object
9 10 11 |
# File 'lib/humble/database_table.rb', line 9 def named(name) @name = name end |