Class: Nanoc::CLI::CommandRunner
- Inherits:
-
Cri::CommandRunner
- Object
- Cri::CommandRunner
- Nanoc::CLI::CommandRunner
- Defined in:
- lib/nanoc/cli/command_runner.rb
Overview
A command runner subclass for nanoc commands that adds nanoc-specific convenience methods and error handling.
Direct Known Subclasses
Nanoc::CLI::Commands::AutoCompile, Nanoc::CLI::Commands::Check, Nanoc::CLI::Commands::Compile, Nanoc::CLI::Commands::CreateItem, Nanoc::CLI::Commands::CreateLayout, Nanoc::CLI::Commands::CreateSite, Nanoc::CLI::Commands::Deploy, Nanoc::CLI::Commands::Prune, Nanoc::CLI::Commands::Shell, Nanoc::CLI::Commands::ShowData, Nanoc::CLI::Commands::ShowPlugins, Nanoc::CLI::Commands::ShowRules, Nanoc::CLI::Commands::Sync, Nanoc::CLI::Commands::Update, Nanoc::CLI::Commands::ValidateCSS, Nanoc::CLI::Commands::ValidateHTML, Nanoc::CLI::Commands::ValidateLinks, Nanoc::CLI::Commands::View, Nanoc::CLI::Commands::Watch
Class Method Summary (collapse)
-
+ (Object) call(opts, args, cmd)
deprecated
Deprecated.
use
Cri::CommandDSL#runner
Instance Method Summary (collapse)
-
- (void) call
-
- (Boolean) debug?
True if debug output is enabled, false if not.
-
- (Boolean) in_site_dir?
(also: #is_in_site_dir?)
True if the current working directory is a nanoc site directory, false otherwise.
-
- (void) load_site
Asserts that the current working directory contains a site (just like #require_site) and loads the site into memory.
-
- (void) require_site
Asserts that the current working directory contains a site (Site instance).
-
- (Nanoc::Site) site
Gets the site (Site instance) in the current directory and loads its data.
Class Method Details
+ (Object) call(opts, args, cmd)
use Cri::CommandDSL#runner
33 34 35 |
# File 'lib/nanoc/cli/command_runner.rb', line 33 def self.call(opts, args, cmd) new(opts, args, cmd).call end |
Instance Method Details
- (void) call
This method returns an undefined value.
10 11 12 13 14 |
# File 'lib/nanoc/cli/command_runner.rb', line 10 def call Nanoc::CLI::ErrorHandler.handle_while(command: self) do run end end |
- (Boolean) debug?
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 |
- (Boolean) in_site_dir? Also known as: is_in_site_dir?
Returns true if the current working directory is a nanoc site directory, false otherwise
39 40 41 |
# File 'lib/nanoc/cli/command_runner.rb', line 39 def in_site_dir? Nanoc::Site.cwd_is_nanoc_site? end |
- (void) load_site
This method returns an undefined value.
Asserts that the current working directory contains a site (just like #require_site) and loads the site into memory.
59 60 61 62 63 64 |
# File 'lib/nanoc/cli/command_runner.rb', line 59 def load_site require_site print 'Loading site data… ' site.load puts 'done' end |
- (void) require_site
This method returns an undefined value.
Asserts that the current working directory contains a site (Site instance). If no site is present, prints an error message and exits.
49 50 51 52 53 |
# File 'lib/nanoc/cli/command_runner.rb', line 49 def require_site if site.nil? raise ::Nanoc::Errors::GenericTrivial, 'The current working directory does not seem to be a nanoc site.' end end |
- (Nanoc::Site) site
Gets the site (Site instance) in the current directory and loads its data.
20 21 22 23 24 25 26 27 28 |
# File 'lib/nanoc/cli/command_runner.rb', line 20 def site # Load site if possible @site ||= nil if self.is_in_site_dir? && @site.nil? @site = Nanoc::Site.new('.') end @site end |