Class: Docker::Template::CLI::Build

Inherits:
Object
  • Object
show all
Defined in:
lib/docker/template/cli/build.rb

Instance Method Summary collapse

Constructor Details

#initialize(args, opts) ⇒ Build

Returns a new instance of Build.



9
10
11
12
13
# File 'lib/docker/template/cli/build.rb', line 9

def initialize(args, opts)
  @opts = Meta.new(opts || {})
  @repos = Parser.new(args, opts || {}).parse
  @args = args
end

Instance Method Details

#changed!Object

– rubocop:disable Metrics/AbcSize –



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/docker/template/cli/build.rb', line 41

def changed!
  Template._require "rugged" do
    git = Rugged::Repository.new(Template.root.to_s)
    dir = Template.root.join(@opts.repos_dir)

    repos = git.last_commit.diff.each_delta.each_with_object(Set.new) do |delta, set|
      next unless Pathutil.new(delta.new_file[:path]).expand_path(Template.root).in_path?(dir)
      set.merge(delta.new_file[:path].split("/").values_at(
        1
      ))
    end

    @repos = @repos.select do |repo|
      repos.include?(
        repo.name
      )
    end
  end
end

#exclude!Object



29
30
31
32
33
34
35
# File 'lib/docker/template/cli/build.rb', line 29

def exclude!
  Parser.new(@opts[:exclude].map { |v| v.split(/,\s*/) }.flatten.compact).parse.each do |repo|
    @repos.delete_if do |v|
      v.name == repo.name && v.tag == repo.tag
    end
  end
end

#startObject



17
18
19
20
21
22
23
24
25
# File 'lib/docker/template/cli/build.rb', line 17

def start
  _profile do
    changed! if @opts.diff?
    exclude! if @opts.exclude?
    @repos.tap { |o| o.map(&:build) }.uniq(&:name).map(
      &:clean
    )
  end
end