Sha256: dc56be3365abc7c76c50982906bea42b8f2be09aef18cb3d994f084c2f35fdf4

Contents?: true

Size: 1.16 KB

Versions: 13

Compression:

Stored size: 1.16 KB

Contents

module CukeModeler

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

  module Nested

    # The parent model that contains this model
    attr_accessor :parent_model


    # Returns the ancestor model of this model that matches the given type.
    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

  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
cuke_modeler-1.5.1 lib/cuke_modeler/nested.rb
cuke_modeler-1.5.0 lib/cuke_modeler/nested.rb
cuke_modeler-1.4.0 lib/cuke_modeler/nested.rb
cuke_modeler-1.3.0 lib/cuke_modeler/nested.rb
cuke_modeler-1.2.1 lib/cuke_modeler/nested.rb
cuke_modeler-1.2.0 lib/cuke_modeler/nested.rb
cuke_modeler-1.1.1 lib/cuke_modeler/nested.rb
cuke_modeler-1.1.0 lib/cuke_modeler/nested.rb
cuke_modeler-1.0.4 lib/cuke_modeler/nested.rb
cuke_modeler-1.0.3 lib/cuke_modeler/nested.rb
cuke_modeler-1.0.2 lib/cuke_modeler/nested.rb
cuke_modeler-1.0.1 lib/cuke_modeler/nested.rb
cuke_modeler-1.0.0 lib/cuke_modeler/nested.rb