Class: Baha::ContainerOptions::Option

Inherits:
Object
  • Object
show all
Defined in:
lib/baha/container_options/option.rb

Direct Known Subclasses

Cmd, Env, ExposedPorts, Volumes

Constant Summary collapse

KEYS =
{
  :cmd => 'Cmd',
  :cpushares => 'CpuShares',
  :cpuset => 'Cpuset',
  :domainname => 'Domainname',
  :entrypoint => 'Entrypoint',
  :env => 'Env',
  :exposedports => 'ExposedPorts',
  :hostname => 'Hostname',
  :image => 'Image',
  :memory => 'Memory',
  :memoryswap => 'MemorySwap',
  :networkdisabled => 'NetworkDisabled',
  :user => 'User',
  :volumes => 'Volumes',
  :workingdir => 'WorkingDir',
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Option

Returns a new instance of Option.

Raises:

  • (ArgumentError)


27
28
29
30
31
32
33
# File 'lib/baha/container_options/option.rb', line 27

def initialize(*args)
  k,@value = args
  raise ArgumentError, "Cannot understand option key '#{k}'" unless k.respond_to?(:to_sym)
  @key = k.to_sym.downcase
  raise ERROR("Option with key '#{@key}' is not found. Expecting #{KEYS.keys.inspect}") unless KEYS.has_key?(@key)
  @config_key = KEYS[@key]
end

Instance Attribute Details

#config_keyObject (readonly)

Returns the value of attribute config_key.



24
25
26
# File 'lib/baha/container_options/option.rb', line 24

def config_key
  @config_key
end

#keyObject (readonly)

Returns the value of attribute key.



23
24
25
# File 'lib/baha/container_options/option.rb', line 23

def key
  @key
end

#valueObject (readonly)

Returns the value of attribute value.



25
26
27
# File 'lib/baha/container_options/option.rb', line 25

def value
  @value
end

Instance Method Details

#apply(config) ⇒ Object

Apply this option to the container’s config hash



40
41
42
# File 'lib/baha/container_options/option.rb', line 40

def apply(config)
  config[@config_key] = @value
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/baha/container_options/option.rb', line 35

def eql?(other)
  @key == other.key and @value == other.value
end

#inspectObject



49
50
51
# File 'lib/baha/container_options/option.rb', line 49

def inspect
  "#{self.class.name}<@key=#{@key.inspect},@value=#{@value.inspect}>"
end

#validate!Object

Validate the option’s value



45
46
47
# File 'lib/baha/container_options/option.rb', line 45

def validate!
  KEYS.has_key?(@key)
end