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
# File 'lib/ruby_yacht/dsl/hook.rb', line 250

def dockerfile_command
  "ENV #{@name} #{value}"
end

#shell_commandObject

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



255
256
257
# File 'lib/ruby_yacht/dsl/hook.rb', line 255

def shell_command
  "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