Sha256: 4bf2ffdb076992d69ddd4726ec59fff4ac95957c709b9e12fa1e6c5da47043b1

Contents?: true

Size: 1.15 KB

Versions: 2

Compression:

Stored size: 1.15 KB

Contents

class Mona::Package::Repo
  include Mona::Mixins

  Inject = Mona::Deps[
    "package.list",
  ]

  include Inject

  sig do
    returns(T::Array[Mona::Package])
  end
  def all
    list.call
  end

  sig do
    params(
      name: T.nilable(
        T.any(
          String,
          Symbol,
          T::Array[
            T.any(String, Symbol)
          ]
        )
      ),
    )
    .returns(T::Array[Mona::Package])
  end
  def filter(name: nil)
    packages = all

    unless name.nil?
      names = name.is_a?(Array) ? name : [name]
      names = names.map(&:to_sym)

      packages = packages.select { names.include?(_1.name) }
    end

    packages
  end

  sig do
    params(
      package_name: T.nilable(T.any(String, Symbol)),
    )
    .returns(T.nilable(Mona::Package))
  end
  def find(package_name)
    all.detect { _1.name == package_name.to_sym }
  end

  sig do
    params(
      package_name: T.nilable(T.any(String, Symbol)),
    )
    .returns(Mona::Package)
  end
  def find!(package_name)
    find(package_name) || (raise StandardError.new("package '#{package_name}' was not found for Mona project '#{Mona.current_project.root_path}'"))
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mona-0.2.3 lib/mona/package/repo.rb
mona-0.2.2 lib/mona/package/repo.rb