Class: AppSendr::Command::Base

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/appsendr/commands/base.rb

Direct Known Subclasses

App, Auth, Build, Groups, Help, Portal, Testers, Version

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

#argsObject

Returns the value of attribute args.



14
15
16
# File 'lib/appsendr/commands/base.rb', line 14

def args
  @args
end

#autodetected_appObject (readonly)

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

#appsendrObject



36
37
38
# File 'lib/appsendr/commands/base.rb', line 36

def appsendr
  @appsendr ||= AppSendr::Command.run_internal('auth:client', args)
end

#askObject



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

#extract_app(force = true) ⇒ Object

Raises:



40
41
42
43
44
45
46
47
48
49
# File 'lib/appsendr/commands/base.rb', line 40

def extract_app(force=true)
  app = extract_option('--app', false)
  raise(CommandFailed, "You must specify an app name after --app") if app == false
  unless app
    app = extract_app_in_dir(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

#extract_option(options, default = true) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/appsendr/commands/base.rb', line 59

def extract_option(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

#format_date(date) ⇒ Object



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

Returns:

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