Class: TwoWaySQL::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/twowaysql/node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Context

Returns a new instance of Context.



5
6
7
8
9
10
# File 'lib/twowaysql/node.rb', line 5

def initialize(data)
  @data = data
  @enabled = true
  @bound_variables = []
  @sql_fragments = []
end

Instance Attribute Details

#bound_variablesObject (readonly)

Returns the value of attribute bound_variables.



11
12
13
# File 'lib/twowaysql/node.rb', line 11

def bound_variables
  @bound_variables
end

#dataObject (readonly)

Returns the value of attribute data.



13
14
15
# File 'lib/twowaysql/node.rb', line 13

def data
  @data
end

#sql_fragmentsObject (readonly)

Returns the value of attribute sql_fragments.



12
13
14
# File 'lib/twowaysql/node.rb', line 12

def sql_fragments
  @sql_fragments
end

Instance Method Details

#add_sql(sql_fragment) ⇒ Object



30
31
32
# File 'lib/twowaysql/node.rb', line 30

def add_sql(sql_fragment)
  @sql_fragments << sql_fragment
end

#add_value(value) ⇒ Object



34
35
36
37
# File 'lib/twowaysql/node.rb', line 34

def add_value(value)
  @sql_fragments << '?'
  @bound_variables << value
end

#add_values(values) ⇒ Object



39
40
41
42
# File 'lib/twowaysql/node.rb', line 39

def add_values(values)
  @sql_fragments << Array.new(values.size, '?').join(', ')
  @bound_variables.concat(values)
end

#enable!Object



48
49
50
# File 'lib/twowaysql/node.rb', line 48

def enable!
  @enabled = true
end

#enabled?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/twowaysql/node.rb', line 44

def enabled?
  @enabled
end

#fork_childObject



19
20
21
22
23
# File 'lib/twowaysql/node.rb', line 19

def fork_child
  child = Context.new(@data)
  child.disable!
  child
end

#join_child(child_ctx) ⇒ Object



25
26
27
28
# File 'lib/twowaysql/node.rb', line 25

def join_child(child_ctx)
  @sql_fragments.concat(child_ctx.sql_fragments)
  @bound_variables.concat(child_ctx.bound_variables)
end

#sql(separator = "") ⇒ Object



15
16
17
# File 'lib/twowaysql/node.rb', line 15

def sql(separator="")
  @sql_fragments.join(separator)
end