Class: Dotcode::CLI::Commands::Apply

Inherits:
Dry::CLI::Command
  • Object
show all
Defined in:
lib/dotcode/cli.rb

Overview

apply

Instance Method Summary collapse

Instance Method Details

#call(workdir:) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/dotcode/cli.rb', line 38

def call(workdir:, **)
  @workdir = workdir

  load_dotcode_yml_in_workdir
  exec_dotcode_yml_commands_in_template_dir
  sync_files
end

#exec_dotcode_yml_commands_in_template_dirObject



57
58
59
60
61
62
63
# File 'lib/dotcode/cli.rb', line 57

def exec_dotcode_yml_commands_in_template_dir
  dotcode_file_entries = YAML.load_file(File.join(__dir__, "../../templates", @template_name, "dotcode.yml"))

  dotcode_file_entries.map do |entry|
    system entry["shell"] if entry.key?("shell")
  end
end

#load_dotcode_yml_in_workdirObject



46
47
48
49
50
51
52
53
54
55
# File 'lib/dotcode/cli.rb', line 46

def load_dotcode_yml_in_workdir
  dotcode_yml_path = File.join(Dir.pwd, @workdir, ".code.yml")

  raise_error ".code.yml not found" unless File.exist? dotcode_yml_path

  @dotcode_yml = YAML.load_file(dotcode_yml_path)
  @template_name = @dotcode_yml["template"]

  raise_error "\"template:\" key not found in .code.yml" unless @template_name
end

#sync_filesObject



65
66
67
68
# File 'lib/dotcode/cli.rb', line 65

def sync_files
  system "rsync -rv '#{File.join(__dir__, "../../templates", @template_name,
                                 "_tmpl")}/' '#{File.join(Dir.pwd, @workdir)}'"
end