Class: ComputedModel::DepGraph::Edge Private

Inherits:
Object
  • Object
show all
Defined in:
lib/computed_model/dep_graph.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

An edge in the dependency graph. That is, a dependency declaration in a computed model.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, spec) ⇒ Edge

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Edge.

Parameters:

  • name (Symbol)

    the name of the dependency (not the dependent)

  • spec (Array)

    an auxiliary data called subfield selectors



160
161
162
163
# File 'lib/computed_model/dep_graph.rb', line 160

def initialize(name, spec)
  @name = name
  @spec = Array(spec)
end

Instance Attribute Details

#nameSymbol (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the name of the dependency (not the dependent).

Returns:

  • (Symbol)

    the name of the dependency (not the dependent)



154
155
156
# File 'lib/computed_model/dep_graph.rb', line 154

def name
  @name
end

#specArray (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns an auxiliary data called subfield selectors.

Returns:

  • (Array)

    an auxiliary data called subfield selectors



156
157
158
# File 'lib/computed_model/dep_graph.rb', line 156

def spec
  @spec
end

Instance Method Details

#evaluate(subfields) ⇒ Array?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • subfields (Array)

    incoming list of subfield selectors

Returns:

  • (Array, nil)


167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/computed_model/dep_graph.rb', line 167

def evaluate(subfields)
  return @spec if @spec.all? { |specelem| !specelem.respond_to?(:call) }

  evaluated = []
  @spec.each do |specelem|
    if specelem.respond_to?(:call)
      ret = specelem.call(subfields)
      if ret.is_a?(Array)
        evaluated.push(*ret)
      else
        evaluated << ret
      end
    else
      evaluated << specelem
    end
  end
  evaluated
end