Class: EPC::Command::BaseCommand

Inherits:
Object
  • Object
show all
Includes:
Error, PersistentAttributes
Defined in:
lib/epc/command/base_command.rb

Direct Known Subclasses

ArchiveCommand, AttachtoCommand, BuildCommand, CopyCommand, CreateCommand, CreateConfigCommand, CreateGroupCommand, CreateLibraryCommand, CreateLibrarylanguageCommand, CreateLibrarysetCommand, CreateObjectroleCommand, CreateProjectCommand, CreateRoleCommand, CreateServicedefinitionCommand, CreateSolutionCommand, CreateUserCommand, DeleteCommand, DeleteLibraryCommand, DeleteProjectCommand, DeleteServicedefinitionCommand, DeployCommand, DetachfromCommand, GetUserPropertyCommand, InfoCommand, ListCommand, ListDeploymentsCommand, ListDeploymentstagesCommand, ListGroupsCommand, ListLibrariesCommand, ListLibrarylanguagesCommand, ListMetricsCommand, ListObjectrolesCommand, ListObjecttypesCommand, ListPermissiongroupsCommand, ListPermissionsCommand, ListPluginsCommand, ListProjectsCommand, ListProjecttypesCommand, ListRolesCommand, ListRuntimesCommand, ListServicedefinitionsCommand, ListServicetypesCommand, ListServiceversionsCommand, ListSolutionsCommand, ListUserpropertiesCommand, ListUsersCommand, LoginCommand, LogoutCommand, PullCommand, PushCommand, RefreshSolutionCommand, RenewCommand, RequestPasswordchangeCommand, SetUserPropertyCommand, ShowCommand, ShowGroupCommand, ShowInstancesCommand, ShowLibrarysetCommand, ShowMetricsCommand, ShowProjecttypeCommand, SubmitCommand, TargetCommand, UnarchiveCommand, UndeployCommand, UpdateCommand, UpdateDeploymentCommand, UpdateGroupCommand, UpdateLibrarysetCommand, UpdateProjectCommand, UpdateSolutionCommand, UpdateUserCommand, VoteCommand

Constant Summary collapse

SLEEP_TIME =
1
TICKER_TICKS =

Numerators are in secs

25/SLEEP_TIME
GIVEUP_TICKS =
120/SLEEP_TIME
@@required_options =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from PersistentAttributes

#auth_token, #caller_id, #target_url

Constructor Details

#initialize(client, options = {}) ⇒ BaseCommand

Returns a new instance of BaseCommand.



48
49
50
51
52
53
54
# File 'lib/epc/command/base_command.rb', line 48

def initialize(client, options = {})
  @client = client
  @options = options.dup
  if @options[:skip_prompts].present?
    create_method(:ask) {|text, arr| return "Y"}
  end
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



11
12
13
# File 'lib/epc/command/base_command.rb', line 11

def client
  @client
end

#klass_nameObject



86
87
88
89
# File 'lib/epc/command/base_command.rb', line 86

def klass_name
  return self.class.name if @klass_name.blank?
  @klass_name
end

#object_idObject

Returns the value of attribute object_id.



15
16
17
# File 'lib/epc/command/base_command.rb', line 15

def object_id
  @object_id
end

#object_typeObject

Returns the value of attribute object_type.



14
15
16
# File 'lib/epc/command/base_command.rb', line 14

def object_type
  @object_type
end

#optionsObject (readonly)

Returns the value of attribute options.



12
13
14
# File 'lib/epc/command/base_command.rb', line 12

def options
  @options
end

#target_idObject

Returns the value of attribute target_id.



17
18
19
# File 'lib/epc/command/base_command.rb', line 17

def target_id
  @target_id
end

#target_typeObject

Returns the value of attribute target_type.



16
17
18
# File 'lib/epc/command/base_command.rb', line 16

def target_type
  @target_type
end

Class Method Details

.include_module(object_type) ⇒ Object



41
42
43
44
45
46
# File 'lib/epc/command/base_command.rb', line 41

def self.include_module(object_type)
  mod = object_type.capitalize
  if EPC::Config.module_exists?(mod)
    self.send :include, eval("EPC::Command::#{mod}")
  end
end

.inherited(subklass) ⇒ Object



28
29
30
31
# File 'lib/epc/command/base_command.rb', line 28

def self.inherited(subklass)
  # Here login is required for all commands that inherit
  subklass.
end

.required_options(*opts, opt_hash) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/epc/command/base_command.rb', line 33

def self.required_options(*opts, opt_hash)
  options_hash = {
    :mode => :any?,
    :message => "You need to specify all required options"
  }.merge(opt_hash)
  @@required_options << {:name => opts, :mode => options_hash[:mode], :message => options_hash[:message]}
end

Instance Method Details

#check_optionsObject



71
72
73
74
75
76
# File 'lib/epc/command/base_command.rb', line 71

def check_options
  @@required_options.each do |req_opt|
    raise FatalError, req_opt[:message] unless req_opt[:name].map{|opt| @options[opt].present?}.send(req_opt[:mode])

  end	
end

#context_paramsObject



78
79
80
# File 'lib/epc/command/base_command.rb', line 78

def context_params
  return [object_type, object_id, target_type, target_id]
end

#context_params=(params) ⇒ Object



82
83
84
# File 'lib/epc/command/base_command.rb', line 82

def context_params=(params)
  @object_type, @object_id, @target_type, @target_id = params
end

#go(*args) ⇒ Object



56
57
58
59
60
61
62
63
64
# File 'lib/epc/command/base_command.rb', line 56

def go(*args)
  if () && (!logged_in?)
    say("You must be logged in to run this command")
    return 1
  else
    check_options
    return translate_status_to_exit_code(execute(*args))
  end
end

#say_err(statement) ⇒ Object



66
67
68
# File 'lib/epc/command/base_command.rb', line 66

def say_err(statement)
  EPC::Config.say_err(statement)
end