Class: OmfEc::AppDefinition

Inherits:
Object
  • Object
show all
Includes:
Backward::AppDefinition
Defined in:
omf_ec/lib/omf_ec/app_definition.rb

Overview

Application Definition used in experiment script

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods included from Backward::AppDefinition

#defMeasurement, #defMetric, #defProperty

Constructor Details

- (AppDefinition) initialize(name)

Returns a new instance of AppDefinition

Parameters:

  • name (String)

    name of the application to define



19
20
21
22
# File 'omf_ec/lib/omf_ec/app_definition.rb', line 19

def initialize(name)
  self.name = name
  self.properties = Hashie::Mash.new
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

- (Object) method_missing(method_name, *args)



61
62
63
64
65
66
67
68
69
70
# File 'omf_ec/lib/omf_ec/app_definition.rb', line 61

def method_missing(method_name, *args)
  k = method_name.to_sym
  return @properties[k] if @properties.key?(k)
  m = method_name.to_s.match(/(.*?)([=]?)$/)
  if m[2] == '='
    @properties[m[1].to_sym] = args.first
  else
    super
  end
end

Instance Attribute Details

- (Object) name

TODO: eventually this call would mirror all the properties of the App Proxy right now we just have name, binary_path, parameters



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'omf_ec/lib/omf_ec/app_definition.rb', line 12

class AppDefinition

  # TODO: eventually this call would mirror all the properties of the App Proxy
  # right now we just have name, binary_path, parameters
  attr_accessor :name, :properties

  # @param [String] name name of the application to define
  def initialize(name)
    self.name = name
    self.properties = Hashie::Mash.new
  end

  # Add new parameter(s) to this Application Definition
  #
  # @param [Hash] params a hash with the parameters to add
  #
  def define_parameter(params)
    @properties[:parameters] = Hashie::Mash.new unless @properties.key?(:parameters)
    if params.kind_of? Hash
      @properties[:parameters].merge!(params)
    else
      error "Cannot define parameter for app '#{self.name}'! Parameter "+
        "not passed as a Hash ('#{params.inspect}')"
    end
  end

  def define_measurement_point(mp)
    @properties[:oml] = Hashie::Mash.new unless @properties.key?(:oml)
    if mp.kind_of? Hash
      @properties[:oml][:available_mps] = Array.new unless @properties[:oml].key?(:available_mps)
      @properties[:oml][:available_mps] << mp
    else
      error "Cannot define Measurement Point for app '#{self.name}'! MP "+
        "not passed as a Hash ('#{mp.inspect}')"
    end
  end

  warn_removed :version

  def path=(arg)
    @properties[:binary_path] = arg
    warn_deprecation :path=, :binary_path=
  end

  def shortDescription=(arg)
    @properties[:description] = arg
    warn_deprecation :shortDescription=, :description=
  end

  def method_missing(method_name, *args)
    k = method_name.to_sym
    return @properties[k] if @properties.key?(k)
    m = method_name.to_s.match(/(.*?)([=]?)$/)
    if m[2] == '='
      @properties[m[1].to_sym] = args.first
    else
      super
    end
  end

  include OmfEc::Backward::AppDefinition
end

- (Object) properties

TODO: eventually this call would mirror all the properties of the App Proxy right now we just have name, binary_path, parameters



16
17
18
# File 'omf_ec/lib/omf_ec/app_definition.rb', line 16

def properties
  @properties
end

Instance Method Details

- (Object) define_measurement_point(mp)



38
39
40
41
42
43
44
45
46
47
# File 'omf_ec/lib/omf_ec/app_definition.rb', line 38

def define_measurement_point(mp)
  @properties[:oml] = Hashie::Mash.new unless @properties.key?(:oml)
  if mp.kind_of? Hash
    @properties[:oml][:available_mps] = Array.new unless @properties[:oml].key?(:available_mps)
    @properties[:oml][:available_mps] << mp
  else
    error "Cannot define Measurement Point for app '#{self.name}'! MP "+
      "not passed as a Hash ('#{mp.inspect}')"
  end
end

- (Object) define_parameter(params)

Add new parameter(s) to this Application Definition

Parameters:

  • params (Hash)

    a hash with the parameters to add



28
29
30
31
32
33
34
35
36
# File 'omf_ec/lib/omf_ec/app_definition.rb', line 28

def define_parameter(params)
  @properties[:parameters] = Hashie::Mash.new unless @properties.key?(:parameters)
  if params.kind_of? Hash
    @properties[:parameters].merge!(params)
  else
    error "Cannot define parameter for app '#{self.name}'! Parameter "+
      "not passed as a Hash ('#{params.inspect}')"
  end
end

- (Object) path=(arg)



51
52
53
54
# File 'omf_ec/lib/omf_ec/app_definition.rb', line 51

def path=(arg)
  @properties[:binary_path] = arg
  warn_deprecation :path=, :binary_path=
end

- (Object) shortDescription=(arg)



56
57
58
59
# File 'omf_ec/lib/omf_ec/app_definition.rb', line 56

def shortDescription=(arg)
  @properties[:description] = arg
  warn_deprecation :shortDescription=, :description=
end