Class: Squealer::Target
Defined Under Namespace
Classes: BlockRequired, Queue
Class Method Summary collapse
Instance Method Summary collapse
- #assign(column_name, &block) ⇒ Object
-
#initialize(database_connection, table_name, &block) ⇒ Target
constructor
A new instance of Target.
- #sql ⇒ Object
Constructor Details
#initialize(database_connection, table_name, &block) ⇒ Target
Returns a new instance of Target.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/squealer/target.rb', line 13 def initialize(database_connection, table_name, &block) raise BlockRequired, "Block must be given to target (otherwise, there's no work to do)" unless block_given? raise ArgumentError, "Table name must be supplied" if table_name.to_s.strip.empty? @dbc = database_connection @table_name = table_name.to_s @binding = block.binding verify_table_name_in_scope @row_id = infer_row_id @column_names = [] @column_values = [] @sql = '' target(&block) end |
Class Method Details
Instance Method Details
#assign(column_name, &block) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/squealer/target.rb', line 34 def assign(column_name, &block) @column_names << column_name if block_given? @column_values << yield else @column_values << infer_value(column_name, @binding) end end |
#sql ⇒ Object
30 31 32 |
# File 'lib/squealer/target.rb', line 30 def sql @sql end |