Class: DataMapper::Query::Path

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


613
614
615
616
617
618
619
620
621
622
623
624
625
# File 'lib/gems/dm-core-0.9.7/lib/dm-core/query.rb', line 613

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.



579
580
581
# File 'lib/gems/dm-core-0.9.7/lib/dm-core/query.rb', line 579

def model
  @model
end

#operatorObject (readonly)

Returns the value of attribute operator.



579
580
581
# File 'lib/gems/dm-core-0.9.7/lib/dm-core/query.rb', line 579

def operator
  @operator
end

#propertyObject (readonly)

Returns the value of attribute property.



579
580
581
# File 'lib/gems/dm-core-0.9.7/lib/dm-core/query.rb', line 579

def property
  @property
end

#relationshipsObject (readonly)

Returns the value of attribute relationships.



579
580
581
# File 'lib/gems/dm-core-0.9.7/lib/dm-core/query.rb', line 579

def relationships
  @relationships
end

Instance Method Details

#field(*args) ⇒ Object

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



590
591
592
# File 'lib/gems/dm-core-0.9.7/lib/dm-core/query.rb', line 590

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

#to_symObject

more duck typing



595
596
597
# File 'lib/gems/dm-core-0.9.7/lib/dm-core/query.rb', line 595

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