module Kamaze::DockerImage::Concern::Setup
Provides setup (used during initialization) and related methods.
Protected Instance Methods
default_commands()
click to toggle source
Get default commands
@return [Hash]
# File lib/kamaze/docker_image/concern/setup.rb, line 74 def default_commands content = Pathname.new(__dir__).join('..', 'commands.yml').read YAML.safe_load(content, [Symbol]) end
setup(locations, &block)
click to toggle source
@param [Array<Thread::Backtrace::Location>] locations @return [self]
# File lib/kamaze/docker_image/concern/setup.rb, line 24 def setup(locations, &block) setup_defaults(locations).tap do setup_block(&block) @name = @name.to_s @commands = Hash[@commands.map { |k, v| [k.to_sym, v] }] to_h.each { |k, v| instance_variable_set("@#{k}", v) } end end
setup_block() { |s| ... }
click to toggle source
@yield [Config] config used to setup instance @return [Config]
# File lib/kamaze/docker_image/concern/setup.rb, line 62 def setup_block Config.new(self.respond_to?(:to_h) ? to_h : {}).tap do |s| yield(s) if block_given? s.freeze s.to_h.each { |k, v| setup_attr(k, v) } end end
setup_defaults(locations)
click to toggle source
Setup
atttributes with default values
@param [Array<Thread::Backtrace::Location>] locations @return [self]
# File lib/kamaze/docker_image/concern/setup.rb, line 41 def setup_defaults(locations) self.tap do @name = nil @version = 'latest' @path = Pathname.new('.') @verbose = $stdout.tty? && $stderr.tty? @tasks_load = true @tasks_ns = nil @run_as = called_from(locations).dirname.basename.to_s @docker_bin = 'docker' @exec_command = 'bash -il' @commands = default_commands @ssh = {} end end
Private Instance Methods
called_from(locations = caller_locations)
click to toggle source
@return [Pathname]
# File lib/kamaze/docker_image/concern/setup.rb, line 93 def called_from(locations = caller_locations) location = locations.first.path Pathname.new(location).realpath end
setup_attr(attr, val)
click to toggle source
Set given attr with given value
@param [String|Symbol] attr @param [Object] val
# File lib/kamaze/docker_image/concern/setup.rb, line 86 def setup_attr(attr, val) __send__("#{attr}=", val) rescue NoMethodError nil end