Module: Grably::Module
- Defined in:
- lib/grably/core/module.rb
Overview
Methods for working with submodules
Defined Under Namespace
Classes: ModuleCall
Constant Summary collapse
- DEFAULT_FILES =
List of file names we can load as submodule entry
Rake::Application::DEFAULT_RAKEFILES
Class Method Summary collapse
-
.ensure_filename(path) ⇒ Object
Ensures that provided path points to one of allowed to load files.
- .ensure_module_dir(path) ⇒ Object
-
.reference(path, task) ⇒ Grably::Module::ModuleCall
Get submodule object.
Class Method Details
.ensure_filename(path) ⇒ Object
Ensures that provided path points to one of allowed to load files
48 49 50 51 52 53 54 |
# File 'lib/grably/core/module.rb', line 48 def ensure_filename(path) basename = File.basename(path) return path if DEFAULT_FILES.include?(basename) exp = DEFAULT_FILES.join(', ') raise "Wrong file name #{basename} expected one of #{exp}" end |
.ensure_module_dir(path) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/grably/core/module.rb', line 56 def ensure_module_dir(path) base_path = Dir["#{path}/*"] .find { |f| DEFAULT_FILES.include?(File.basename(f)) } raise "Can't find any file to load in #{path}" unless base_path base_path end |
.reference(path, task) ⇒ Grably::Module::ModuleCall
Get submodule object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/grably/core/module.rb', line 36 def reference(path, task) base_path = File.(File.join(Dir.pwd, path)) raise "#{path} does not exist" unless File.exist?(path) path = if File.directory?(base_path) ensure_module_dir(base_path) else ensure_filename(base_path) end ModuleCall.new(path, task) end |