Class: Zedkit::CLI::Runner
- Inherits:
-
Object
- Object
- Zedkit::CLI::Runner
- Defined in:
- lib/zedkit/cli/runner.rb
Constant Summary collapse
- SECTIONS =
['projects']
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#locale ⇒ Object
Returns the value of attribute locale.
-
#password ⇒ Object
Returns the value of attribute password.
-
#section ⇒ Object
readonly
Returns the value of attribute section.
-
#user_key ⇒ Object
Returns the value of attribute user_key.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
- #go! ⇒ Object
- #has_command? ⇒ Boolean
- #has_credentials? ⇒ Boolean
- #has_items? ⇒ Boolean
- #has_password? ⇒ Boolean
- #has_section? ⇒ Boolean
- #has_user_key? ⇒ Boolean
- #has_username? ⇒ Boolean
-
#initialize ⇒ Runner
constructor
A new instance of Runner.
- #items_to_key_value_hash ⇒ Object
Constructor Details
#initialize ⇒ Runner
Returns a new instance of Runner.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/zedkit/cli/runner.rb', line 26 def initialize @user_key, @username, @password = nil, nil, nil @locale = :en @config = File.('~') << "/.zedkit" if !ARGV.empty? && ARGV[0].include?(":") @section = ARGV[0].split(":")[0] @command = ARGV[0].split(":")[1] else @section = SECTIONS[0] ARGV.empty? ? @command = nil : @command = ARGV[0] end ARGV.shift begin set_credentials if has_section? && has_command? set_items rescue Zedkit::CLI::ZedkitError => zke puts zke end end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
22 23 24 |
# File 'lib/zedkit/cli/runner.rb', line 22 def command @command end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
22 23 24 |
# File 'lib/zedkit/cli/runner.rb', line 22 def config @config end |
#items ⇒ Object (readonly)
Returns the value of attribute items.
22 23 24 |
# File 'lib/zedkit/cli/runner.rb', line 22 def items @items end |
#locale ⇒ Object
Returns the value of attribute locale.
21 22 23 |
# File 'lib/zedkit/cli/runner.rb', line 21 def locale @locale end |
#password ⇒ Object
Returns the value of attribute password.
21 22 23 |
# File 'lib/zedkit/cli/runner.rb', line 21 def password @password end |
#section ⇒ Object (readonly)
Returns the value of attribute section.
22 23 24 |
# File 'lib/zedkit/cli/runner.rb', line 22 def section @section end |
#user_key ⇒ Object
Returns the value of attribute user_key.
21 22 23 |
# File 'lib/zedkit/cli/runner.rb', line 21 def user_key @user_key end |
#username ⇒ Object
Returns the value of attribute username.
21 22 23 |
# File 'lib/zedkit/cli/runner.rb', line 21 def username @username end |
Instance Method Details
#go! ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/zedkit/cli/runner.rb', line 74 def go! begin if has_section? && has_command? if has_credentials? unless has_user_key? @user_key = Zedkit::Users.verify(:login => username, :password => password)['user_key'] end run else raise Zedkit::CLI::MissingCredentials.new(:message => Zedkit::CLI.ee(locale, :runner, :credentials)) end else puts commands end rescue Zedkit::ZedkitError => zke puts zke end end |
#has_command? ⇒ Boolean
61 62 63 |
# File 'lib/zedkit/cli/runner.rb', line 61 def has_command? not command.nil? end |
#has_credentials? ⇒ Boolean
54 55 56 |
# File 'lib/zedkit/cli/runner.rb', line 54 def has_credentials? has_user_key? || (has_username? && has_password?) end |
#has_items? ⇒ Boolean
65 66 67 |
# File 'lib/zedkit/cli/runner.rb', line 65 def has_items? items && items.length > 0 end |
#has_password? ⇒ Boolean
51 52 53 |
# File 'lib/zedkit/cli/runner.rb', line 51 def has_password? password && password.is_a?(String) && !password.nil? end |
#has_section? ⇒ Boolean
58 59 60 |
# File 'lib/zedkit/cli/runner.rb', line 58 def has_section? not section.nil? end |
#has_user_key? ⇒ Boolean
45 46 47 |
# File 'lib/zedkit/cli/runner.rb', line 45 def has_user_key? user_key && user_key.is_a?(String) && !user_key.nil? end |
#has_username? ⇒ Boolean
48 49 50 |
# File 'lib/zedkit/cli/runner.rb', line 48 def has_username? username && username.is_a?(String) && !username.nil? end |
#items_to_key_value_hash ⇒ Object
68 69 70 71 72 |
# File 'lib/zedkit/cli/runner.rb', line 68 def items_to_key_value_hash rh = {} items.each {|item| rh[item.split('=')[0]] = item.split('=')[1] if item.include?('=') } if has_items? rh end |