Class: DefaultingRowSet

Inherits:
Object
  • Object
show all
Defined in:
lib/dbexpect/defaulting_row_set.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDefaultingRowSet

Returns a new instance of DefaultingRowSet.



23
24
25
26
27
28
# File 'lib/dbexpect/defaulting_row_set.rb', line 23

def initialize
  @defaults = Hash.new
  @rows = []

  @columns_in_order = []
end

Instance Attribute Details

#columns_in_orderObject

Returns the value of attribute columns_in_order.



20
21
22
# File 'lib/dbexpect/defaulting_row_set.rb', line 20

def columns_in_order
  @columns_in_order
end

#defaultsObject

Returns the value of attribute defaults.



19
20
21
# File 'lib/dbexpect/defaulting_row_set.rb', line 19

def defaults
  @defaults
end

#rowsObject

Returns the value of attribute rows.



21
22
23
# File 'lib/dbexpect/defaulting_row_set.rb', line 21

def rows
  @rows
end

Instance Method Details

#add_row(column_values) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/dbexpect/defaulting_row_set.rb', line 35

def add_row(column_values)
  column_values.keys.map {|col| add_column(col) }

  defaulted_row = set_defaults_at_time_of_addition(column_values)
  @rows << Row.new(defaulted_row,@columns_in_order & defaulted_row.keys)
  @rows.last
end

#empty?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/dbexpect/defaulting_row_set.rb', line 53

def empty?
  @rows.empty?
end

#insert_statements(schema, name) ⇒ Object



43
44
45
46
47
# File 'lib/dbexpect/defaulting_row_set.rb', line 43

def insert_statements(schema,name)
  @rows.collect do |row|
    row.insert_stmt(schema,name)
  end
end

#set_default(column, value) ⇒ Object



30
31
32
33
# File 'lib/dbexpect/defaulting_row_set.rb', line 30

def set_default(column,value)
  add_column(column)
  @defaults[column] = value
end

#where_clausesObject



49
50
51
# File 'lib/dbexpect/defaulting_row_set.rb', line 49

def where_clauses
  @rows.map(&:where_clause)
end