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.
Calls superclass method
# File lib/cuke_modeler/models/directory.rb, line 19 def initialize(directory_path = nil) @path = directory_path @feature_files = [] @directories = [] super(directory_path) return unless directory_path raise(ArgumentError, "Unknown directory: #{directory_path.inspect}") unless File.exist?(directory_path) processed_directory_data = process_directory(directory_path) populate_directory(self, processed_directory_data) end
Public Instance Methods
children()
click to toggle source
Returns the model objects that belong to this model.
# File lib/cuke_modeler/models/directory.rb, line 39 def children @feature_files + @directories end
name()
click to toggle source
Returns the name of the modeled directory.
# File lib/cuke_modeler/models/directory.rb, line 34 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.
# File lib/cuke_modeler/models/directory.rb, line 45 def to_s path.to_s end
Private Instance Methods
process_directory(directory_path)
click to toggle source
# File lib/cuke_modeler/models/directory.rb, line 53 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 77 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