module Sequel::GraphEach

Public Instance Methods

each() { |r| ... } click to toggle source

Call graph_each for graphed datasets that are not being eager graphed.

Calls superclass method
   # File lib/sequel/extensions/graph_each.rb
26 def each
27   if @opts[:graph] && !@opts[:eager_graph]
28     graph_each{|r| yield r}
29   else
30     super
31   end
32 end
with_sql_each(sql) { |r| ... } click to toggle source

Call graph_each for graphed datasets that are not being eager graphed.

Calls superclass method
   # File lib/sequel/extensions/graph_each.rb
35 def with_sql_each(sql)
36   if @opts[:graph] && !@opts[:eager_graph]
37     graph_each(sql){|r| yield r}
38   else
39     super
40   end
41 end

Private Instance Methods

graph_each(sql=select_sql) { |graph| ... } click to toggle source

Fetch the rows, split them into component table parts, tranform and run the row_proc on each part (if applicable), and yield a hash of the parts.

   # File lib/sequel/extensions/graph_each.rb
48 def graph_each(sql=select_sql)
49   # Reject tables with nil datasets, as they are excluded from
50   # the result set
51   datasets = @opts[:graph][:table_aliases].to_a.reject{|ta,ds| ds.nil?}
52   # Get just the list of table aliases into a local variable, for speed
53   table_aliases = datasets.map{|ta,ds| ta}
54   # Get an array of arrays, one for each dataset, with
55   # the necessary information about each dataset, for speed
56   datasets = datasets.map{|ta, ds| [ta, ds, ds.row_proc]}
57   # Use the manually set graph aliases, if any, otherwise
58   # use the ones automatically created by .graph
59   column_aliases = @opts[:graph][:column_aliases]
60   fetch_rows(sql) do |r|
61     graph = {}
62     # Create the sub hashes, one per table
63     table_aliases.each{|ta| graph[ta]={}}
64     # Split the result set based on the column aliases
65     # If there are columns in the result set that are
66     # not in column_aliases, they are ignored
67     column_aliases.each do |col_alias, tc|
68       ta, column = tc
69       graph[ta][column] = r[col_alias]
70     end
71     # For each dataset run the row_proc if applicable
72     datasets.each do |ta,ds,rp|
73       g = graph[ta]
74       graph[ta] = if g.values.any?{|x| !x.nil?}
75         rp ? rp.call(g) : g
76       else
77         nil
78       end
79     end
80 
81     yield graph
82   end
83   self
84 end