Class: Pgai::Resources::Remote::Clone

Inherits:
BaseRecord
  • Object
show all
Defined in:
lib/pgai/resources/remote/clone.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseRecord

client, #client, client=, with_client

Methods included from Attributes

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

Instance Attribute Details

#db_objectObject

Returns the value of attribute db_object.



12
13
14
# File 'lib/pgai/resources/remote/clone.rb', line 12

def db_object
  @db_object
end

#metadataObject

Returns the value of attribute metadata.



15
16
17
# File 'lib/pgai/resources/remote/clone.rb', line 15

def 
  @metadata
end

#snapshotObject

Returns the value of attribute snapshot.



13
14
15
# File 'lib/pgai/resources/remote/clone.rb', line 13

def snapshot
  @snapshot
end

#statusObject

Returns the value of attribute status.



14
15
16
# File 'lib/pgai/resources/remote/clone.rb', line 14

def status
  @status
end

Class Method Details

.find(id) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/pgai/resources/remote/clone.rb', line 18

def find(id)
  data = client.get(File.join(path, id))
  raise Pgai::ResourceNotFound unless data.key?(:id)

  new(data.slice(:id, :protected)) do |resource|
    resource.refresh_attributes(data)
  end
end

.pathObject



27
28
29
# File 'lib/pgai/resources/remote/clone.rb', line 27

def path
  "clone"
end

Instance Method Details

#deleteObject



65
66
67
68
69
70
# File 'lib/pgai/resources/remote/clone.rb', line 65

def delete
  data = client.delete(object_path)
  refresh_attributes(data) unless data.empty?

  self
end

#ready?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/pgai/resources/remote/clone.rb', line 52

def ready?
  status.code == "OK"
end

#refreshObject



56
57
58
59
60
61
62
63
# File 'lib/pgai/resources/remote/clone.rb', line 56

def refresh
  data = client.get(object_path)
  raise Pgai::ResourceNotFound unless data.key?(:id)

  refresh_attributes(data)

  self
end

#refresh_attributes(data) ⇒ Object



78
79
80
81
82
83
84
# File 'lib/pgai/resources/remote/clone.rb', line 78

def refresh_attributes(data)
  assign_attributes(data.slice(:delete_at, :created_at))
  .refresh_attributes(data.fetch(:metadata))
  ensure_status.refresh_attributes(data.fetch(:status))
  ensure_db_object.refresh_attributes(data.fetch(:db))
  ensure_snapshot.refresh_attributes(data.fetch(:snapshot))
end

#resetObject



72
73
74
75
76
# File 'lib/pgai/resources/remote/clone.rb', line 72

def reset
  client.post(object_path("reset"))

  self
end

#saveObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/pgai/resources/remote/clone.rb', line 32

def save
  body = {
    id: id,
    snapshot: {
      id: snapshot.id
    },
    protected: protected,
    db: {
      username: db_object.username,
      password: db_object.password,
      restricted: db_object.restricted
    }
  }

  data = client.post(self.class.path, body)
  refresh_attributes(data)

  self
end

#status_messageObject



86
87
88
# File 'lib/pgai/resources/remote/clone.rb', line 86

def status_message
  status&.message
end