Module: ActiveRecordExtended::QueryMethods::Unionize

Defined in:
lib/active_record_extended/query_methods/unionize.rb

Defined Under Namespace

Classes: UnionChain

Constant Summary collapse

UNION_RELATION_METHODS =
[:order_union, :reorder_union, :union_as].freeze
UNIONIZE_METHODS =
[:union, :union_all, :union_except, :union_intersect].freeze

Instance Method Summary collapse

Instance Method Details

#to_nice_union_sql(color = true) ⇒ Object



136
137
138
139
140
# File 'lib/active_record_extended/query_methods/unionize.rb', line 136

def to_nice_union_sql(color = true)
  return to_union_sql unless defined?(::Niceql)

  ::Niceql::Prettifier.prettify_sql(to_union_sql, color)
end

#to_union_sqlObject

Will construct Just the union SQL statement that was been built thus far



130
131
132
133
134
# File 'lib/active_record_extended/query_methods/unionize.rb', line 130

def to_union_sql
  return unless union_values?

  apply_union_ordering(build_union_nodes!(false)).to_sql
end

#union(opts = :chain, *args) ⇒ Object



109
110
111
112
113
# File 'lib/active_record_extended/query_methods/unionize.rb', line 109

def union(opts = :chain, *args)
  return UnionChain.new(spawn) if :chain == opts

  opts.nil? ? self : spawn.union!(opts, *args, chain_method: __callee__)
end

#union!(opts = :chain, *args, chain_method: :union) ⇒ Object



121
122
123
124
125
126
127
# File 'lib/active_record_extended/query_methods/unionize.rb', line 121

def union!(opts = :chain, *args, chain_method: :union)
  union_chain    = UnionChain.new(self)
  chain_method ||= :union
  return union_chain if :chain == opts

  union_chain.public_send(chain_method, *([opts] + args))
end

#unionize_storageObject



75
76
77
# File 'lib/active_record_extended/query_methods/unionize.rb', line 75

def unionize_storage
  @values.fetch(:unionize, {})
end

#unionize_storage!Object



79
80
81
82
83
84
85
86
# File 'lib/active_record_extended/query_methods/unionize.rb', line 79

def unionize_storage!
  @values[:unionize] ||= {
    union_values:          [],
    union_operations:      [],
    union_ordering_values: [],
    unionized_name:        nil
  }
end