Class: Squealer::Target

Inherits:
Object show all
Defined in:
lib/squealer/target.rb

Defined Under Namespace

Classes: BlockRequired, Queue

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(database_connection, table_name, &block) ⇒ Target

Returns a new instance of Target.

Raises:



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

.currentObject



9
10
11
# File 'lib/squealer/target.rb', line 9

def self.current
  Queue.instance.current
end

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

#sqlObject



30
31
32
# File 'lib/squealer/target.rb', line 30

def sql
  @sql
end