Sha256: 5a065a494297c5618d53208f493b5e9bdcec4eb22e088ee46ccd6033e45e641e

Contents?: true

Size: 1.58 KB

Versions: 12

Compression:

Stored size: 1.58 KB

Contents

module CukeModeler

  # A class modeling a feature file in a Cucumber suite.
  class FeatureFile < Model

    include Parsed


    # The comment models contained by the modeled feature file
    attr_accessor :comments

    # The feature model contained by the modeled feature file
    attr_accessor :feature

    # The file path of the modeled feature file
    attr_accessor :path


    # Creates a new FeatureFile object and, if *file_path* is provided,
    # populates the object.
    def initialize(file_path = nil)
      @path = file_path
      @comments = []

      super(file_path)

      return unless file_path
      raise(ArgumentError, "Unknown file: #{file_path.inspect}") unless File.exist?(file_path)

      processed_feature_file_data = process_feature_file(file_path)
      populate_featurefile(self, processed_feature_file_data)
    end

    # Returns the name of the modeled feature file.
    def name
      File.basename(@path.gsub('\\', '/')) if @path
    end

    # Returns the model objects that belong to this model.
    def children
      @feature ? [@feature] : []
    end

    # Returns a string representation of this model. For a feature file
    # model, this will be the path of the modeled feature file.
    def to_s
      path.to_s
    end


    private


    def process_feature_file(file_path)
      source_text = IO.read(file_path)

      feature_file_data = Parsing.parse_text(source_text, file_path)
      feature_file_data = feature_file_data.merge({ 'path' => file_path })

      feature_file_data
    end

  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
cuke_modeler-3.18.0 lib/cuke_modeler/models/feature_file.rb
cuke_modeler-3.17.0 lib/cuke_modeler/models/feature_file.rb
cuke_modeler-3.16.0 lib/cuke_modeler/models/feature_file.rb
cuke_modeler-3.15.0 lib/cuke_modeler/models/feature_file.rb
cuke_modeler-3.14.0 lib/cuke_modeler/models/feature_file.rb
cuke_modeler-3.13.0 lib/cuke_modeler/models/feature_file.rb
cuke_modeler-3.12.0 lib/cuke_modeler/models/feature_file.rb
cuke_modeler-3.11.0 lib/cuke_modeler/models/feature_file.rb
cuke_modeler-3.10.0 lib/cuke_modeler/models/feature_file.rb
cuke_modeler-3.9.0 lib/cuke_modeler/models/feature_file.rb
cuke_modeler-3.8.0 lib/cuke_modeler/models/feature_file.rb
cuke_modeler-3.7.0 lib/cuke_modeler/models/feature_file.rb