Class: Bashy::Add
- Inherits:
-
Object
- Object
- Bashy::Add
- Defined in:
- lib/bashy.rb
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Add
constructor
A new instance of Add.
Constructor Details
#initialize(options = {}) ⇒ Add
Returns a new instance of Add.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/bashy.rb', line 54 def initialize( = {}) # Check that our directories are in tact. Bashy::check_and_load_config_directory # If we haven't been passed the name of the bash snippet, raise an exception. raise(ArgumentError) unless .has_key?(:name) # We're going to do different things here if we're operating on a path or the user wants to enter a snippet of code directly. snippet_path = File.join(SNIPPET_PATH, [:name]) if(![:path].nil?) FileUtils.cp([:path], snippet_path) else(.has_key?(:snippet)) File.open(snippet_path, 'w') do |f| f.write("#!/usr/bin/env bash\n") unless [:snippet] =~ /^#!/ f.write([:snippet]) end FileUtils.chmod(0777, snippet_path) end Bashy.config[:snippets] << [:name] Bashy.save_config end |