Module: CukeModeler::Nested

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

Overview

NOT A PART OF THE PUBLIC API A mix-in module containing methods used by models that are nested inside of other models.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#parent_modelObject

The parent model that contains this model



10
11
12
# File 'lib/cuke_modeler/nested.rb', line 10

def parent_model
  @parent_model
end

Instance Method Details

#get_ancestor(ancestor_type) ⇒ Object

Returns the ancestor model of this model that matches the given type.

Raises:

  • (ArgumentError)


14
15
16
17
18
19
20
21
22
23
# File 'lib/cuke_modeler/nested.rb', line 14

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