Sha256: 4a49e49c40e960b6aeaa916ca7f7c8734d07e431fb704b9e0c5905c884787dfc

Contents?: true

Size: 952 Bytes

Versions: 2

Compression:

Stored size: 952 Bytes

Contents

class Mona::Task::Manager
  include Mona::Mixins

  Inject = Mona::Deps[
    packages_repo: "package.repo"
  ]

  include Inject

  sig do
    params(
      method_name: Symbol,
      args: T.anything,
      kwargs: T.anything
    )
    .returns(T::Boolean)
  end
  def method_missing(method_name, *args, **kwargs)
    task = Mona.current_project.tasks.detect { _1.name == method_name } || (raise StandardError.new("task '#{method_name}' not found for project"))

    case task.on
    when :package
      statuses = kwargs[:packages].inject({}) do |result, package_name|
        package = packages_repo.find!(package_name.to_sym)
        result[package.name] = task.block.call(package, kwargs[:args])
        result
      end

      failed_packages = statuses.reject {|package_name, exitstatus| exitstatus == 0}

      failed_packages.any? ? false : true
    else
      raise StandardError.new("unsupported task subject: #{task.on}")
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mona-0.2.3 lib/mona/task/manager.rb
mona-0.2.2 lib/mona/task/manager.rb