Class: BranchIOCLI::RakeTask

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/branch_io_cli/rake_task.rb

Instance Method Summary collapse

Constructor Details

#initialize(name = :branch) ⇒ RakeTask

Returns a new instance of RakeTask.



8
9
10
11
12
13
14
# File 'lib/branch_io_cli/rake_task.rb', line 8

def initialize(name = :branch)
  namespace name do
    add_branch_task :report, "Generate a brief Branch report"
    add_branch_task :setup, "Set a project up with the Branch SDK"
    add_branch_task :validate, "Validate Universal Links in one or more projects"
  end
end

Instance Method Details

#add_branch_task(task_name, description) ⇒ Object



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

def add_branch_task(task_name, description)
  command_class = Command.const_get("#{task_name.to_s.capitalize}Command")
  configuration_class = Configuration.const_get("#{task_name.to_s.capitalize}Configuration")

  desc description
  task task_name, %i{paths options} do |task, args|
    paths = args[:paths]
    paths = [paths] unless paths.respond_to?(:each)
    options = args[:options] || {}

    paths.each do |path|
      Dir.chdir(path) do
        begin
          command_class.new(configuration_class.wrapper(options)).run!
        rescue StandardError => e
          say "Error from #{task_name} task in #{path}: #{e.message}"
          say e.backtrace if options[:trace]
        end
      end
    end
  end
end