Parent

Files

Class Index [+]

Quicksearch

ActiveRecord::PredicateBuilder

Public Class Methods

new(engine) click to toggle source
   # File lib/active_record/relation/predicate_builder.rb, line 4
4:     def initialize(engine)
5:       @engine = engine
6:     end

Public Instance Methods

build_from_hash(attributes, default_table) click to toggle source
    # File lib/active_record/relation/predicate_builder.rb, line 8
 8:     def build_from_hash(attributes, default_table)
 9:       predicates = attributes.map do |column, value|
10:         table = default_table
11: 
12:         if value.is_a?(Hash)
13:           table = Arel::Table.new(column, :engine => @engine)
14:           build_from_hash(value, table)
15:         else
16:           column = column.to_s
17: 
18:           if column.include?('.')
19:             table_name, column = column.split('.', 2)
20:             table = Arel::Table.new(table_name, :engine => @engine)
21:           end
22: 
23:           attribute = table[column] || Arel::Attribute.new(table, column)
24: 
25:           case value
26:           when Array, ActiveRecord::Associations::AssociationCollection, ActiveRecord::Relation
27:             values = value.to_a
28:             attribute.in(values)
29:           when Range, Arel::Relation
30:             attribute.in(value)
31:           else
32:             attribute.eq(value)
33:           end
34:         end
35:       end
36: 
37:       predicates.flatten
38:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.