Class: OracleCloud::Asset

Inherits:
Object
  • Object
show all
Defined in:
lib/oraclecloud/asset.rb

Direct Known Subclasses

IPAssociation, Instance, Orchestration, SSHKey

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, path) ⇒ Asset

Returns a new instance of Asset.



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/oraclecloud/asset.rb', line 22

def initialize(client, path)
  @client     = client
  @asset_data = nil
  @path       = path
  @container  = path.split('/').first

  local_init
  validate!

  fetch
end

Instance Attribute Details

#asset_dataObject (readonly)

Returns the value of attribute asset_data.



20
21
22
# File 'lib/oraclecloud/asset.rb', line 20

def asset_data
  @asset_data
end

#asset_typeObject (readonly)

Returns the value of attribute asset_type.



20
21
22
# File 'lib/oraclecloud/asset.rb', line 20

def asset_type
  @asset_type
end

#clientObject (readonly)

Returns the value of attribute client.



20
21
22
# File 'lib/oraclecloud/asset.rb', line 20

def client
  @client
end

#containerObject (readonly)

Returns the value of attribute container.



20
21
22
# File 'lib/oraclecloud/asset.rb', line 20

def container
  @container
end

#pathObject (readonly)

Returns the value of attribute path.



20
21
22
# File 'lib/oraclecloud/asset.rb', line 20

def path
  @path
end

Instance Method Details

#fetchObject Also known as: refresh



43
44
45
# File 'lib/oraclecloud/asset.rb', line 43

def fetch
  @asset_data = client.single_item(asset_type, path)
end

#full_nameObject



57
58
59
# File 'lib/oraclecloud/asset.rb', line 57

def full_name
  "/Compute-#{client.identity_domain}/#{name_with_container}"
end

#idObject Also known as: name



48
49
50
# File 'lib/oraclecloud/asset.rb', line 48

def id
  asset_data['name'].split('/').last
end

#local_initObject



34
35
36
37
# File 'lib/oraclecloud/asset.rb', line 34

def local_init
  # this should be redefined in each Assets subclass with things like
  # the @asset_type to use in API calls
end

#name_with_containerObject



53
54
55
# File 'lib/oraclecloud/asset.rb', line 53

def name_with_container
  "#{container}/#{id}"
end

#strip_identity_domain(name) ⇒ Object



61
62
63
# File 'lib/oraclecloud/asset.rb', line 61

def strip_identity_domain(name)
  name.gsub("/Compute-#{client.identity_domain}/", '')
end

#validate!Object



39
40
41
# File 'lib/oraclecloud/asset.rb', line 39

def validate!
  raise "#{self.class} did not define an asset_type variable" if asset_type.nil?
end