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.



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

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

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

#shellObject (readonly)

Returns the value of attribute shell.



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

def shell
  @shell
end

Class Method Details

.source_rootObject

Set the source root for Thor::Actions



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

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.



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

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.



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

def pathname(path)
  Pathname.new(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.



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

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)


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

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