Class: Guacamole::DocumentModelMapper::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/guacamole/document_model_mapper.rb

Overview

An attribute to encapsulate special mapping

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Attribute

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.

Parameters:

  • name (Symbol)

    The name of the attribute

  • options (Hash) (defaults to: {})

    Additional options to be passed

Options Hash (options):

  • :via (Edge)

    The Edge class this attribute relates to



34
35
36
37
# File 'lib/guacamole/document_model_mapper.rb', line 34

def initialize(name, options = {})
  @name    = name.to_sym
  @options = options
end

Instance Attribute Details

#nameSymbol (readonly)

The name of the attribute with in the model

Returns:

  • (Symbol)

    The name of the attribute



19
20
21
# File 'lib/guacamole/document_model_mapper.rb', line 19

def name
  @name
end

#optionsHash (readonly)

Additional options to be used for the mapping

Returns:

  • (Hash)

    The mapping options for the attribute



24
25
26
# File 'lib/guacamole/document_model_mapper.rb', line 24

def options
  @options
end

Instance Method Details

#==(other) ⇒ Boolean Also known as: eql?

To Attribute instances are equal if their name is equal

Parameters:

  • other (Attribute)

    The Attribute to compare this one to

Returns:

  • (Boolean)

    True if both have the same name



81
82
83
84
# File 'lib/guacamole/document_model_mapper.rb', line 81

def ==(other)
  other.instance_of?(self.class) &&
    other.name == name
end

#edge_classEdge

The edge class to be used during the mapping process

Returns:

  • (Edge)

    The actual edge class



69
70
71
# File 'lib/guacamole/document_model_mapper.rb', line 69

def edge_class
  options[:via]
end

#get_value(model) ⇒ Object



46
47
48
49
50
# File 'lib/guacamole/document_model_mapper.rb', line 46

def get_value(model)
  value = model.send(getter)

  value.is_a?(Guacamole::Query) ? value.entries : value
end

#getterObject

The name of the getter for this attribute



42
43
44
# File 'lib/guacamole/document_model_mapper.rb', line 42

def getter
  name
end

#inverse?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/guacamole/document_model_mapper.rb', line 73

def inverse?
  !!options[:inverse]
end

#map_via_edge?Boolean

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

Returns:

  • (Boolean)

    True if there was an edge class configured



62
63
64
# File 'lib/guacamole/document_model_mapper.rb', line 62

def map_via_edge?
  !!edge_class
end

#setterString

The name of the setter for this attribute

Returns:

  • (String)

    The method name to set this attribute



55
56
57
# File 'lib/guacamole/document_model_mapper.rb', line 55

def setter
  "#{name}="
end