Class: Snip::Command::Edit

Inherits:
Object
  • Object
show all
Includes:
Snip
Defined in:
lib/snip/command/edit.rb

Constant Summary

Constants included from Snip

DEFAULT_DIR, INSTALL_DIR, VERSION

Instance Method Summary collapse

Methods included from Snip

init, initialized?, snippet_exists?

Constructor Details

#initialize(args, options = {}) ⇒ Edit

Returns a new instance of Edit.



9
10
11
12
# File 'lib/snip/command/edit.rb', line 9

def initialize(args, options={})
  @args = Array(args)
  @options = options
end

Instance Method Details

#executeObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/snip/command/edit.rb', line 14

def execute
  name = @args
  raise NotInitializedError unless Snip::initialized?
  raise SnippetNotFoundError unless Snip::snippet_exists?(name)

  file_path = File.join(Snip::INSTALL_DIR, name)
  if Snip::Util::Editor::open(file_path)
    puts "Snippet updated successfully"
  end
end