class Guacamole::DocumentModelMapper::Attribute

An attribute to encapsulate special mapping

Attributes

name[R]

The name of the attribute with in the model

@return [Symbol] The name of the attribute

options[R]

Additional options to be used for the mapping

@return [Hash] The mapping options for the attribute

Public Class Methods

new(name, options = {}) click to toggle source

Create a new attribute instance

You must at least provide the name of the attribute to be mapped and optionally pass configuration for the mapper when it processes this attribute.

@param [Symbol] name The name of the attribute @param [Hash] options Additional options to be passed @option options [Edge] :via The Edge class this attribute relates to

# File lib/guacamole/document_model_mapper.rb, line 33
def initialize(name, options = {})
  @name    = name.to_sym
  @options = options
end

Public Instance Methods

==(other) click to toggle source

To Attribute instances are equal if their name is equal

@param [Attribute] other The Attribute to compare this one to @return [Boolean] True if both have the same name

# File lib/guacamole/document_model_mapper.rb, line 80
def ==(other)
  other.instance_of?(self.class) &&
    other.name == name
end
Also aliased as: eql?
edge_class() click to toggle source

The edge class to be used during the mapping process

@return [Edge] The actual edge class

# File lib/guacamole/document_model_mapper.rb, line 68
def edge_class
  options[:via]
end
eql?(other)
Alias for: ==
get_value(model) click to toggle source
# File lib/guacamole/document_model_mapper.rb, line 45
def get_value(model)
  value = model.send(getter)

  value.is_a?(Guacamole::Query) ? value.entries : value
end
getter() click to toggle source

The name of the getter for this attribute

@returns [Symbol] The method name to read this attribute

# File lib/guacamole/document_model_mapper.rb, line 41
def getter
  name
end
inverse?() click to toggle source
# File lib/guacamole/document_model_mapper.rb, line 72
def inverse?
  !!options[:inverse]
end
map_via_edge?() click to toggle source

Should this attribute be mapped via an Edge in a Graph?

@return [Boolean] True if there was an edge class configured

# File lib/guacamole/document_model_mapper.rb, line 61
def map_via_edge?
  !!edge_class
end
setter() click to toggle source

The name of the setter for this attribute

@return [String] The method name to set this attribute

# File lib/guacamole/document_model_mapper.rb, line 54
def setter
  "#{name}="
end