Class: StackFu::App

Inherits:
Object
  • Object
show all
Includes:
ApiHooks, Rendering
Defined in:
lib/stackfu/app.rb

Constant Summary

Constants included from Rendering

Rendering::LEFT_MARGIN

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ApiHooks

#initialize_api

Methods included from Rendering

#done, #error, #fill_values_from_options, #menu_for, #render_target, #spinner, #table, #warning

Constructor Details

#initialize(args) ⇒ App

Returns a new instance of App.



7
8
9
# File 'lib/stackfu/app.rb', line 7

def initialize(args)
  @args = args
end

Instance Attribute Details

#argsObject

Returns the value of attribute args.



5
6
7
# File 'lib/stackfu/app.rb', line 5

def args
  @args
end

Class Method Details

.settings?Boolean

Returns:



75
76
77
# File 'lib/stackfu/app.rb', line 75

def self.settings?
  File.exists?(StackFu::CONFIG_FILE)
end

Instance Method Details

#executeObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/stackfu/app.rb', line 19

def execute
  begin
    command = @args.delete_at(0)
    cmd = Commands::Command.create(command, @args)
    cmd.run
  rescue Errno::ECONNREFUSED
    error "Could not connect to StackFu server.",
      "Please check if your internet connection is active. If you think this problem is not in your end, please report it by emailing [email protected] or try again in a few minutes."
    raise if $dev

  rescue ActiveResource::ClientError
    error "There was an error contacting StackFu backend: #{$!.message}.",
      "Please report this problem at [email protected] or try again in a few minutes."
    raise if $dev
    
  rescue ActiveResource::ServerError
    error "There was an error contacting StackFu backend: #{$!.message}.",
      "Please report this problem at [email protected] or try again in a few minutes."
    raise if $dev

  rescue ActiveResource::UnauthorizedAccess
    error "Access denied for user '#{$config[:login]}'",
      "Please check the credentials provided on file #{ENV['HOME']}/.stackfu and run 'stackfu config' for changing it."
    raise if $dev

  rescue ActiveResource::ResourceNotFound
    error "There was an internal error contacting StackFu backend.",
      "Please report this problem at [email protected] or try again in a few minutes."
    raise if $dev

  rescue Commands::Exceptions::UnknownCommand
    error "Command #{command} does not exist", "Try using 'stackfu help' for a summary of available commands."
    
  rescue Commands::Exceptions::InvalidCommand
    error "Command #{command} is invalid", $!.message
    
  rescue Commands::Exceptions::InvalidSubcommand
    error "Invalid usage for command #{command}", $!.message
  end
end

#load_configObject



71
72
73
# File 'lib/stackfu/app.rb', line 71

def load_config
  YAML.load(File.read(StackFu::CONFIG_FILE))
end

#startObject



11
12
13
14
15
16
17
# File 'lib/stackfu/app.rb', line 11

def start
  welcome and return unless App.settings?
  $config = load_config
  initialize_api($config)
  
  execute
end

#welcomeObject



60
61
62
63
64
65
66
67
68
69
# File 'lib/stackfu/app.rb', line 60

def welcome
  puts "== StackFu Initial Configuration ==".bright.color(:green)
  puts ""
  puts "It seems this is the first time you use #{"StackFu".foreground(:yellow)} from the command line."
  puts ""
  puts "To get you up to speed, we need you to provide us a couple of configuration settings that will follow."
  puts
  Commands::ConfigCommand.new.run
  true
end