Class: DataMapper::Query::Path

Inherits:
Object
  • Object
show all
Includes:
Assertions
Defined in:
lib/gems/dm-core-0.9.9/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)


661
662
663
664
665
666
667
668
669
670
671
672
673
# File 'lib/gems/dm-core-0.9.9/lib/dm-core/query.rb', line 661

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.



627
628
629
# File 'lib/gems/dm-core-0.9.9/lib/dm-core/query.rb', line 627

def model
  @model
end

#operatorObject (readonly)

Returns the value of attribute operator.



627
628
629
# File 'lib/gems/dm-core-0.9.9/lib/dm-core/query.rb', line 627

def operator
  @operator
end

#propertyObject (readonly)

Returns the value of attribute property.



627
628
629
# File 'lib/gems/dm-core-0.9.9/lib/dm-core/query.rb', line 627

def property
  @property
end

#relationshipsObject (readonly)

Returns the value of attribute relationships.



627
628
629
# File 'lib/gems/dm-core-0.9.9/lib/dm-core/query.rb', line 627

def relationships
  @relationships
end

Instance Method Details

#field(*args) ⇒ Object

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



638
639
640
# File 'lib/gems/dm-core-0.9.9/lib/dm-core/query.rb', line 638

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

#to_symObject

more duck typing



643
644
645
# File 'lib/gems/dm-core-0.9.9/lib/dm-core/query.rb', line 643

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