Class: Squeel::Adapters::ActiveRecord::Context
- Defined in:
- lib/squeel/adapters/active_record/context.rb,
lib/squeel/adapters/active_record/3.0/context.rb
Constant Summary collapse
- JoinPart =
Because the AR::Associations namespace is insane
::ActiveRecord::Associations::JoinDependency::JoinPart
- JoinBase =
Because the AR::Associations namespace is insane
::ActiveRecord::Associations::ClassMethods::JoinDependency::JoinBase
Instance Attribute Summary
Attributes inherited from Context
Instance Method Summary collapse
- #find(object, parent = @base) ⇒ Object
-
#initialize(object) ⇒ Context
constructor
A new instance of Context.
- #sanitize_sql(conditions, parent) ⇒ Object
- #traverse(keypath, parent = @base, include_endpoint = false) ⇒ Object
Methods inherited from Context
Constructor Details
#initialize(object) ⇒ Context
Returns a new instance of Context.
10 11 12 13 |
# File 'lib/squeel/adapters/active_record/context.rb', line 10 def initialize(object) @base = object.join_base super end |
Instance Method Details
#find(object, parent = @base) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/squeel/adapters/active_record/context.rb', line 15 def find(object, parent = @base) if JoinPart === parent object = object.to_sym if String === object case object when Symbol, Nodes::Stub @object.join_associations.detect { |j| j.reflection.name == object.to_sym && j.parent == parent } when Nodes::Join @object.join_associations.detect { |j| j.reflection.name == object.name && j.parent == parent && (object.polymorphic? ? j.reflection.klass == object.klass : true) } else @object.join_associations.detect { |j| j.reflection == object && j.parent == parent } end end end |
#sanitize_sql(conditions, parent) ⇒ Object
46 47 48 |
# File 'lib/squeel/adapters/active_record/context.rb', line 46 def sanitize_sql(conditions, parent) parent.active_record.send(:sanitize_sql, conditions, parent.aliased_table_name) end |
#traverse(keypath, parent = @base, include_endpoint = false) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/squeel/adapters/active_record/context.rb', line 36 def traverse(keypath, parent = @base, include_endpoint = false) parent = @base if keypath.absolute? keypath.path.each do |key| parent = find(key, parent) || key end parent = find(keypath.endpoint, parent) if include_endpoint parent end |