Class: DataMapper::Query::Path
- Object
- DataMapper::Query::Path
Attributes
Instance Attributes
| model | [RW] | public |
Returns the value of attribute model. |
|---|---|---|---|
| operator | [RW] | public |
Returns the value of attribute operator. |
| property | [RW] | public |
Returns the value of attribute property. |
| relationships | [RW] | public |
Returns the value of attribute relationships. |
Constructor Summary
public
initialize(repository, relationships, model, property_name = nil)
[View source]
56 57 58 59 60 61 62 63 64 65 66
# File 'dm-core/lib/dm-core/query.rb', line 56 def initialize(repository, relationships, model, property_name = nil) raise ArgumentError, "+repository+ is not a Repository, but was #{repository.class}", caller unless Repository === repository raise ArgumentError, "+relationships+ is not an Array, it is a #{relationships.class}", caller unless Array === relationships raise ArgumentError, "+model+ is not a DM::Resource, it is a #{model}", caller unless model.ancestors.include?(DataMapper::Resource) raise ArgumentError, "+property_name+ is not a Symbol, it is a #{property_name.class}", caller unless Symbol === property_name || property_name.nil? @repository = repository @relationships = relationships @model = model @property = @model.properties(@repository.name)[property_name] if property_name end
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
public
method_missing(method, *args)
[View source]
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
# File 'dm-core/lib/dm-core/query.rb', line 79 def method_missing(method, *args) if relationship = @model.relationships(@repository.name)[method] clazz = if @model == relationship.child_model relationship.parent_model else relationship.child_model end relations = [] relations.concat(@relationships) relations << relationship #@model.relationships[method] return Query::Path.new(@repository, relations,clazz) end if @model.properties(@model.repository.name)[method] @property = @model.properties(@model.repository.name)[method] return self end raise NoMethodError, "undefined property or association `#{method}' on #{@model}" end
Public Visibility
Public Instance Method Summary
| #field(*args) |
duck type the DM::Query::Path to act like a DM::Property. |
|---|
Public Instance Methods Inherited from Object
Public Instance Method Details
field
public
field(*args)
duck type the DM::Query::Path to act like a DM::Property
[View source]
100 101 102
# File 'dm-core/lib/dm-core/query.rb', line 100 def field(*args) @property ? @property.field(*args) : nil end