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



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

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

#clone_idObject



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

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

#expected_cloning_timeObject



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

def expected_cloning_time
  @expected_cloning_time ||= client.expected_cloning_time
end

#local_portObject



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

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

#prepareObject



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

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



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

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