module Journeyman::Load
Internal: Contains all the file requirement logic, to load the factory definitions.
Attributes
factories_paths[RW]
Public: Paths that will be loaded expecting factory definitions.
Public Class Methods
extended(journeyman)
click to toggle source
# File lib/journeyman/load.rb, line 9 def self.extended(journeyman) journeyman.factories_paths = %w(spec/factories) end
Public Instance Methods
load_factories()
click to toggle source
Internal: Loads all the factory files and processes the factory definitions.
# File lib/journeyman/load.rb, line 14 def load_factories absolute_factories_paths.each do |path| load_factories_if_file(path) load_factories_if_directory(path) end end
Private Instance Methods
absolute_factories_paths()
click to toggle source
Internal: Builds the absolute path for the factories location.
# File lib/journeyman/load.rb, line 24 def absolute_factories_paths if root_path factories_paths.map { |path| root_path.join(path) } else factories_paths.map { |path| File.expand_path(path) }.uniq end end
load_factories_if_directory(path)
click to toggle source
Internal: If the path is a directory, it loads all the factories in that path.
# File lib/journeyman/load.rb, line 38 def load_factories_if_directory(path) if File.directory?(path) Dir[File.join(path, '**', '*.rb')].sort.each { |file| Kernel.load file } end end
load_factories_if_file(path)
click to toggle source
Internal: If the path matches a file, it loads the factories defined in it.
# File lib/journeyman/load.rb, line 33 def load_factories_if_file(path) Kernel.load("#{path}.rb") if File.exists?("#{path}.rb") end
root_path()
click to toggle source
Internal: Returns the root path of the project TODO: Extract Rails and Sinatra integration.
# File lib/journeyman/load.rb, line 46 def root_path defined?(Rails) && Rails.root || defined?(Sinatra::Application) && Pathname.new(Sinatra::Application.root) || defined?(ROOT_DIR) && Pathname.new(ROOT_DIR) end