Class: Hcloud::Future

Inherits:
Delegator
  • Object
show all
Defined in:
lib/hcloud/future.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, target_class, id, raw_data: nil) ⇒ Future

rubocop: disable Lint/MissingSuper



10
11
12
13
14
15
# File 'lib/hcloud/future.rb', line 10

def initialize(client, target_class, id, raw_data: nil)
  @target_class = target_class
  @id = id
  @raw_data = raw_data
  @__client = client
end

Instance Attribute Details

#raw_dataObject (readonly)

Returns the value of attribute raw_data.



7
8
9
# File 'lib/hcloud/future.rb', line 7

def raw_data
  @raw_data
end

Instance Method Details

#__getobj__Object

rubocop: enable Lint/MissingSuper



18
19
20
21
22
23
24
25
26
27
# File 'lib/hcloud/future.rb', line 18

def __getobj__
  # pluralize class name and convert it to symbol
  @__getobj__ ||= @__client.public_send(
    @target_class.name # full name of the class including namespaces
                 .demodulize # last module name only
                 .tableize # convert to table name, split words by _ + downcase
                 .pluralize
                 .to_sym
  ).find(@id)
end