Module: CukeModeler::Nested Private

Included in:
Model
Defined in:
lib/cuke_modeler/nested.rb

Overview

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

A mix-in module containing methods used by models that are nested inside of other models. Internal helper class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#parent_modelObject

The parent model that contains this model



12
13
14
# File 'lib/cuke_modeler/nested.rb', line 12

def parent_model
  @parent_model
end

Instance Method Details

#get_ancestor(ancestor_type) ⇒ Model?

Returns the ancestor model of this model that matches the given type. Available types are simply snake_case versions of the model Class names. Additionally, a special type :test will return either a Scenario or an Outline model.

Examples:

model.get_ancestor(:directory)

Parameters:

  • ancestor_type (Symbol)

    The ancestor type to get

Returns:

  • (Model, nil)

    The ancestor model, if one is found

Raises:

  • (ArgumentError)

    If the passed type is not a valid model type



28
29
30
31
32
33
34
35
36
37
# File 'lib/cuke_modeler/nested.rb', line 28

def get_ancestor(ancestor_type)
  target_classes = classes_for_type(ancestor_type)

  raise(ArgumentError, "Unknown ancestor type '#{ancestor_type}'.") if target_classes.nil?

  ancestor = parent_model
  ancestor = ancestor.parent_model until target_classes.include?(ancestor.class) || ancestor.nil?

  ancestor
end