Parent

DeltaCloud::BaseObject

BaseObject model basically provide the basic operation around REST model, like defining a links between different objects, element with text values, or collection of these elements

Attributes

base_name[R]
client[R]
id[R]
objects[R]
uri[R]
url[R]

Public Class Methods

new(opts={}, &block) click to toggle source

For initializing new object you require to set id, url, client and name attribute.

# File lib/base_object.rb, line 34
def initialize(opts={}, &block)
  @id, @url, @client, @base_name = opts[:id], opts[:url], opts[:client], opts[:name]
  @objects = []
  raise BaseObjectParamError if @id.nil? or @url.nil? or @client.nil? or @base_name.nil?
  yield self if block_given?
end

Public Instance Methods

add_addresses!(collection_name, values=[]) click to toggle source

This method define collection of text elements inside REST model XML syntax: <addresses>

  <address>127.0.0.1</address>
  <address>127.0.0.2</address>
</addresses>
# File lib/base_object.rb, line 100
def add_addresses!(collection_name, values=[])
  @objects << {
    :type => :collection,
    :method_name => collection_name.sanitize,
    :values => values.collect { |v| { :address => v.text.strip, :type => v[:type] }}
  }
end
add_authentication!(auth_type, values=[]) click to toggle source
# File lib/base_object.rb, line 79
def add_authentication!(auth_type, values=[])
  value = { :key => (values/'login/keyname').text.strip } if auth_type == 'key'
  if auth_type == 'password'
    value = {
      :username => (values/'login/username').text.strip,
      :username => (values/'login/password').text.strip
    }
  end
  @objects << {
    :type => :collection,
    :method_name => 'authentication',
    :values => value
  }
end
add_blob!(blob_name) click to toggle source

This method adds blobs to the blob_list property of a bucket

# File lib/base_object.rb, line 147
def add_blob!(blob_name)
  if @blob_list.nil?
    @blob_list = [blob_name]
    @objects << {
      :type => :list,
      :method_name => "blob_list",
      :value => @blob_list
    }
  else
    @blob_list << blob_name
    current = search_for_method('blob_list')
    current[:value] = @blob_list
  end
end
add_collection!(collection_name, values=[]) click to toggle source

This method define collection of text elements inside REST model XML syntax: <addresses>

  <address>127.0.0.1</address>
  <address>127.0.0.2</address>
</addresses>
# File lib/base_object.rb, line 113
def add_collection!(collection_name, values=[])
  @objects << {
    :type => :collection,
    :method_name => collection_name.sanitize,
    :values => values
  }
end
add_hwp_property!(name, property, type) click to toggle source

Method add property for hardware profile

# File lib/base_object.rb, line 57
def add_hwp_property!(name, property, type)
  hwp_property=case type
    when :float then DeltaCloud::HWP::FloatProperty.new(property, name)
    when :integer then DeltaCloud::HWP::Property.new(property, name)
  end
  @objects << {
    :type => :property,
    :method_name => name.sanitize,
    :property => hwp_property
  }
end
add_text!(object_name, value) click to toggle source

This method define text object in REST model XML syntax: <name>Instance 1</name>

# File lib/base_object.rb, line 71
def add_text!(object_name, value)
  @objects << {
    :type => :text,
    :method_name => object_name.sanitize,
    :value => value
  }
end
method_handler(m, args=[]) click to toggle source

Basic method hander. This define a way how value from property will be returned

# File lib/base_object.rb, line 123
def method_handler(m, args=[])
  case m[:type]
    when :link then return @client.send(m[:method_name].singularize, m[:id])
    when :text then return m[:value]
    when :property then return m[:property]
    when :collection then return m[:values]
    when :list then return m[:value].join(", ")
    else raise NoHandlerForMethod
  end
end
method_missing(method_name, *args) click to toggle source
# File lib/base_object.rb, line 134
def method_missing(method_name, *args)
  # First of all search throught array for method name
  m = search_for_method(method_name)
  if m.nil?
    super
  else
    # Call appropriate handler for method
    method_handler(m, args)
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.