Class: Eso::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/eso/configuration/configuration.rb

Overview

This class represents the Configuration that is sent to the server for new style Discovery Connections.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service_name:, config_name:, properties: [], config_id:) ⇒ Configuration

Returns a new instance of Configuration.



7
8
9
10
11
12
# File 'lib/eso/configuration/configuration.rb', line 7

def initialize(service_name:, config_name:, properties:[], config_id:)
  @service_name = service_name
  @config_name = config_name
  @properties = properties
  @config_id = config_id
end

Instance Attribute Details

#config_idObject

Returns the value of attribute config_id.



5
6
7
# File 'lib/eso/configuration/configuration.rb', line 5

def config_id
  @config_id
end

#config_nameObject

Returns the value of attribute config_name.



5
6
7
# File 'lib/eso/configuration/configuration.rb', line 5

def config_name
  @config_name
end

#propertiesObject

Returns the value of attribute properties.



5
6
7
# File 'lib/eso/configuration/configuration.rb', line 5

def properties
  @properties
end

#service_nameObject

Returns the value of attribute service_name.



5
6
7
# File 'lib/eso/configuration/configuration.rb', line 5

def service_name
  @service_name
end

Class Method Details

.load(hash) ⇒ Configuration

Load a Configuration object from a Hash

Parameters:

  • hash (Hash)

    The Hash containing the Configuration object

Returns:

  • (Configuration)

    The Configuration object which was in the Hash



63
64
65
66
67
68
69
70
71
# File 'lib/eso/configuration/configuration.rb', line 63

def self.load(hash)
  configuration = self.new(service_name: hash[:serviceName],
                           config_name: hash[:configName],
                           config_id: hash[:configID])
  hash[:configurationAttributes][:properties].each do |prop|
    configuration.properties << ConfigurationAttribute.load(prop)
  end
  configuration
end

Instance Method Details

#delete_property(name) ⇒ Object

Delete a Configuration attribute property value given the name of the property

Parameters:

  • name (String)

    The name of the property to update



55
56
57
# File 'lib/eso/configuration/configuration.rb', line 55

def delete_property(name)
  properties.delete_if{|attr| attr.property == name}
end

#property(name) ⇒ String

Retrieve a Configuration attribute property value given the name of the property

Parameters:

  • name (String)

    The name of the property to retrieve

Returns:

  • (String)

    The value of the property



38
39
40
41
# File 'lib/eso/configuration/configuration.rb', line 38

def property(name)
  prop = properties.find{|attr| attr.property == name}
  prop.value unless prop.nil?
end

#to_hashHash

Convert the Configuration to a Hash

Returns:

  • (Hash)

    A Hash representation of the Configuration



24
25
26
27
28
29
30
31
32
# File 'lib/eso/configuration/configuration.rb', line 24

def to_hash
  hash = {:configId => @config_id,
          :serviceName => @service_name,
          :configName => @config_name,
          :configurationAttributes => {:valueClass => Eso::Values::OBJECT,
                                       :objectType => 'service_configuration',
                                       :properties => []}}
  properties.each {|prop| hash[:configurationAttributes][:properties] << prop.to_hash}
end

#to_jsonString

Convert the Configuration to a JSON string for sending to Nexpose

Returns:

  • (String)

    A JSON String representation of the Configuration



17
18
19
# File 'lib/eso/configuration/configuration.rb', line 17

def to_json
  self.to_hash.to_json
end

#update_property(name, value) ⇒ String

Update a Configuration attribute property value given the name of the property

Parameters:

  • name (String)

    The name of the property to update

  • value (String)

    The value of the property to update

Returns:

  • (String)

    The value of the property



48
49
50
# File 'lib/eso/configuration/configuration.rb', line 48

def update_property(name, value)
  properties.find{|attr| attr.property == name}.value = value
end