Module: Kontena::Cli::Models::CloudApiModel

Included in:
ImageRepo, ImageTag, Node, Organization, Platform
Defined in:
lib/kontena/cli/models/cloud_api_model.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/kontena/cli/models/cloud_api_model.rb', line 14

def method_missing(method, *args, &block)
  key = method.to_s.gsub('_', '-')

  return api_data['attributes'].has_key?(key) && api_data['attributes'][key] if key.end_with?('?'.freeze)

  if api_data['attributes'].has_key?(key)
    api_data['attributes'][key]
  else
    raise ArgumentError.new("Method `#{m}` doesn't exist.")
  end
end

Instance Attribute Details

#api_dataObject (readonly)

Returns the value of attribute api_data.



4
5
6
# File 'lib/kontena/cli/models/cloud_api_model.rb', line 4

def api_data
  @api_data
end

Instance Method Details

#idObject



10
11
12
# File 'lib/kontena/cli/models/cloud_api_model.rb', line 10

def id
  api_data['id']
end

#initialize(api_data) ⇒ Object



6
7
8
# File 'lib/kontena/cli/models/cloud_api_model.rb', line 6

def initialize(api_data)
  @api_data = api_data || {}
end