Class: Snippit::CLI::Save
- Inherits:
-
Object
- Object
- Snippit::CLI::Save
- Defined in:
- lib/snippit/cli/save.rb
Overview
Snippit::CLI::Save saves a new snippet, or overwrites an existing one.
Instance Method Summary collapse
-
#initialize(path, force: false, name: nil, slug: nil) ⇒ Save
constructor
Initializes a new Save subcommand.
-
#start ⇒ Integer
Starts the save subcommand.
Methods included from Slugify
Methods included from IO
#definitions, #definitions_file, #delete_snippet, #filepath!, #read_snippet, #snippit_dir, #snippit_dir!, #write_definition, #write_snippet
Constructor Details
#initialize(path, force: false, name: nil, slug: nil) ⇒ Save
Initializes a new Save subcommand.
18 19 20 21 22 23 |
# File 'lib/snippit/cli/save.rb', line 18 def initialize(path, force: false, name: nil, slug: nil) @force = force @path = path @name = name @slug = slug end |
Instance Method Details
#start ⇒ Integer
Starts the save subcommand.
28 29 30 31 32 33 |
# File 'lib/snippit/cli/save.rb', line 28 def start base_name = File.basename(@path) slug = @slug || slugify(base_name) handle(slug) { write_snippet(@name || base_name, slug, File.read(@path), @force) } end |