Class: Dapp::Controller

Inherits:
Object
  • Object
show all
Includes:
Helper::Log, Helper::Shellout
Defined in:
lib/dapp/controller.rb

Overview

Controller

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helper::Shellout

included, #shellout, #shellout!

Methods included from Helper::Log

included, #log, #log_format_string, #log_indent, #log_indent_next, #log_indent_prev, #log_info, #log_secondary, #log_step, #log_time, #log_with_indent, #with_log_indent

Constructor Details

#initialize(cli_options: {}, patterns: nil) ⇒ Controller

Returns a new instance of Controller.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/dapp/controller.rb', line 9

def initialize(cli_options: {}, patterns: nil)
  @cli_options = cli_options
  @cli_options[:log_indent] = 0

  @patterns = patterns || []
  @patterns << '*' unless @patterns.any?

  paint_initialize
  Helper::I18n.initialize
  build_confs
end

Instance Attribute Details

#cli_optionsObject (readonly)

Returns the value of attribute cli_options.



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

def cli_options
  @cli_options
end

#patternsObject (readonly)

Returns the value of attribute patterns.



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

def patterns
  @patterns
end

Class Method Details

.flush_stage_cacheObject



55
56
57
58
# File 'lib/dapp/controller.rb', line 55

def self.flush_stage_cache
  shellout('docker rmi $(docker images --format="{{.Repository}}:{{.Tag}}" dapp)')
  shellout('docker rmi $(docker images -f "dangling=true" -q)')
end

Instance Method Details

#buildObject



21
22
23
24
25
26
# File 'lib/dapp/controller.rb', line 21

def build
  build_confs.each do |build_conf|
    log_step(build_conf._name)
    with_log_indent { Application.new(config: build_conf, cli_options: cli_options).build! }
  end
end

#flush_build_cacheObject



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

def flush_build_cache
  build_confs.each do |build_conf|
    log(build_conf._name)
    app = Application.new(config: build_conf, cli_options: cli_options, ignore_git_fetch: true)
    FileUtils.rm_rf app.build_cache_path
  end
end

#listObject



28
29
30
31
32
# File 'lib/dapp/controller.rb', line 28

def list
  build_confs.each do |build_conf|
    log(build_conf._name)
  end
end

#push(repo) ⇒ Object

Raises:



34
35
36
37
# File 'lib/dapp/controller.rb', line 34

def push(repo)
  raise Error::Controller, code: :push_command_unexpected_apps unless @build_confs.one?
  Application.new(config: @build_confs.first, cli_options: cli_options, ignore_git_fetch: true).export!(repo)
end

#smartpush(repo_prefix) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/dapp/controller.rb', line 39

def smartpush(repo_prefix)
  build_confs.each do |build_conf|
    log_step(build_conf._name)
    repo = File.join(repo_prefix, build_conf._name)
    with_log_indent { Application.new(config: build_conf, cli_options: cli_options, ignore_git_fetch: true).export!(repo) }
  end
end