Class: ActiveAny::Relation::WhereClause
- Inherits:
-
Object
- Object
- ActiveAny::Relation::WhereClause
- Includes:
- Enumerable
- Defined in:
- lib/active_any/relation/where_clause.rb
Defined Under Namespace
Classes: Condition
Instance Attribute Summary collapse
-
#conditions ⇒ Object
readonly
Returns the value of attribute conditions.
Class Method Summary collapse
Instance Method Summary collapse
- #+(other) ⇒ Object (also: #merge)
- #==(other) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(hash = {}, conditions = nil) ⇒ WhereClause
constructor
A new instance of WhereClause.
- #merge!(hash) ⇒ Object
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
#conditions ⇒ Object (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
.empty ⇒ Object
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 |