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)


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

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

  path_class = self.class

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

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

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

Instance Attribute Details

#modelObject (readonly)



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

def model
  @model
end

#propertyObject (readonly)



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

def property
  @property
end

#relationshipsObject (readonly)



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

def relationships
  @relationships
end

#repository_nameObject (readonly)



23
24
25
# File 'lib/dm-core/query/path.rb', line 23

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.



57
58
59
# File 'lib/dm-core/query/path.rb', line 57

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.



65
66
67
# File 'lib/dm-core/query/path.rb', line 65

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

#instance_of?(klass) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#kind_of?(klass) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/dm-core/query/path.rb', line 44

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

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

Returns:

  • (Boolean)


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

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