class Oops::Tasks

Attributes

additional_paths[RW]
excludes[RW]
format[RW]
includes[RW]
prerequisites[RW]

Public Class Methods

default_args() click to toggle source
# File lib/oops/tasks.rb, line 9
def self.default_args
  {
    prerequisites: ['assets:clean', 'assets:precompile'],
    additional_paths: [],
    includes: ['public/assets', 'public/packs'],
    excludes: ['.gitignore'],
    format: 'zip'
  }
end
new() { |self| ... } click to toggle source
# File lib/oops/tasks.rb, line 19
def initialize(&block)
  self.class.default_args.each do |key, value|
    public_send("#{key}=", value)
  end
  yield(self)
  create_task!
end

Public Instance Methods

add_file(file_path, path) click to toggle source
# File lib/oops/tasks.rb, line 27
def add_file file_path, path
  if format == 'zip'
    sh *%W{zip -r -g build/#{file_path} #{path}}
  elsif format == 'tar'
    sh *%W{tar -r -f build/#{file_path} #{path}}
  end
end
remove_file(file_path, path) click to toggle source
# File lib/oops/tasks.rb, line 35
def remove_file file_path, path
  if format == 'zip'
    sh *%W{zip build/#{file_path} -d #{path}}
  elsif format == 'tar'
    sh *%W{tar --delete -f build/#{file_path} #{path}}
  end
end

Private Instance Methods

create_task!() click to toggle source
# File lib/oops/tasks.rb, line 45
def create_task!
  # Remove any existing definition
  Rake::Task["oops:build"].clear if Rake::Task.task_defined?("oops:build")

  namespace :oops do
    task :build, [:filename] => prerequisites do |t, args|
      args.with_defaults filename: default_filename

      file_path = args.filename

      sh %{mkdir -p build}
      sh %{git archive --format #{format} --output build/#{file_path} HEAD}

      (includes + additional_paths).each do |path|
        add_file file_path, path
      end

      excludes.each do |path|
        remove_file file_path, path
      end

      puts "Packaged Application: #{file_path}"
    end
  end
end