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:



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/dapp/config/application.rb', line 15

def initialize(parent)
  @_parent = parent

  @_docker       = Directive::Docker::Base.new
  @_git_artifact = Directive::GitArtifact.new
  @_shell        = Directive::Shell::Base.new
  @_chef         = Directive::Chef.new
  @_tmp_dir      = Directive::TmpDir.new
  @_build_dir    = Directive::BuildDir.new

  @_apps                    = []

  @_before_install_artifact = []
  @_before_setup_artifact   = []
  @_after_install_artifact  = []
  @_after_setup_artifact    = []
  @_import_artifact         = []

  @_install_dependencies    = []
  @_setup_dependencies      = []

  yield self if block_given?
end

Instance Attribute Details

#_after_install_artifactObject (readonly)

Returns the value of attribute _after_install_artifact.



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

def _after_install_artifact
  @_after_install_artifact
end

#_after_setup_artifactObject (readonly)

Returns the value of attribute _after_setup_artifact.



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

def _after_setup_artifact
  @_after_setup_artifact
end

#_basenameObject (readonly)

Returns the value of attribute _basename.



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

def _basename
  @_basename
end

#_before_install_artifactObject (readonly)

Returns the value of attribute _before_install_artifact.



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

def _before_install_artifact
  @_before_install_artifact
end

#_before_setup_artifactObject (readonly)

Returns the value of attribute _before_setup_artifact.



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

def _before_setup_artifact
  @_before_setup_artifact
end

#_build_dirObject (readonly)

Returns the value of attribute _build_dir.



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

def _build_dir
  @_build_dir
end

#_builderObject (readonly)

Returns the value of attribute _builder.



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

def _builder
  @_builder
end

#_chefObject (readonly)

Returns the value of attribute _chef.



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

def _chef
  @_chef
end

#_dockerObject (readonly)

Returns the value of attribute _docker.



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

def _docker
  @_docker
end

#_git_artifactObject (readonly)

Returns the value of attribute _git_artifact.



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

def _git_artifact
  @_git_artifact
end

#_home_pathObject (readonly)

Returns the value of attribute _home_path.



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

def _home_path
  @_home_path
end

#_import_artifactObject (readonly)

Returns the value of attribute _import_artifact.



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

def _import_artifact
  @_import_artifact
end

#_install_dependenciesObject (readonly)

Returns the value of attribute _install_dependencies.



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

def _install_dependencies
  @_install_dependencies
end

#_parentObject (readonly)

Returns the value of attribute _parent.



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

def _parent
  @_parent
end

#_setup_dependenciesObject (readonly)

Returns the value of attribute _setup_dependencies.



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

def _setup_dependencies
  @_setup_dependencies
end

#_shellObject (readonly)

Returns the value of attribute _shell.



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

def _shell
  @_shell
end

#_tmp_dirObject (readonly)

Returns the value of attribute _tmp_dir.



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

def _tmp_dir
  @_tmp_dir
end

Instance Method Details

#_app_chainObject



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

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

#_app_runlistObject



99
100
101
102
103
104
105
106
# File 'lib/dapp/config/application.rb', line 99

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

#_appsObject



91
92
93
# File 'lib/dapp/config/application.rb', line 91

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

#_nameObject



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

def _name
  (@_name || @_basename).tap do |name|
    reg = '^[[[:alnum:]]_.-]*$'
    raise Error::Config, code: :app_name_incorrect, data: { name: name, reg: reg } unless name =~ /#{reg}/
  end
end

#_root_appObject



108
109
110
# File 'lib/dapp/config/application.rb', line 108

def _root_app
  _app_chain.first
end

#artifact(where_to_add, before: nil, after: nil, **options, &blk) ⇒ Object

Raises:



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

def artifact(where_to_add, before: nil, after: nil, **options, &blk)
  raise Error::Config, code: :stage_artifact_double_associate unless before.nil? || after.nil?
  artifact_base(instance_variable_get(:"@_#{artifact_variable_name(before, after)}"), where_to_add, **options, &blk)
end

#build_dirObject



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

def build_dir
  @_build_dir
end

#builder(type) ⇒ Object

Raises:



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

def builder(type)
  project.log_warning(desc: { code: 'excess_builder_instruction', context: 'warning' }) if @_chef.send(:empty?) && @_shell.send(:empty?)
  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}", instance_variable_get(:"@_#{another_builder}").class.new)
  @_builder = type
end

#chefObject



55
56
57
# File 'lib/dapp/config/application.rb', line 55

def chef
  @_chef.tap { raise Error::Config, code: :builder_type_conflict unless _builder == :chef }
end

#dockerObject



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

def docker
  @_docker
end

#git_artifactObject



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

def git_artifact
  @_git_artifact ||= Directive::GitArtifact.new
end

#install_depends_on(*args) ⇒ Object



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

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

#setup_depends_on(*args) ⇒ Object



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

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

#shellObject



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

def shell
  @_shell.tap { raise Error::Config, code: :builder_type_conflict unless _builder == :shell }
end

#tmp_dirObject



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

def tmp_dir
  @_tmp_dir
end