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, line 26 def each if @opts[:graph] && !@opts[:eager_graph] graph_each{|r| yield r} else super end 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, line 35 def with_sql_each(sql) if @opts[:graph] && !@opts[:eager_graph] graph_each(sql){|r| yield r} else super end 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, line 48 def graph_each(sql=select_sql) # Reject tables with nil datasets, as they are excluded from # the result set datasets = @opts[:graph][:table_aliases].to_a.reject{|ta,ds| ds.nil?} # Get just the list of table aliases into a local variable, for speed table_aliases = datasets.collect{|ta,ds| ta} # Get an array of arrays, one for each dataset, with # the necessary information about each dataset, for speed datasets = datasets.collect{|ta, ds| [ta, ds, ds.row_proc]} # Use the manually set graph aliases, if any, otherwise # use the ones automatically created by .graph column_aliases = @opts[:graph_aliases] || @opts[:graph][:column_aliases] fetch_rows(sql) do |r| graph = {} # Create the sub hashes, one per table table_aliases.each{|ta| graph[ta]={}} # Split the result set based on the column aliases # If there are columns in the result set that are # not in column_aliases, they are ignored column_aliases.each do |col_alias, tc| ta, column = tc graph[ta][column] = r[col_alias] end # For each dataset run the row_proc if applicable datasets.each do |ta,ds,rp| g = graph[ta] graph[ta] = if g.values.any?{|x| !x.nil?} rp ? rp.call(g) : g else nil end end yield graph end self end