Class: DataMapper::Query::Path

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Equalizer

equalize

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)


98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/dm-core/query/path.rb', line 98

private def method_missing(method, *args)
  return @property.send(method, *args) if @property

  path_class = self.class

  if (relationship = @model.relationships(@repository_name)[method])
    return path_class.new(@relationships.dup << relationship)
  end

  return path_class.new(@relationships, method) if @model.properties(@repository_name).named?(method)

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

Instance Attribute Details

#modelObject (readonly)



32
33
34
# File 'lib/dm-core/query/path.rb', line 32

def model
  @model
end

#propertyObject (readonly)



35
36
37
# File 'lib/dm-core/query/path.rb', line 35

def property
  @property
end

#relationshipsObject (readonly)



29
30
31
# File 'lib/dm-core/query/path.rb', line 29

def relationships
  @relationships
end

#repository_nameObject (readonly)



26
27
28
# File 'lib/dm-core/query/path.rb', line 26

def repository_name
  @repository_name
end

Instance Method Details

#ascObject

Used for creating :order options. This technique may be deprecated, so marking as semipublic until the issue is resolved.



62
63
64
# File 'lib/dm-core/query/path.rb', line 62

def asc
  Operator.new(property, :asc)
end

#descObject

Used for creating :order options. This technique may be deprecated, so marking as semipublic until the issue is resolved.



70
71
72
# File 'lib/dm-core/query/path.rb', line 70

def desc
  Operator.new(property, :desc)
end

#instance_of?(klass) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/dm-core/query/path.rb', line 54

def instance_of?(klass)
  super || (defined?(@property) ? @property.instance_of?(klass) : false)
end

#kind_of?(klass) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/dm-core/query/path.rb', line 49

def kind_of?(klass)
  super || (defined?(@property) ? @property.is_a?(klass) : false)
end

#respond_to?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


75
76
77
78
79
80
# File 'lib/dm-core/query/path.rb', line 75

def respond_to?(method, include_private = false)
  super ||
    (defined?(@property) && @property.respond_to?(method, include_private)) ||
    @model.relationships(@repository_name).named?(method)                   ||
    @model.properties(@repository_name).named?(method)
end