Class: CukeModeler::FeatureFile

Inherits:
Model
  • Object
show all
Includes:
Parsed
Defined in:
lib/cuke_modeler/models/feature_file.rb

Overview

A class modeling a feature file in a Cucumber suite.

Instance Attribute Summary collapse

Attributes included from Parsed

#parsing_data

Attributes included from Nested

#parent_model

Instance Method Summary collapse

Methods included from Containing

#each, #each_descendant, #each_model

Methods included from Nested

#get_ancestor

Constructor Details

#initialize(file_path = nil) ⇒ FeatureFile

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

Examples:

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

Parameters:

  • file_path (String) (defaults to: nil)

    The file path that will be used to populate the model

Raises:

  • (ArgumentError)

    If file_path is not a String

  • (ArgumentError)

    If the file path does not exist



30
31
32
33
34
35
# File 'lib/cuke_modeler/models/feature_file.rb', line 30

def initialize(file_path = nil)
  @path = file_path
  @comments = []

  super
end

Instance Attribute Details

#commentsObject

The comment models contained by the modeled feature file



10
11
12
# File 'lib/cuke_modeler/models/feature_file.rb', line 10

def comments
  @comments
end

#featureObject

The feature model contained by the modeled feature file



13
14
15
# File 'lib/cuke_modeler/models/feature_file.rb', line 13

def feature
  @feature
end

#pathObject

The file path of the modeled feature file



16
17
18
# File 'lib/cuke_modeler/models/feature_file.rb', line 16

def path
  @path
end

Instance Method Details

#childrenArray<Feature>

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

Examples:

feature_file.children

Returns:

  • (Array<Feature>)

    A collection of child models



55
56
57
# File 'lib/cuke_modeler/models/feature_file.rb', line 55

def children
  @feature ? [@feature] : []
end

#inspect(verbose: false) ⇒ String

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.

Examples:

feature_file.inspect
feature_file.inspect(verbose: true)

Parameters:

  • verbose (Boolean) (defaults to: false)

    Whether or not to return the full details of the object. Defaults to false.

Returns:

  • (String)

    A string representation of this model



83
84
85
86
87
# File 'lib/cuke_modeler/models/feature_file.rb', line 83

def inspect(verbose: false)
  return super if verbose

  "#{super.chop} @path: #{@path.inspect}>"
end

#nameString

Returns the name of the modeled feature file.

Examples:

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

Returns:

  • (String)

    The name of the file



44
45
46
# File 'lib/cuke_modeler/models/feature_file.rb', line 44

def name
  File.basename(@path.gsub('\\', '/')) if @path
end

#to_sString

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

Examples:

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

Returns:

  • (String)

    A string representation of this model



66
67
68
# File 'lib/cuke_modeler/models/feature_file.rb', line 66

def to_s
  path.to_s
end