Class: Pgai::Resources::Local::Environment

Inherits:
BaseRecord
  • Object
show all
Defined in:
lib/pgai/resources/local/environment.rb

Instance Method Summary collapse

Methods inherited from BaseRecord

all, backend, delete, #delete, find, #klass, record_type, #save

Methods included from Attributes

#assign_attribute, #assign_attributes, #has_attribute?, included, #initialize

Instance Method Details

#clientObject



15
16
17
18
19
20
# File 'lib/pgai/resources/local/environment.rb', line 15

def client
  @client ||= Pgai::Client.new(
    token: access_token,
    host: "http://127.0.0.1:#{local_port}"
  )
end

#clone_idObject



44
45
46
# File 'lib/pgai/resources/local/environment.rb', line 44

def clone_id
  @clone_id ||= "#{clone_prefix}_#{self.alias}"
end

#expected_cloning_timeObject



36
37
38
# File 'lib/pgai/resources/local/environment.rb', line 36

def expected_cloning_time
  @expected_cloning_time ||= client.expected_cloning_time
end

#local_portObject



40
41
42
# File 'lib/pgai/resources/local/environment.rb', line 40

def local_port
  @local_port ||= Port::Allocator.pick
end

#prepareObject



22
23
24
25
26
27
28
# File 'lib/pgai/resources/local/environment.rb', line 22

def prepare
  with_port_forward do
    Resources::Remote::BaseRecord.with_client(client) do
      yield(self)
    end
  end
end

#with_port_forward(manager = Pgai::Commander.instance.port_manager) ⇒ Object



30
31
32
33
34
# File 'lib/pgai/resources/local/environment.rb', line 30

def with_port_forward(manager = Pgai::Commander.instance.port_manager)
  manager.forward(local_port, id, port) do
    yield self
  end
end