Class: RubyYacht::Hook::EnvironmentVariableBehavior

Inherits:
Behavior
  • Object
show all
Defined in:
lib/ruby_yacht/dsl/hook.rb

Overview

This class provides a behavior for setting an environment variable in the image.

Instance Attribute Summary

Attributes inherited from Behavior

#context

Instance Method Summary collapse

Constructor Details

#initialize(name, proc) ⇒ EnvironmentVariableBehavior

This initializer creates the behavior.

Parameters

  • name: String The name of the environment variable to create.
  • proc: Proc The proc for generating the value for the environment variable.


238
239
240
241
242
# File 'lib/ruby_yacht/dsl/hook.rb', line 238

def initialize(name, proc)
  @name = name
  @proc = proc
  @context = self
end

Instance Method Details

#dockerfile_commandObject

The command that should be run in a Dockerfile for this behavior.



250
251
252
253
254
# File 'lib/ruby_yacht/dsl/hook.rb', line 250

def dockerfile_command
  value = self.value
  return nil unless value
  "ENV #{@name} #{value}"
end

#shell_commandObject

The command that should be run in a shell script for this behavior.



257
258
259
260
261
# File 'lib/ruby_yacht/dsl/hook.rb', line 257

def shell_command
  value = self.value
  return nil unless value
  "export #{@name}=\"#{value}\""
end

#valueObject

The value for the environment variable.



245
246
247
# File 'lib/ruby_yacht/dsl/hook.rb', line 245

def value
  context.instance_eval(&@proc)
end