Class: Nanoc::CLI::CommandRunner Private
- Inherits:
-
Cri::CommandRunner
- Object
- Cri::CommandRunner
- Nanoc::CLI::CommandRunner
- Defined in:
- lib/nanoc/cli/command_runner.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
A command runner subclass for Nanoc commands that adds Nanoc-specific convenience methods and error handling.
Direct Known Subclasses
Nanoc::CLI::Commands::Compile, Nanoc::CLI::Commands::CreateSite, Nanoc::CLI::Commands::Prune, Nanoc::CLI::Commands::Shell, Nanoc::CLI::Commands::ShowData, Nanoc::CLI::Commands::ShowPlugins, Nanoc::CLI::Commands::View
Class Method Summary collapse
- .enter_site_dir ⇒ Object private
- .find_site_dir ⇒ Object private
Instance Method Summary collapse
- #call ⇒ void private
-
#debug? ⇒ Boolean
private
True if debug output is enabled, false if not.
-
#in_site_dir? ⇒ Boolean
private
True if the current working directory is a Nanoc site directory, false otherwise.
-
#load_site ⇒ void
private
Asserts that the current working directory contains a site and loads the site into memory.
Class Method Details
.enter_site_dir ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/nanoc/cli/command_runner.rb', line 40 def self.enter_site_dir dir = find_site_dir if dir.nil? raise ::Nanoc::Core::TrivialError, 'The current working directory, nor any of its parents, seems to be a Nanoc site.' end return if Dir.getwd == dir $stderr.puts "Using Nanoc site in #{dir}" Dir.chdir(dir) end |
.find_site_dir ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/nanoc/cli/command_runner.rb', line 25 def self.find_site_dir start_here = Dir.pwd here = start_here until Nanoc::Core::SiteLoader.cwd_is_nanoc_site? Dir.chdir('..') return nil if Dir.pwd == here here = Dir.pwd end here ensure Dir.chdir(start_here) end |
Instance Method Details
#call ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
13 14 15 16 17 |
# File 'lib/nanoc/cli/command_runner.rb', line 13 def call Nanoc::CLI::ErrorHandler.handle_while do run end end |
#debug? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns true if debug output is enabled, false if not.
69 70 71 |
# File 'lib/nanoc/cli/command_runner.rb', line 69 def debug? Nanoc::CLI.debug? end |
#in_site_dir? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns true if the current working directory is a Nanoc site directory, false otherwise.
21 22 23 |
# File 'lib/nanoc/cli/command_runner.rb', line 21 def in_site_dir? Nanoc::Core::SiteLoader.cwd_is_nanoc_site? end |
#load_site ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Asserts that the current working directory contains a site and loads the site into memory.
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/nanoc/cli/command_runner.rb', line 55 def load_site self.class.enter_site_dir $stderr.print 'Loading siteā¦ ' $stderr.flush site = Nanoc::Core::SiteLoader.new.new_from_cwd $stderr.puts 'done' site end |