Class: ActiveAny::Relation::WhereClause

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/active_any/relation/where_clause.rb

Defined Under Namespace

Classes: Condition

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}, conditions = nil) ⇒ WhereClause

Returns a new instance of WhereClause.



44
45
46
# File 'lib/active_any/relation/where_clause.rb', line 44

def initialize(hash = {}, conditions = nil)
  @conditions = conditions ? conditions : hash.map { |key, value| Condition.new(key, value) }
end

Instance Attribute Details

#conditionsObject (readonly)

Returns the value of attribute conditions.



42
43
44
# File 'lib/active_any/relation/where_clause.rb', line 42

def conditions
  @conditions
end

Class Method Details

.emptyObject



48
49
50
# File 'lib/active_any/relation/where_clause.rb', line 48

def self.empty
  new
end

Instance Method Details

#+(other) ⇒ Object Also known as: merge



56
57
58
# File 'lib/active_any/relation/where_clause.rb', line 56

def +(other)
  WhereClause.new({}, (conditions + other.conditions).flatten)
end

#==(other) ⇒ Object



52
53
54
# File 'lib/active_any/relation/where_clause.rb', line 52

def ==(other)
  other.conditions.sort_by(&:key) == conditions.sort_by(&:key)
end

#each(&block) ⇒ Object



70
71
72
# File 'lib/active_any/relation/where_clause.rb', line 70

def each(&block)
  conditions.each(&block)
end

#merge!(hash) ⇒ Object



62
63
64
65
66
# File 'lib/active_any/relation/where_clause.rb', line 62

def merge!(hash)
  hash.each do |key, value|
    conditions << Condition.new(key, value)
  end
end