Module: Dagnabit::Vertex::Settings

Included in:
Associations, Connectivity
Defined in:
lib/dagnabit/vertex/settings.rb

Overview

Contains parameters that can be customized on a per-vertex-model basis.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#edge_model_nameString

The name of this vertex’s edge model.

Returns:

  • (String)


11
12
13
# File 'lib/dagnabit/vertex/settings.rb', line 11

def edge_model_name
  @edge_model_name
end

Instance Method Details

#connected_by(edge_model_name) ⇒ void

This method returns an undefined value.

Sets the name of the edge model associated with a vertex.

#edge_model uses ActiveSupport’s ‘constantize` method to look up the model from `edge_model_name`.

Parameters:

  • edge_model_name (String)

    the name of the edge model to use



39
40
41
# File 'lib/dagnabit/vertex/settings.rb', line 39

def connected_by(edge_model_name)
  self.edge_model_name = edge_model_name
end

#edge_modelClass

The edge model associated with a vertex model.

Returns:

  • (Class)

    the edge model



17
18
19
# File 'lib/dagnabit/vertex/settings.rb', line 17

def edge_model
  edge_model_name.constantize
end

#edge_tableString

The edge table used by connectivity queries. Equivalent to

edge_model.table_name

Returns:

  • (String)

    the name of the edge table



27
28
29
# File 'lib/dagnabit/vertex/settings.rb', line 27

def edge_table
  edge_model.table_name
end

#inherited(subclass) ⇒ Object

This callback ensures that whenever a class that extends Settings is inherited, the settings for the superclass are passed to the subclass.

This callback executes any previously-defined definitions of ‘inherited` beforee executing its own code.

Parameters:

  • subclass (Class)

    the descendant class



51
52
53
54
# File 'lib/dagnabit/vertex/settings.rb', line 51

def inherited(subclass)
  super
  subclass.connected_by(edge_model_name)
end