Class: CukeModeler::Directory

Inherits:
Model
  • Object
show all
Defined in:
lib/cuke_modeler/models/directory.rb

Overview

A class modeling a directory in a Cucumber suite.

Instance Attribute Summary collapse

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(directory_path = nil) ⇒ Directory

Creates a new Directory object and, if directory_path is provided, populates the object.

Examples:

Directory.new
Directory.new('some/directory/path')

Parameters:

  • directory_path (String) (defaults to: nil)

    The directory path that will be used to populate the model

Raises:

  • (ArgumentError)

    If directory_path is not a String

  • (ArgumentError)

    If the directory path does not exist



28
29
30
31
32
33
34
# File 'lib/cuke_modeler/models/directory.rb', line 28

def initialize(directory_path = nil)
  @path = directory_path
  @feature_files = []
  @directories = []

  super(directory_path)
end

Instance Attribute Details

#directoriesObject

The directory models contained by the modeled directory



11
12
13
# File 'lib/cuke_modeler/models/directory.rb', line 11

def directories
  @directories
end

#feature_filesObject

The feature file models contained by the modeled directory



8
9
10
# File 'lib/cuke_modeler/models/directory.rb', line 8

def feature_files
  @feature_files
end

#pathObject

The file path of the modeled directory



14
15
16
# File 'lib/cuke_modeler/models/directory.rb', line 14

def path
  @path
end

Instance Method Details

#childrenArray<Directory, FeatureFile>

Returns the model objects that are children of this model. For a Directory model, these would be any associated Directory and FeatureFile models.

Examples:

directory.children

Returns:



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

def children
  @feature_files + @directories
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 Directory model, this will be the path of the directory. If verbose is true, provides default Ruby inspection behavior instead.

Examples:

directory.inspect
directory.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/directory.rb', line 83

def inspect(verbose: false)
  return super(verbose: verbose) if verbose

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

#nameString?

Returns the name of the modeled directory.

Examples:

d = Directory.new('some/directory/foo')
d.name  #=> 'foo'

Returns:

  • (String, nil)

    The name of the directory



43
44
45
# File 'lib/cuke_modeler/models/directory.rb', line 43

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

#to_sString

Returns a string representation of this model. For a Directory model, this will be the path of the modeled directory.

Examples:

directory.to_s #=> 'some/directory/path'

Returns:

  • (String)

    A string representation of this model



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

def to_s
  path.to_s
end