Class: Nanoc::CLI::CommandRunner Private

Inherits:
Cri::CommandRunner
  • Object
show all
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.

Instance Method Summary collapse

Instance Method Details

#callvoid

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.



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

#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.

Returns:

  • (Boolean)

    true if debug output is enabled, false if not

See Also:



65
66
67
# File 'lib/nanoc/cli/command_runner.rb', line 65

def debug?
  Nanoc::CLI.debug?
end

#in_site_dir?Boolean Also known as: is_in_site_dir?

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.

Returns:

  • (Boolean)

    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::Int::SiteLoader.cwd_is_nanoc_site?
end

#load_site(preprocess: false) ⇒ 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.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/nanoc/cli/command_runner.rb', line 47

def load_site(preprocess: false)
  print 'Loading site… '
  $stdout.flush

  if site.nil?
    raise ::Nanoc::Int::Errors::GenericTrivial, 'The current working directory does not seem to be a Nanoc site.'
  end

  if preprocess
    site.compiler.action_provider.preprocess(site)
  end

  puts 'done'
end

#siteNanoc::Int::Site

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.

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

Returns:



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 is_in_site_dir? && @site.nil?
    @site = Nanoc::Int::SiteLoader.new.new_from_cwd
  end

  @site
end

#site=(new_site) ⇒ 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.

For debugging purposes.



33
34
35
# File 'lib/nanoc/cli/command_runner.rb', line 33

def site=(new_site)
  @site = new_site
end