Class: AppSendr::Command::Base
- Inherits:
-
Object
- Object
- AppSendr::Command::Base
show all
- Includes:
- Helpers
- Defined in:
- lib/appsendr/commands/base.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Helpers
#credentials_file, #credentials_setup?, #display, #error, #has_project_droppr?, #home_directory, #in_project_dir?, #is_file_to_large?, #message, #project_appsendr, #project_appsendr_app, #read_app, #read_app_id, #require_in_project_and_no_droppr, #require_project, #require_project_dir, #require_project_droppr, #running_on_a_mac?, #running_on_windows?, #size_of_file
Constructor Details
#initialize(args, appsendr = nil) ⇒ Base
Returns a new instance of Base.
16
17
18
19
20
|
# File 'lib/appsendr/commands/base.rb', line 16
def initialize(args, appsendr=nil)
@args = args
@appsendr = appsendr
@autodetected_app = false
end
|
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
14
15
16
|
# File 'lib/appsendr/commands/base.rb', line 14
def args
@args
end
|
#autodetected_app ⇒ Object
Returns the value of attribute autodetected_app.
15
16
17
|
# File 'lib/appsendr/commands/base.rb', line 15
def autodetected_app
@autodetected_app
end
|
Instance Method Details
#appsendr ⇒ Object
36
37
38
|
# File 'lib/appsendr/commands/base.rb', line 36
def appsendr
@appsendr ||= AppSendr::Command.run_internal('auth:client', args)
end
|
#ask ⇒ Object
32
33
34
|
# File 'lib/appsendr/commands/base.rb', line 32
def ask
gets.strip
end
|
#confirm(message = "Are you sure you wish to continue? (y/n)?") ⇒ Object
22
23
24
25
|
# File 'lib/appsendr/commands/base.rb', line 22
def confirm(message="Are you sure you wish to continue? (y/n)?")
display("#{message} ", false)
ask.downcase == 'y'
end
|
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/appsendr/commands/base.rb', line 40
def (force=true)
app = ('--app', false)
raise(CommandFailed, "You must specify an app name after --app") if app == false
unless app
app = (Dir.pwd) ||
raise(CommandFailed, "No app specified.\nRun this command from app folder or set it adding --app <app name>") if force
@autodetected_app = true
end
app
end
|
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/appsendr/commands/base.rb', line 59
def (options, default=true)
values = options.is_a?(Array) ? options : [options]
return unless opt_index = args.select { |a| values.include? a }.first
opt_position = args.index(opt_index) + 1
if args.size > opt_position && opt_value = args[opt_position]
if opt_value.include?('--')
opt_value = nil
else
args.delete_at(opt_position)
end
end
opt_value ||= default
args.delete(opt_index)
block_given? ? yield(opt_value) : opt_value
end
|
27
28
29
30
|
# File 'lib/appsendr/commands/base.rb', line 27
def format_date(date)
date = Time.parse(date) if date.is_a?(String)
date.strftime("%Y-%m-%d %H:%M %Z")
end
|
#option_exists?(options, default = true) ⇒ Boolean
51
52
53
54
55
56
|
# File 'lib/appsendr/commands/base.rb', line 51
def option_exists?(options, default=true)
values = options.is_a?(Array) ? options : [options]
return false unless opt_index = args.select { |a| values.include? a }.first
args.delete(opt_index)
return true
end
|