Class: DataMapper::Query::Path

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Equalizer

equalize

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

TODO: document

Raises:

  • (NoMethodError)


85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/dm-core/query/path.rb', line 85

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

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

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

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

Instance Attribute Details

#modelObject (readonly)

TODO: document



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

def model
  @model
end

#propertyObject (readonly)

TODO: document



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

def property
  @property
end

#relationshipsObject (readonly)

TODO: document



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

def relationships
  @relationships
end

#repository_nameObject (readonly)

TODO: document



19
20
21
# File 'lib/dm-core/query/path.rb', line 19

def repository_name
  @repository_name
end

Instance Method Details

#instance_of?(klass) ⇒ Boolean

TODO: document

Returns:

  • (Boolean)


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

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

#kind_of?(klass) ⇒ Boolean

TODO: document

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

TODO: document

Returns:

  • (Boolean)


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

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