Module: Yap::Cli::OptionsLoader
- Included in:
- Options, Yap::Cli::Options::Addon, Yap::Cli::Options::Addon::Disable, Yap::Cli::Options::Addon::Enable, Yap::Cli::Options::Addon::List, Yap::Cli::Options::Addon::Search, Yap::Cli::Options::Generate, Yap::Cli::Options::Generate::Addon
- Defined in:
- lib/yap/cli/options.rb
Instance Method Summary collapse
- #load_command(path) ⇒ Object
- #load_constant_from_path(path) ⇒ Object
- #load_relative_constant(path_str) ⇒ Object
Instance Method Details
#load_command(path) ⇒ Object
8 9 10 |
# File 'lib/yap/cli/options.rb', line 8 def load_command(path) load_constant_from_path Pathname.new('yap/cli/commands').join(path) end |
#load_constant_from_path(path) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/yap/cli/options.rb', line 12 def load_constant_from_path(path) requiring_parts = [] path_parts = path.to_s.split('/') requiring_path = nil constant = path_parts.reduce(Object) do |constant, path_part| requiring_parts << path_part file2load = Yap.root.join('lib', requiring_parts.join('/') + "*.rb") requiring_path = Dir[ file2load ].sort.first if requiring_path require requiring_path path_part = File.basename(requiring_path).sub(/\.rb$/, '') requiring_parts.pop requiring_parts.push path_part constant_name = path_part.capitalize if constant.const_defined?(constant_name) constant = constant.const_get(constant_name) else fail "Couldn't find #{path_part} in #{constant}" end else fail LoadError, "Couldn't load any file for #{file2load}" end end Treefell['shell'].puts "#{inspect} loaded: #{constant}" constant end |
#load_relative_constant(path_str) ⇒ Object
39 40 41 42 43 |
# File 'lib/yap/cli/options.rb', line 39 def load_relative_constant(path_str) base_path = self.class.name.downcase.gsub(/::/, '/') require_path = Pathname.new(base_path) load_constant_from_path require_path.join(path_str).to_s end |