Class: Callstacking::Rails::Setup

Inherits:
Object
  • Object
show all
Defined in:
lib/callstacking/rails/setup.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSetup

Returns a new instance of Setup.



9
10
11
# File 'lib/callstacking/rails/setup.rb', line 9

def initialize
  @settings = Callstacking::Rails::Settings.new
end

Instance Attribute Details

#settingsObject

Returns the value of attribute settings.



7
8
9
# File 'lib/callstacking/rails/setup.rb', line 7

def settings
  @settings
end

Class Method Details

.instructionsObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/callstacking/rails/setup.rb', line 41

def self.instructions
  puts "loading environment #{Callstacking::Rails::Env.environment}"
  puts
  puts "Usage: "
  puts
  puts "  > callstacking-rails register"
  puts
  puts "    Opens a browser window to register as a callstacking.com user."
  puts
  puts "  > callstacking-rails setup"
  puts
  puts "    Interactively prompts you for your callstacking.com username/password."
  puts "    Stores auth details in #{Callstacking::Rails::Settings::SETTINGS_FILE}"
  puts
  puts "  > callstacking-rails enable"
  puts
  puts "    Enables the callstacking tracing."
  puts
  puts "  > callstacking-rails disable"
  puts
  puts "    Disables the callstacking tracing."
  puts
  puts " You can have multiple environments."
  puts " The default is #{Callstacking::Rails::Env::DEFAULT_ENVIRONMENT}."
  puts
  puts " The #{Callstacking::Rails::Env.environment}: section in the #{Callstacking::Rails::Settings::SETTINGS_FILE} contains your credentials."
  puts " By setting the RAILS_ENV environment you can maintain multiple settings."
  puts
  puts "Questions? Create an issue: https://github.com/callstacking/callstacking-rails/issues"
  
  :instructions
end

Instance Method Details

#prompt(label, echo: true) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/callstacking/rails/setup.rb', line 31

def prompt(label, echo: true)
  puts label

  value = echo ? STDIN.gets.chomp : STDIN.noecho(&:gets).chomp
  puts

  return nil if value == ''
  value
end

#startObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/callstacking/rails/setup.rb', line 13

def start
  puts "Login to callstacking.com"
  puts
  
  email      = prompt("Enter email:", echo: true)
  password   = prompt("Enter password:", echo: false)

  settings.save(email, password, url)

  puts "Authentication successful."
  puts "Settings saved to #{Callstacking::Rails::Settings::SETTINGS_FILE}"
  true
rescue StandardError => e
  puts "Error authenticating: #{e.message}"
  puts e.backtrace.join("\n")
  false
end