Sha256: 708fd35125c2cb147b8ad3b948bdf606c91f6c782005a55d7b7b50eeac2149b7

Contents?: true

Size: 1.13 KB

Versions: 10

Compression:

Stored size: 1.13 KB

Contents

module CukeModeler

  # NOT A PART OF THE PUBLIC API
  # 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_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


    private


    def classes_for_type(type)
      {
        directory: [Directory],
        feature_file: [FeatureFile],
        feature: [Feature],
        rule: [Rule],
        test: [Scenario, Outline, Background],
        background: [Background],
        scenario: [Scenario],
        outline: [Outline],
        step: [Step],
        table: [Table],
        example: [Example],
        row: [Row]
      }[type]
    end

  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
cuke_modeler-3.20.0 lib/cuke_modeler/nested.rb
cuke_modeler-3.19.0 lib/cuke_modeler/nested.rb
cuke_modeler-3.18.0 lib/cuke_modeler/nested.rb
cuke_modeler-3.17.0 lib/cuke_modeler/nested.rb
cuke_modeler-3.16.0 lib/cuke_modeler/nested.rb
cuke_modeler-3.15.0 lib/cuke_modeler/nested.rb
cuke_modeler-3.14.0 lib/cuke_modeler/nested.rb
cuke_modeler-3.13.0 lib/cuke_modeler/nested.rb
cuke_modeler-3.12.0 lib/cuke_modeler/nested.rb
cuke_modeler-3.11.0 lib/cuke_modeler/nested.rb