Class: Dapp::Config::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/dapp/config/application.rb

Overview

Application

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent) {|_self| ... } ⇒ Application

Returns a new instance of Application.

Yields:

  • (_self)

Yield Parameters:



18
19
20
21
22
23
24
25
26
27
# File 'lib/dapp/config/application.rb', line 18

def initialize(parent)
  @_apps   = []
  @_parent = parent

  @_artifact = []
  @_install_dependencies = []
  @_setup_dependencies   = []

  yield self if block_given?
end

Instance Attribute Details

#_artifact ⇒ Object (readonly)

Returns the value of attribute _artifact.



10
11
12
# File 'lib/dapp/config/application.rb', line 10

def _artifact
  @_artifact
end

#_basename ⇒ Object (readonly)

Returns the value of attribute _basename.



7
8
9
# File 'lib/dapp/config/application.rb', line 7

def _basename
  @_basename
end

#_builder ⇒ Object (readonly)

Returns the value of attribute _builder.



5
6
7
# File 'lib/dapp/config/application.rb', line 5

def _builder
  @_builder
end

#_chef ⇒ Object (readonly)

Returns the value of attribute _chef.



11
12
13
# File 'lib/dapp/config/application.rb', line 11

def _chef
  @_chef
end

#_docker ⇒ Object (readonly)

Returns the value of attribute _docker.



8
9
10
# File 'lib/dapp/config/application.rb', line 8

def _docker
  @_docker
end

#_git_artifact ⇒ Object (readonly)

Returns the value of attribute _git_artifact.



9
10
11
# File 'lib/dapp/config/application.rb', line 9

def _git_artifact
  @_git_artifact
end

#_home_path ⇒ Object (readonly)

Returns the value of attribute _home_path.



6
7
8
# File 'lib/dapp/config/application.rb', line 6

def _home_path
  @_home_path
end

#_install_dependencies ⇒ Object (readonly)

Returns the value of attribute _install_dependencies.



14
15
16
# File 'lib/dapp/config/application.rb', line 14

def _install_dependencies
  @_install_dependencies
end

#_parent ⇒ Object (readonly)

Returns the value of attribute _parent.



13
14
15
# File 'lib/dapp/config/application.rb', line 13

def _parent
  @_parent
end

#_setup_dependencies ⇒ Object (readonly)

Returns the value of attribute _setup_dependencies.



15
16
17
# File 'lib/dapp/config/application.rb', line 15

def _setup_dependencies
  @_setup_dependencies
end

#_shell ⇒ Object (readonly)

Returns the value of attribute _shell.



12
13
14
# File 'lib/dapp/config/application.rb', line 12

def _shell
  @_shell
end

Instance Method Details

#_app_chain ⇒ Object



81
82
83
# File 'lib/dapp/config/application.rb', line 81

def _app_chain
  @_app_chain ||= (_parent ? _parent._app_chain : []) + [self]
end

#_app_runlist ⇒ Object



85
86
87
88
89
90
91
92
# File 'lib/dapp/config/application.rb', line 85

def _app_runlist
  _app_chain.map(&:_name).map do |name|
    if (subname = name.split("#{_root_app._name}-", 2)[1])
      subname_parts = subname.split('-')
      subname_parts.join('_') if subname_parts.any?
    end
  end.compact
end

#_apps ⇒ Object



77
78
79
# File 'lib/dapp/config/application.rb', line 77

def _apps
  @_apps.empty? ? [self] : @_apps.flatten
end

#_name ⇒ Object



73
74
75
# File 'lib/dapp/config/application.rb', line 73

def _name
  @_name || @_basename
end

#_root_app ⇒ Object



94
95
96
# File 'lib/dapp/config/application.rb', line 94

def _root_app
  _app_chain.first
end

#artifact(where_to_add, **options, &blk) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/dapp/config/application.rb', line 47

def artifact(where_to_add, **options, &blk)
  @_artifact << begin
    config = clone.tap do |app|
      app.instance_variable_set(:'@_artifact', [])
      app.instance_variable_set(:'@_name', app_name("artifact-#{SecureRandom.hex(2)}"))
      app.instance_eval(&blk) if block_given?
    end
    Artifact::Stage.new(where_to_add, config: config, **options)
  end
end

#builder(type) ⇒ Object

Raises:



66
67
68
69
70
71
# File 'lib/dapp/config/application.rb', line 66

def builder(type)
  raise Error::Config, code: :builder_type_unsupported, data: { type: type } unless [:chef, :shell].include?((type = type.to_sym))
  another_builder = [:chef, :shell].find { |t| t != type }
  instance_variable_set(:"@_#{another_builder}", Config.const_get(another_builder.capitalize).new)
  @_builder = type
end

#chef ⇒ Object

Raises:



37
38
39
40
# File 'lib/dapp/config/application.rb', line 37

def chef
  raise Error::Config, code: :builder_type_conflict unless _builder == :chef
  @_chef ||= Chef.new
end

#docker ⇒ Object



62
63
64
# File 'lib/dapp/config/application.rb', line 62

def docker
  @_docker ||= Docker.new
end

#git_artifact ⇒ Object



58
59
60
# File 'lib/dapp/config/application.rb', line 58

def git_artifact
  @_git_artifact ||= GitArtifact.new
end

#install_depends_on(*args) ⇒ Object



29
30
31
# File 'lib/dapp/config/application.rb', line 29

def install_depends_on(*args)
  @_install_dependencies.concat(args)
end

#setup_depends_on(*args) ⇒ Object



33
34
35
# File 'lib/dapp/config/application.rb', line 33

def setup_depends_on(*args)
  @_setup_dependencies.concat(args)
end

#shell ⇒ Object

Raises:



42
43
44
45
# File 'lib/dapp/config/application.rb', line 42

def shell
  raise Error::Config, code: :builder_type_conflict unless _builder == :shell
  @_shell ||= Shell.new
end