Class: Pgai::Commander

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Singleton
Defined in:
lib/pgai/commander.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCommander

Returns a new instance of Commander.



23
24
25
# File 'lib/pgai/commander.rb', line 23

def initialize
  self.verbosity = :info
end

Instance Attribute Details

#verbosityObject

Returns the value of attribute verbosity.



8
9
10
# File 'lib/pgai/commander.rb', line 8

def verbosity
  @verbosity
end

Class Method Details

.configure(options) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/pgai/commander.rb', line 11

def self.configure(options)
  instance.tap do |commander|
    if options[:verbose]
      commander.verbosity = :debug
    end

    if options[:quiet]
      commander.verbosity = :error
    end
  end
end

Instance Method Details

#check_access_token_presence!Object



55
56
57
# File 'lib/pgai/commander.rb', line 55

def check_access_token_presence!
  raise "Access token is not set" unless config&.access_token
end

#configObject



31
32
33
# File 'lib/pgai/commander.rb', line 31

def config
  @config ||= Pgai::Resources::Local::Configuration.default
end

#configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



35
36
37
# File 'lib/pgai/commander.rb', line 35

def configure
  yield self
end

#loggerObject



47
48
49
# File 'lib/pgai/commander.rb', line 47

def logger
  @logger ||= TTY::Logger.new
end

#port_managerObject



51
52
53
# File 'lib/pgai/commander.rb', line 51

def port_manager
  @port_manager ||= Port::Manager.new(logger: logger)
end

#storeObject



27
28
29
# File 'lib/pgai/commander.rb', line 27

def store
  @store ||= Pgai::Store.new(key: Pgai::Encryption::Key.new.read)
end

#with_env(env_name, &block) ⇒ Object



59
60
61
62
63
64
65
66
67
68
# File 'lib/pgai/commander.rb', line 59

def with_env(env_name, &block)
  check_access_token_presence!

  env = Resources::Local::Environment.find(env_name) do |env|
    env.access_token = config.access_token
    env.clone_prefix = config.clone_prefix
  end

  env.prepare(&block)
end