Parent

Class/Module Index [+]

Quicksearch

Nanoc::CLI::CommandRunner

A command runner subclass for nanoc commands that adds nanoc-specific convenience methods and error handling.

Public Class Methods

call(opts, args, cmd) click to toggle source

@deprecated use `Cri::CommandDSL#runner`

@see rubydoc.info/gems/cri/Cri/CommandDSL#runner-instance_method

# File lib/nanoc/cli/command_runner.rb, line 34
def self.call(opts, args, cmd)
  self.new(opts, args, cmd).call
end

Public Instance Methods

call() click to toggle source

@see rubydoc.info/gems/cri/Cri/CommandRunner#call-instance_method

@return [void]

# File lib/nanoc/cli/command_runner.rb, line 11
def call
  Nanoc::CLI::ErrorHandler.handle_while(:command => self) do
    self.run
  end
end
debug?() click to toggle source

@return [Boolean] true if debug output is enabled, false if not

@see Nanoc::CLI.debug?

# File lib/nanoc/cli/command_runner.rb, line 69
def debug?
  Nanoc::CLI.debug?
end
is_in_site_dir?() click to toggle source

@return [Boolean] true if the current working directory is a nanoc site

directory, false otherwise
# File lib/nanoc/cli/command_runner.rb, line 40
def is_in_site_dir?
  Nanoc::Site.cwd_is_nanoc_site?
end
load_site() click to toggle source

Asserts that the current working directory contains a site (just like {require_site}) and loads the site into memory.

@return [void]

# File lib/nanoc/cli/command_runner.rb, line 59
def load_site
  self.require_site
  print "Loading site data… "
  self.site.load
  puts "done"
end
require_site() click to toggle source

Asserts that the current working directory contains a site ({Nanoc::Site} instance). If no site is present, prints an error message and exits.

@return [void]

# 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
site() click to toggle source

Gets the site ({Nanoc::Site} instance) in the current directory and loads its data.

@return [Nanoc::Site] The site in the current working directory

# File lib/nanoc/cli/command_runner.rb, line 21
def site
  # Load site if possible
  @site ||= nil
  if self.is_in_site_dir? && @site.nil?
    @site = Nanoc::Site.new('.')
  end

  @site
end

Protected Instance Methods

set_vcs(vcs_name) click to toggle source

Sets the data source's VCS to the VCS with the given name. Does nothing when the site's data source does not support VCSes (i.e. does not implement vcs=).

@param [String] vcs_name The name of the VCS that should be used

@return [void]

# File lib/nanoc/cli/command_runner.rb, line 82
def set_vcs(vcs_name)
  # Skip if not possible
  return if vcs_name.nil? || site.nil?

  # Find VCS
  vcs_class = Nanoc::Extra::VCS.named(vcs_name.to_sym)
  if vcs_class.nil?
    raise Nanoc::Errors::GenericTrivial, "A VCS named #{vcs_name} was not found"
  end

  site.data_sources.each do |data_source|
    # Skip if not possible
    next if !data_source.respond_to?(:vcs=)

    # Set VCS
    data_source.vcs = vcs_class.new
  end
end
stack() click to toggle source

@return [Array] The compilation stack.

# File lib/nanoc/cli/command_runner.rb, line 102
def stack
  (self.site && self.site.compiler.stack) || []
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.