Module: Dry

Defined in:
lib/dry-stack/stack.rb,
lib/version.rb,
lib/dry-stack/command_line.rb

Overview

class TrueClass

def encode_with(coder) = coder.represent_scalar('tag:yaml.org,2002:str', 'true')

end

class FalseClass

def encode_with(coder)= coder.represent_scalar('tag:yaml.org,2002:str', 'false')

end

Defined Under Namespace

Modules: CommandLine Classes: ConfigurationFunction, ServiceFunction, Stack

Constant Summary collapse

EMPTY_HASH =
:empty_hash
DEFAULT_INIT_SERVICE =

add “init: true” option

true

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cmd_paramsObject

Returns the value of attribute cmd_params.



60
61
62
# File 'lib/dry-stack/stack.rb', line 60

def cmd_params
  @cmd_params
end

Instance Method Details

#each_recursive(parent, each_ = -> { _1.respond_to?(:each) ? _1.each : [] }, path = [], &blk) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/dry-stack/stack.rb', line 39

def each_recursive(parent, each_ = -> { _1.respond_to?(:each) ? _1.each : [] }, path = [], &blk)
  each2_ = each_.is_a?(Array) ? ->(p) { (m = each_.find { p.respond_to? _1 }) ? p.send(m) : [] } : each_
  (each2_[parent] || []).each do |(k,v)|
    blk.call [path + [parent], k, v, path]
    each_recursive(v || k, each_, path + [parent], &blk)
  end
end

#ENV!Object



20
# File 'lib/dry-stack/stack.rb', line 20

def ENV! = ENV.method(:fetch)

#expand_hash(hash) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/dry-stack/stack.rb', line 47

def expand_hash(hash)
  hash.select { _1.to_s =~ /\./ }.each do |k, v|
    name = k.to_s.scan(/([^\.]*)\.(.*)/).flatten
    hash.delete k
    hash[name[0]] ||= {}
    hash[name[0]][name[1]] ||= {}
    hash[name[0]][name[1]].merge! v if v.is_a?(Hash)
    hash[name[0]][name[1]] = v unless v.is_a?(Hash)
  end
  hash.each { expand_hash(_2) if _2.is_a?(Hash) }
  hash
end

#Stack(name = nil, configuration = nil) ⇒ Object



63
64
65
66
67
68
69
70
71
# File 'lib/dry-stack/stack.rb', line 63

def Stack(name = nil, configuration = nil, &)
  Stack.last_stack = Stack.new name
  Stack.last_stack.instance_exec(&) if block_given?
  Stack.last_stack.instance_exec do
    @services_blocks&.each { instance_exec &_1 }
    @after_blocks&.each { instance_exec &_1 }
  end
  Stack.last_stack.apply_configuration configuration if configuration
end