Class: Webbynode::Commands::Alias
- Inherits:
-
Webbynode::Command
- Object
- Webbynode::Command
- Webbynode::Commands::Alias
- Defined in:
- lib/webbynode/commands/alias.rb
Constant Summary collapse
- FilePath =
".webbynode/aliases"
Constants inherited from Webbynode::Command
Webbynode::Command::Aliases, Webbynode::Command::CommandError, Webbynode::Command::InvalidCommand, Webbynode::Command::InvalidOption, Webbynode::Command::Settings
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#alias ⇒ Object
Returns the value of attribute alias.
-
#command ⇒ Object
Returns the value of attribute command.
-
#session_aliases ⇒ Object
Returns the value of attribute session_aliases.
Instance Method Summary collapse
-
#ensure_aliases_file_exists ⇒ Object
Ensures that the aliases file exists If the file does not exist, it will be created.
- #execute ⇒ Object
-
#exists?(a) ⇒ Boolean
Determines whether an alias already exists inside the session_aliases array.
- #extract_command(a) ⇒ Object
-
#initialize(*args) ⇒ Alias
constructor
A new instance of Alias.
-
#read_aliases_file ⇒ Object
Reads out the aliases file and stores all the aliases inside the session_aliases array.
Methods inherited from Webbynode::Command
add_alias, #api, class_for, command, command_class_name, description, for, #gemfile, #git, help, inherited, #io, #no?, #notify, option, #option, #options, options_help, #param, #param_values, parameter, #params, #params_hash, params_help, #pushand, #remote_executor, requires_initialization!, requires_options!, requires_pushed_application!, #run, #server, setting, #settings, summary, summary_help, usage, #validate_initialization, #validate_options, #yes?
Constructor Details
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
4 5 6 |
# File 'lib/webbynode/commands/alias.rb', line 4 def action @action end |
#alias ⇒ Object
Returns the value of attribute alias.
4 5 6 |
# File 'lib/webbynode/commands/alias.rb', line 4 def alias @alias end |
#command ⇒ Object
Returns the value of attribute command.
4 5 6 |
# File 'lib/webbynode/commands/alias.rb', line 4 def command @command end |
#session_aliases ⇒ Object
Returns the value of attribute session_aliases.
4 5 6 |
# File 'lib/webbynode/commands/alias.rb', line 4 def session_aliases @session_aliases end |
Instance Method Details
#ensure_aliases_file_exists ⇒ Object
Ensures that the aliases file exists If the file does not exist, it will be created
62 63 64 65 66 |
# File 'lib/webbynode/commands/alias.rb', line 62 def ensure_aliases_file_exists unless io.file_exists?(FilePath) io.exec("touch #{FilePath}") end end |
#execute ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/webbynode/commands/alias.rb', line 27 def execute # Reads out the aliases from the aliases file and stores them in session_aliases read_aliases_file # Parses the parameters that were provided by the user parse_parameters # Initializes the specified action send(action) end |
#exists?(a) ⇒ Boolean
Determines whether an alias already exists inside the session_aliases array
51 52 53 54 55 56 57 58 |
# File 'lib/webbynode/commands/alias.rb', line 51 def exists?(a) session_aliases.each do |session_alias| if session_alias =~ /\[(.+)\]/ return true if $1.eql?(a) end end false end |
#extract_command(a) ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/webbynode/commands/alias.rb', line 68 def extract_command(a) session_aliases.each do |session_alias| if session_alias =~ /\[(.+)\] (.+)/ return $2 if a.eql?($1) end end false end |
#read_aliases_file ⇒ Object
Reads out the aliases file and stores all the aliases inside the session_aliases array
41 42 43 44 45 46 47 48 |
# File 'lib/webbynode/commands/alias.rb', line 41 def read_aliases_file @session_aliases = Array.new io.read_file(FilePath).each_line do |line| if line =~ /\[(.+)\] (.+)/ @session_aliases << "[#{$1}] #{$2}" end end end |