Module: ActiveHouse::Chainable

Extended by:
ActiveSupport::Concern
Includes:
ArrayJoinable, Fromable, Groupable, Havingable, Limitable, Orderable, Selectable, Unionable, Whereable
Included in:
Query
Defined in:
lib/active_house/chainable.rb

Instance Method Summary collapse

Methods included from ArrayJoinable

#array_join

Methods included from Unionable

#except_union, #union, #union_for, #update_union

Methods included from Limitable

#limit

Methods included from Havingable

#having

Methods included from Groupable

#group_by

Methods included from Orderable

#order_by

Methods included from Whereable

#where

Methods included from Fromable

#from

Methods included from Selectable

#select

Instance Method Details

#chain_defaultsObject

key - instance variable name that which store values value - default value for the variable



113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/active_house/chainable.rb', line 113

def chain_defaults
  {
      fields: [],
      conditions: [],
      grouping: [],
      ordering: [],
      limit: { offset: nil, limit: nil },
      having: [],
      union: {},
      subquery: nil,
      array_joins: []
  }
end

#chain_methodsObject

key - chain method name value - instance variable name that which store values



97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/active_house/chainable.rb', line 97

def chain_methods
  {
      select: :fields,
      where: :conditions,
      group_by: :grouping,
      order_by: :ordering,
      limit: :limit,
      having: :having,
      union: :unions,
      from: :subquery,
      array_join: :array_joins
  }
end

#dupObject Also known as: clone



145
146
147
# File 'lib/active_house/chainable.rb', line 145

def dup
  chain_query
end

#except(*values) ⇒ Object

Raises:

  • (ArgumentError)


127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/active_house/chainable.rb', line 127

def except(*values)
  raise ArgumentError, 'wrong number of arguments' if values.empty?
  not_allowed = values - chain_methods.keys
  unless not_allowed.empty?
    raise ArgumentError, "Values #{not_allowed} are not allowed, allowed only #{chain_methods.keys}."
  end

  new_data = {}
  chain_methods.each do |meth, var|
    new_data[var] = chain_defaults[var].dup if values.include?(meth)
  end
  chain_query(new_data)
end

#initializeObject



90
91
92
93
# File 'lib/active_house/chainable.rb', line 90

def initialize(*)
  @_with_current_query = false
  super
end

#to_queryObject



141
142
143
# File 'lib/active_house/chainable.rb', line 141

def to_query
  build_query
end