class CukeModeler::FeatureFile

A class modeling a feature file in a Cucumber suite.

Attributes

comments[RW]

The comment models contained by the modeled feature file

feature[RW]

The feature model contained by the modeled feature file

path[RW]

The file path of the modeled feature file

Public Class Methods

new(file_path = nil) click to toggle source

Creates a new FeatureFile object and, if file_path is provided, populates the object.

@example

FeatureFile.new
FeatureFile.new('path/to/some.feature')

@param file_path [String] The file path that will be used to populate the model @raise [ArgumentError] If file_path is not a String @raise [ArgumentError] If the file path does not exist @return [FeatureFile] A new FeatureFile instance

Calls superclass method
# File lib/cuke_modeler/models/feature_file.rb, line 30
def initialize(file_path = nil)
  @path = file_path
  @comments = []

  super
end

Public Instance Methods

children() click to toggle source

Returns the model objects that are children of this model. For a FeatureFile model, this would be any associated Feature model.

@example

feature_file.children

@return [Array<Feature>] A collection of child models

# File lib/cuke_modeler/models/feature_file.rb, line 55
def children
  @feature ? [@feature] : []
end
inspect(verbose: false) click to toggle source

See ‘Object#inspect`. Returns some basic information about the object, including its class, object ID, and its most meaningful attribute. For a FeatureFile model, this will be the path of the feature file. If verbose is true, provides default Ruby inspection behavior instead.

@example

feature_file.inspect
feature_file.inspect(verbose: true)

@param verbose [Boolean] Whether or not to return the full details of

the object. Defaults to false.

@return [String] A string representation of this model

Calls superclass method
# File lib/cuke_modeler/models/feature_file.rb, line 83
def inspect(verbose: false)
  return super if verbose

  "#{super.chop} @path: #{@path.inspect}>"
end
name() click to toggle source

Returns the name of the modeled feature file.

@example

f = FeatureFile.new('path/to/some.feature')
f.name  #=> 'some.feature'

@return [String] The name of the file

# File lib/cuke_modeler/models/feature_file.rb, line 44
def name
  File.basename(@path.gsub('\\', '/')) if @path
end
to_s() click to toggle source

Returns a string representation of this model. For a FeatureFile model, this will be the path of the modeled feature file.

@example

feature_file.to_s #=> 'path/to/some.feature'

@return [String] A string representation of this model

# File lib/cuke_modeler/models/feature_file.rb, line 66
def to_s
  path.to_s
end

Private Instance Methods

populate_model(processed_feature_file_data) click to toggle source
# File lib/cuke_modeler/models/feature_file.rb, line 102
def populate_model(processed_feature_file_data)
  populate_parsing_data(processed_feature_file_data)
  @path = processed_feature_file_data['path']

  if processed_feature_file_data['feature']
    @feature = build_child_model(Feature, processed_feature_file_data['feature'])
  end

  processed_feature_file_data['comments'].each do |comment_data|
    @comments << build_child_model(Comment, comment_data)
  end
end
process_source(file_path) click to toggle source
# File lib/cuke_modeler/models/feature_file.rb, line 93
def process_source(file_path)
  raise(ArgumentError, "Unknown file: #{file_path.inspect}") unless File.exist?(file_path)

  source_text       = File.read(file_path)
  feature_file_data = Parsing.parse_text(source_text, file_path)

  feature_file_data.merge({ 'path' => file_path })
end