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
DEFAULT_STORAGE_VALUE =
proc { [] }

Instance Method Summary collapse

Instance Method Details

#to_nice_union_sql(color = true) ⇒ Object



139
140
141
142
143
# File 'lib/active_record_extended/query_methods/unionize.rb', line 139

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



133
134
135
136
137
# File 'lib/active_record_extended/query_methods/unionize.rb', line 133

def to_union_sql
  return unless union_values?

  apply_union_ordering(build_union_nodes!(false)).to_sql
end

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



112
113
114
115
116
# File 'lib/active_record_extended/query_methods/unionize.rb', line 112

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



124
125
126
127
128
129
130
# File 'lib/active_record_extended/query_methods/unionize.rb', line 124

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



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

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

#unionize_storage!Object



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

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