Class: DataMapper::Query::Path

Inherits:
Object
  • Object
show all
Includes:
Assertions
Defined in:
lib/dm-core/query.rb

Overview

class Operator

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Assertions

#assert_kind_of

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object (private)

Raises:

  • (NoMethodError)


610
611
612
613
614
615
616
617
618
619
620
621
622
# File 'lib/dm-core/query.rb', line 610

def method_missing(method, *args)
  if relationship = @model.relationships(@repository.name)[method]
    klass = klass = model == relationship.child_model ? relationship.parent_model : relationship.child_model
    return Query::Path.new(@repository, @relationships + [ relationship ], klass)
  end

  if @model.properties(@repository.name)[method]
    @property = @model.properties(@repository.name)[method] unless @property
    return self
  end

  raise NoMethodError, "undefined property or association `#{method}' on #{@model}"
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



576
577
578
# File 'lib/dm-core/query.rb', line 576

def model
  @model
end

#operatorObject (readonly)

Returns the value of attribute operator.



576
577
578
# File 'lib/dm-core/query.rb', line 576

def operator
  @operator
end

#propertyObject (readonly)

Returns the value of attribute property.



576
577
578
# File 'lib/dm-core/query.rb', line 576

def property
  @property
end

#relationshipsObject (readonly)

Returns the value of attribute relationships.



576
577
578
# File 'lib/dm-core/query.rb', line 576

def relationships
  @relationships
end

Instance Method Details

#field(*args) ⇒ Object

duck type the DM::Query::Path to act like a DM::Property



587
588
589
# File 'lib/dm-core/query.rb', line 587

def field(*args)
  @property ? @property.field(*args) : nil
end

#to_symObject

more duck typing



592
593
594
# File 'lib/dm-core/query.rb', line 592

def to_sym
  @property ? @property.name.to_sym : @model.storage_name(@repository).to_sym
end