Class: Zedkit::CLI::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/zedkit/cli/runner.rb

Constant Summary collapse

SECTIONS =
['projects']

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRunner

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.expand_path('~') << "/.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

#commandObject (readonly)

Returns the value of attribute command.



22
23
24
# File 'lib/zedkit/cli/runner.rb', line 22

def command
  @command
end

#configObject (readonly)

Returns the value of attribute config.



22
23
24
# File 'lib/zedkit/cli/runner.rb', line 22

def config
  @config
end

#itemsObject (readonly)

Returns the value of attribute items.



22
23
24
# File 'lib/zedkit/cli/runner.rb', line 22

def items
  @items
end

#localeObject

Returns the value of attribute locale.



21
22
23
# File 'lib/zedkit/cli/runner.rb', line 21

def locale
  @locale
end

#passwordObject

Returns the value of attribute password.



21
22
23
# File 'lib/zedkit/cli/runner.rb', line 21

def password
  @password
end

#sectionObject (readonly)

Returns the value of attribute section.



22
23
24
# File 'lib/zedkit/cli/runner.rb', line 22

def section
  @section
end

#user_keyObject

Returns the value of attribute user_key.



21
22
23
# File 'lib/zedkit/cli/runner.rb', line 21

def user_key
  @user_key
end

#usernameObject

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

Returns:

  • (Boolean)


61
62
63
# File 'lib/zedkit/cli/runner.rb', line 61

def has_command?
  not command.nil?
end

#has_credentials?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


65
66
67
# File 'lib/zedkit/cli/runner.rb', line 65

def has_items?
  items && items.length > 0
end

#has_password?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


58
59
60
# File 'lib/zedkit/cli/runner.rb', line 58

def has_section?
  not section.nil?
end

#has_user_key?Boolean

Returns:

  • (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

Returns:

  • (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_hashObject



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