Skip to content

Commit

Permalink
Allow YML configuration to take precedence (#7)
Browse files Browse the repository at this point in the history
* add failing test

* fix failing test

* bump version

* Be more explicit that we ignore direct configuration if packs.yml exists

* remove accidentally commit of parse_packwerks README

* rubocop

* remove ROOTS constant
  • Loading branch information
Alex Evanczuk authored Dec 29, 2022
1 parent e6cc779 commit 6f92e09
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 48 deletions.
Binary file added .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
packs (0.0.3)
packs (0.0.4)
sorbet-runtime

GEM
Expand Down
33 changes: 0 additions & 33 deletions README copy.md

This file was deleted.

6 changes: 5 additions & 1 deletion lib/packs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

module Packs
PACKAGE_FILE = T.let('package.yml'.freeze, String)
ROOTS = T.let(%w[packs components], T::Array[String])

class << self
extend T::Sig
Expand Down Expand Up @@ -45,6 +44,11 @@ def config

sig { params(blk: T.proc.params(arg0: Private::Configuration).void).void }
def configure(&blk)
# If packs.yml is being used, then ignore direct configuration.
# This is only a stop-gap to permit Stimpack users to more easily migrate
# to packs.yml
return if Private::Configuration::CONFIGURATION_PATHNAME.exist?

yield(config)
end

Expand Down
13 changes: 7 additions & 6 deletions lib/packs/private/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@ module Packs
module Private
class Configuration < T::Struct
extend T::Sig
CONFIGURATION_PATHNAME = T.let(Pathname.new('packs.yml'), Pathname)

DEFAULT_PACK_PATHS = T.let([
'packs/*',
'packs/*/*',
], T::Array[String])
'packs/*',
'packs/*/*'
], T::Array[String])

prop :pack_paths, T::Array[String]

sig { returns(Configuration) }
def self.fetch
configuration_path = Pathname.new('packs.yml')
config_hash = configuration_path.exist? ? YAML.load_file('packs.yml') : {}
config_hash = CONFIGURATION_PATHNAME.exist? ? YAML.load_file(CONFIGURATION_PATHNAME) : {}

new(
pack_paths: pack_paths(config_hash),
pack_paths: pack_paths(config_hash)
)
end

Expand Down
2 changes: 1 addition & 1 deletion packs.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |spec|
spec.name = 'packs'
spec.version = '0.0.3'
spec.version = '0.0.4'
spec.authors = ['Gusto Engineers']
spec.email = ['[email protected]']
spec.summary = 'Packs are the specification for gradual modularization in the `rubyatscale` ecosystem.'
Expand Down
32 changes: 26 additions & 6 deletions spec/packs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
write_file('packs/my_pack/package.yml')
write_file('components/my_pack/package.yml')
write_file('packs.yml', <<~YML)
pack_paths:
- packs/*
- components/*
pack_paths:
- packs/*
- components/*
YML
end

Expand All @@ -44,6 +44,26 @@

it { expect(Packs.all.count).to eq 2 }
end

context 'in an app with a differently configured root configured via ruby and YML' do
before do
write_file('packs/my_pack/package.yml')
write_file('components/my_pack/package.yml')
write_file('packages/my_pack/package.yml')
write_file('packs.yml', <<~YML)
pack_paths:
- packs/*
- components/*
YML
Packs.configure do |config|
config.pack_paths = ['packs/*']
end
end

it 'prioritizes the YML configuration' do
expect(Packs.all.count).to eq 2
end
end
end

describe '.find' do
Expand All @@ -70,9 +90,9 @@
write_file('packs/my_pack/package.yml')
write_file('components/my_pack/package.yml')
write_file('packs.yml', <<~YML)
pack_paths:
- packs/*
- components/*
pack_paths:
- packs/*
- components/*
YML
end

Expand Down

0 comments on commit 6f92e09

Please sign in to comment.