Module: CukeModeler::Nested

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

Overview

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



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

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)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/cuke_modeler/nested.rb', line 13

def get_ancestor(ancestor_type)
  target_type = {:directory => [Directory],
                 :feature_file => [FeatureFile],
                 :feature => [Feature],
                 :test => [Scenario, Outline, Background],
                 :background => [Background],
                 :scenario => [Scenario],
                 :outline => [Outline],
                 :step => [Step],
                 :table => [Table],
                 :example => [Example],
                 :row => [Row]
  }[ancestor_type]

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


  ancestor = self.parent_model

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


  ancestor
end