Class: Hcloud::Future

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

Instance Method Summary collapse

Constructor Details

#initialize(client, target_class, id) ⇒ Future

rubocop: disable Lint/MissingSuper



8
9
10
11
12
# File 'lib/hcloud/future.rb', line 8

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

Instance Method Details

#__getobj__Object

rubocop: enable Lint/MissingSuper



15
16
17
18
19
20
21
22
23
24
# File 'lib/hcloud/future.rb', line 15

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