Class: Cmap::SubqueryExpander

Inherits:
Object
  • Object
show all
Defined in:
lib/cmap/subquery_expander.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ SubqueryExpander

Returns a new instance of SubqueryExpander.



5
6
7
8
# File 'lib/cmap/subquery_expander.rb', line 5

def initialize(args)
  @table_name = args.fetch(:table_name)
  @subquery_gsubs = args.fetch(:subquery_gsubs, [])
end

Instance Attribute Details

#subquery_gsubsObject (readonly)

Returns the value of attribute subquery_gsubs.



3
4
5
# File 'lib/cmap/subquery_expander.rb', line 3

def subquery_gsubs
  @subquery_gsubs
end

#table_nameObject (readonly)

Returns the value of attribute table_name.



3
4
5
# File 'lib/cmap/subquery_expander.rb', line 3

def table_name
  @table_name
end

Instance Method Details

#query(edge) ⇒ Object



14
15
16
17
18
19
# File 'lib/cmap/subquery_expander.rb', line 14

def query(edge)
  r = edge.value
  replacements = [["+table_name+", table_name], ["+destination_vertex+", edge.destination_vertex], ["+origin_vertex+", edge.origin_vertex]]
  (subquery_gsubs + replacements).each {|gsub| r = r.gsub(*gsub)}
  r
end

#update_query?(edge) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/cmap/subquery_expander.rb', line 10

def update_query?(edge)
  edge.value != query(edge)
end