Class: Plans::Command

Inherits:
Object
  • Object
show all
Includes:
Thor::Actions, Thor::Base
Defined in:
lib/plans/command.rb

Direct Known Subclasses

Init, List, New, Publish, Thumbs

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(shell, options) ⇒ Command

Initialize the command with the Thor::Shell and the options.



20
21
22
23
# File 'lib/plans/command.rb', line 20

def initialize(shell, options)
  @shell = shell
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



16
17
18
# File 'lib/plans/command.rb', line 16

def options
  @options
end

#shellObject (readonly)

Returns the value of attribute shell.



16
17
18
# File 'lib/plans/command.rb', line 16

def shell
  @shell
end

Class Method Details

.source_rootObject

Set the source root for Thor::Actions



12
13
14
# File 'lib/plans/command.rb', line 12

def self.source_root
  Plans.source_root
end

Instance Method Details

#check_plans_pathname_exists(path) ⇒ Object

Check to see if the .plans path exists Prints a message for the user and raises if it does not.

Parameters:

  • path (Pathname)

    the proposed path to the .plans directory.



29
30
31
32
33
34
35
36
# File 'lib/plans/command.rb', line 29

def check_plans_pathname_exists(path)
  unless path.exist?
    say 'The .plans directory does not exist.', :red
    say 'Run `plans init` to create a .plans folder in your home directory and initialize it with the default document templates.'
    say "  #{@path}"
    raise_error('Plans directory does not exist.')
  end
end

#pathname(path) ⇒ Pathname

The full current path, as a pathname object.

Returns:

  • (Pathname)

    The full path to the directory where the command is to be executed.



40
41
42
# File 'lib/plans/command.rb', line 40

def pathname(path)
  Pathname(File.expand_path(path))
end

#plans_pathname(path = nil) ⇒ Object

Get the path as a pathname object to the .plans directory.

Parameters:

  • path (String) (defaults to: nil)

    The string path to the .plans directory or nil if the users home directory should be used.



49
50
51
52
# File 'lib/plans/command.rb', line 49

def plans_pathname(path = nil)
  path = path || Dir.home
  pathname(path) + '.plans'
end

#raise_error(msg) ⇒ Object

Raise a formatted Thor exception.

Parameters:

  • msg (String)

    the message to include in the exception.

Raises:

  • (Thor::Error)


57
58
59
# File 'lib/plans/command.rb', line 57

def raise_error(msg)
  raise Thor::Error, "Error: #{msg}"
end