Sha256: e306bd32c4a26d284e4518a414e612865f82c3307e8bebb71badd73562969295

Contents?: true

Size: 953 Bytes

Versions: 7

Compression:

Stored size: 953 Bytes

Contents

module CukeModeler

  # A mix-in module containing methods used by elements that are nested inside
  # of other elements.

  module Nested

    # The parent object that contains *self*
    attr_accessor :parent_element


    # Returns the ancestor of *self* that matches the given type.
    def get_ancestor(ancestor_type)
      ancestor = self.parent_element
      target_type = {:directory => Directory,
                     :feature_file => FeatureFile,
                     :feature => Feature,
                     :test => TestElement,
                     :step => Step,
                     :table => Table,
                     :example => Example
      }[ancestor_type]

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

      until ancestor.is_a?(target_type) || ancestor.nil?
        ancestor = ancestor.parent_element
      end

      ancestor
    end

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
cuke_modeler-0.4.1 lib/cuke_modeler/nested.rb
cuke_modeler-0.4.0 lib/cuke_modeler/nested.rb
cuke_modeler-0.3.0 lib/cuke_modeler/nested.rb
cuke_modeler-0.2.0 lib/cuke_modeler/nested.rb
cuke_modeler-0.1.0 lib/cuke_modeler/nested.rb
cuke_modeler-0.0.2 lib/cuke_modeler/nested.rb
cuke_modeler-0.0.1 lib/cuke_modeler/nested.rb