class CukeModeler::Directory

A class modeling a directory in a Cucumber suite.

Attributes

directories[RW]

The directory models contained by the modeled directory

feature_files[RW]

The feature file models contained by the modeled directory

path[RW]

The file path of the modeled directory

Public Class Methods

new(directory_path = nil) click to toggle source

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

@example

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

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

Calls superclass method
# File lib/cuke_modeler/models/directory.rb, line 28
def initialize(directory_path = nil)
  @path = directory_path
  @feature_files = []
  @directories = []

  super
end

Public Instance Methods

children() click to toggle source

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

@example

directory.children

@return [Array<Directory, FeatureFile>] A collection of child models

# File lib/cuke_modeler/models/directory.rb, line 55
def children
  @feature_files + @directories
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 Directory model, this will be the path of the directory. If verbose is true, provides default Ruby inspection behavior instead.

@example

directory.inspect
directory.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/directory.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 directory.

@example

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

@return [String, nil] The name of the directory

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

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

@example

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

@return [String] A string representation of this model

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

Private Instance Methods

populate_model(processed_directory_data) click to toggle source
# File lib/cuke_modeler/models/directory.rb, line 130
def populate_model(processed_directory_data)
  @path = processed_directory_data['path']

  processed_directory_data['directories'].each do |directory_data|
    @directories << build_child_model(Directory, directory_data)
  end

  processed_directory_data['feature_files'].each do |feature_file_data|
    @feature_files << build_child_model(FeatureFile, feature_file_data)
  end
end
process_directory(directory_path) click to toggle source
# File lib/cuke_modeler/models/directory.rb, line 99
def process_directory(directory_path)
  directory_data = { 'path'          => directory_path,
                     'directories'   => [],
                     'feature_files' => [] }

  entries = Dir.entries(directory_path)
  entries.delete '.'
  entries.delete '..'

  entries.each do |entry|
    entry = "#{directory_path}/#{entry}"

    # Ignore anything that isn't a directory or a feature file
    if File.directory?(entry)
      directory_data['directories'] << process_directory(entry)
    elsif entry =~ /\.feature$/
      directory_data['feature_files'] << process_feature_file(entry)
    end
  end


  directory_data
end
process_feature_file(file_path) click to toggle source
# File lib/cuke_modeler/models/directory.rb, line 123
def process_feature_file(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
process_source(directory_path) click to toggle source
# File lib/cuke_modeler/models/directory.rb, line 93
def process_source(directory_path)
  raise(ArgumentError, "Unknown directory: #{directory_path.inspect}") unless File.exist?(directory_path)

  process_directory(directory_path)
end