Skip to content

Commit 6f92e09

Browse files
author
Alex Evanczuk
authored
Allow YML configuration to take precedence (#7)
* 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
1 parent e6cc779 commit 6f92e09

7 files changed

Lines changed: 40 additions & 48 deletions

File tree

.DS_Store

6 KB
Binary file not shown.

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
packs (0.0.3)
4+
packs (0.0.4)
55
sorbet-runtime
66

77
GEM

README copy.md

Lines changed: 0 additions & 33 deletions
This file was deleted.

lib/packs.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

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

1211
class << self
1312
extend T::Sig
@@ -45,6 +44,11 @@ def config
4544

4645
sig { params(blk: T.proc.params(arg0: Private::Configuration).void).void }
4746
def configure(&blk)
47+
# If packs.yml is being used, then ignore direct configuration.
48+
# This is only a stop-gap to permit Stimpack users to more easily migrate
49+
# to packs.yml
50+
return if Private::Configuration::CONFIGURATION_PATHNAME.exist?
51+
4852
yield(config)
4953
end
5054

lib/packs/private/configuration.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,21 @@ module Packs
44
module Private
55
class Configuration < T::Struct
66
extend T::Sig
7+
CONFIGURATION_PATHNAME = T.let(Pathname.new('packs.yml'), Pathname)
8+
79
DEFAULT_PACK_PATHS = T.let([
8-
'packs/*',
9-
'packs/*/*',
10-
], T::Array[String])
10+
'packs/*',
11+
'packs/*/*'
12+
], T::Array[String])
1113

1214
prop :pack_paths, T::Array[String]
1315

1416
sig { returns(Configuration) }
1517
def self.fetch
16-
configuration_path = Pathname.new('packs.yml')
17-
config_hash = configuration_path.exist? ? YAML.load_file('packs.yml') : {}
18+
config_hash = CONFIGURATION_PATHNAME.exist? ? YAML.load_file(CONFIGURATION_PATHNAME) : {}
1819

1920
new(
20-
pack_paths: pack_paths(config_hash),
21+
pack_paths: pack_paths(config_hash)
2122
)
2223
end
2324

packs.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Gem::Specification.new do |spec|
22
spec.name = 'packs'
3-
spec.version = '0.0.3'
3+
spec.version = '0.0.4'
44
spec.authors = ['Gusto Engineers']
55
spec.email = ['dev@gusto.com']
66
spec.summary = 'Packs are the specification for gradual modularization in the `rubyatscale` ecosystem.'

spec/packs_spec.rb

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
write_file('packs/my_pack/package.yml')
2525
write_file('components/my_pack/package.yml')
2626
write_file('packs.yml', <<~YML)
27-
pack_paths:
28-
- packs/*
29-
- components/*
27+
pack_paths:
28+
- packs/*
29+
- components/*
3030
YML
3131
end
3232

@@ -44,6 +44,26 @@
4444

4545
it { expect(Packs.all.count).to eq 2 }
4646
end
47+
48+
context 'in an app with a differently configured root configured via ruby and YML' do
49+
before do
50+
write_file('packs/my_pack/package.yml')
51+
write_file('components/my_pack/package.yml')
52+
write_file('packages/my_pack/package.yml')
53+
write_file('packs.yml', <<~YML)
54+
pack_paths:
55+
- packs/*
56+
- components/*
57+
YML
58+
Packs.configure do |config|
59+
config.pack_paths = ['packs/*']
60+
end
61+
end
62+
63+
it 'prioritizes the YML configuration' do
64+
expect(Packs.all.count).to eq 2
65+
end
66+
end
4767
end
4868

4969
describe '.find' do
@@ -70,9 +90,9 @@
7090
write_file('packs/my_pack/package.yml')
7191
write_file('components/my_pack/package.yml')
7292
write_file('packs.yml', <<~YML)
73-
pack_paths:
74-
- packs/*
75-
- components/*
93+
pack_paths:
94+
- packs/*
95+
- components/*
7696
YML
7797
end
7898

0 commit comments

Comments
 (0)