Sha256: 7dcdf4aa068f8414b1ba0848bc32cf68cf1c7bcd8d3af4b61b4168777ead9df9
Contents?: true
Size: 1.9 KB
Versions: 2
Compression:
Stored size: 1.9 KB
Contents
# frozen_string_literal: true class Mona::Package::Factory include Mona::Mixins sig do params( package_root: String, package_dirname: String, init_proc: T.proc.params(args: T.anything).returns(T.anything) ) .returns(Mona::Package) end def call(package_root, package_dirname, init_proc:) @dependencies = Hash.new { |h, k| h[k] = [] } @current_env = Mona::Package::DEFAULT_ENV instance_exec(&init_proc) package = Mona::Package.new( name: @name, root_path: package_root, package_dirname: package_dirname, dependencies: @dependencies ).tap { check_duplicate_dependencies(_1) } end private def check_duplicate_dependencies(package) package.get_dependency_envs.each do |env| already_imported = package .get_dependencies(env) .group_by{ |e| e } .select { |k, v| v.size > 1 } .keys if already_imported.any? puts "WARNING: duplicated import for following packages #{already_imported.inspect} was already added for package '#{package.name}' for env '#{env}'" end end end sig do params( env: Symbol, block: T.proc.params(args: T.anything).returns(T.anything) ) .void end def dependency(env = Mona::Package::DEFAULT_ENV, &block) @current_env = env instance_eval(&block) @current_env = Mona::Package::DEFAULT_ENV nil end sig do params( package_name: T.any(Symbol, String), ) .void end def import(package_name) package_name = package_name.to_sym @dependencies[@current_env] << package_name nil end sig do params( block: T.proc.params(args: T.anything).returns(T.anything) ) .void end def package(&block) instance_exec(&block) nil end sig do params( value: T.any(String, Symbol) ) .void end def name(value) @name = value.to_sym nil end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
mona-0.2.3 | lib/mona/package/factory.rb |
mona-0.2.2 | lib/mona/package/factory.rb |