File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11PATH
22 remote: .
33 specs:
4- packs (0.0.2 )
4+ packs (0.0.3 )
55 sorbet-runtime
66
77GEM
Original file line number Diff line number Diff line change 33require 'yaml'
44require 'sorbet-runtime'
55require 'packs/pack'
6- require 'packs/configuration'
76require 'packs/private'
87
98module Packs
@@ -38,6 +37,17 @@ def bust_cache!
3837 @for_file = nil
3938 end
4039
40+ sig { returns ( Private ::Configuration ) }
41+ def config
42+ @config = T . let ( @config , T . nilable ( Private ::Configuration ) )
43+ @config ||= Private ::Configuration . fetch
44+ end
45+
46+ sig { params ( blk : T . proc . params ( arg0 : Private ::Configuration ) . void ) . void }
47+ def configure ( &blk )
48+ yield ( config )
49+ end
50+
4151 private
4252
4353 sig { returns ( T ::Hash [ String , Pack ] ) }
@@ -56,12 +66,9 @@ def packs_by_name
5666
5767 sig { returns ( T ::Array [ Pathname ] ) }
5868 def package_glob_patterns
59- config . roots . flat_map do |root |
60- absolute_root = Private . root . join ( root )
61- [
62- *absolute_root . glob ( "*/#{ PACKAGE_FILE } " ) ,
63- *absolute_root . glob ( "*/*/#{ PACKAGE_FILE } " )
64- ]
69+ absolute_root = Private . root
70+ config . pack_paths . flat_map do |pack_path |
71+ Pathname . glob ( absolute_root . join ( pack_path ) . join ( PACKAGE_FILE ) )
6572 end
6673 end
6774 end
Load diff This file was deleted.
Original file line number Diff line number Diff line change 11# typed: strict
22
3+ require 'packs/private/configuration'
4+
35module Packs
46 module Private
57 extend T ::Sig
Original file line number Diff line number Diff line change 1+ # typed: strict
2+
3+ module Packs
4+ module Private
5+ class Configuration < T ::Struct
6+ extend T ::Sig
7+ DEFAULT_PACK_PATHS = T . let ( [
8+ 'packs/*' ,
9+ 'packs/*/*' ,
10+ ] , T ::Array [ String ] )
11+
12+ prop :pack_paths , T ::Array [ String ]
13+
14+ sig { returns ( Configuration ) }
15+ def self . fetch
16+ configuration_path = Pathname . new ( 'packs.yml' )
17+ config_hash = configuration_path . exist? ? YAML . load_file ( 'packs.yml' ) : { }
18+
19+ new (
20+ pack_paths : pack_paths ( config_hash ) ,
21+ )
22+ end
23+
24+ sig { params ( config_hash : T ::Hash [ T . untyped , T . untyped ] ) . returns ( T ::Array [ String ] ) }
25+ def self . pack_paths ( config_hash )
26+ specified_pack_paths = config_hash [ 'pack_paths' ]
27+ if specified_pack_paths . nil?
28+ DEFAULT_PACK_PATHS . dup
29+ else
30+ Array ( specified_pack_paths )
31+ end
32+ end
33+ end
34+ end
35+ end
Original file line number Diff line number Diff line change 11Gem ::Specification . new do |spec |
22 spec . name = 'packs'
3- spec . version = '0.0.2 '
3+ spec . version = '0.0.3 '
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.'
Original file line number Diff line number Diff line change 2020 end
2121
2222 context 'in an app with a differently configured root' do
23+ before do
24+ write_file ( 'packs/my_pack/package.yml' )
25+ write_file ( 'components/my_pack/package.yml' )
26+ write_file ( 'packs.yml' , <<~YML )
27+ pack_paths:
28+ - packs/*
29+ - components/*
30+ YML
31+ end
32+
33+ it { expect ( Packs . all . count ) . to eq 2 }
34+ end
35+
36+ context 'in an app with a differently configured root configured via ruby' do
2337 before do
2438 write_file ( 'packs/my_pack/package.yml' )
2539 write_file ( 'components/my_pack/package.yml' )
2640 Packs . configure do |config |
27- config . roots = %w[ components packs ]
41+ config . pack_paths = [ ' packs/*' , 'components/*' ]
2842 end
2943 end
3044
5569 before do
5670 write_file ( 'packs/my_pack/package.yml' )
5771 write_file ( 'components/my_pack/package.yml' )
58- Packs . configure do |config |
59- config . roots = %w[ components packs ]
60- end
72+ write_file ( 'packs.yml' , <<~YML )
73+ pack_paths:
74+ - packs/*
75+ - components/*
76+ YML
6177 end
6278
6379 it { expect ( Packs . find ( 'packs/my_pack' ) . name ) . to eq 'packs/my_pack' }
Original file line number Diff line number Diff line change 1717
1818 config . before do
1919 Packs . bust_cache!
20- Packs . configure do |packs_config |
21- packs_config . roots = [ 'packs' ]
22- end
2320 end
2421
2522 config . around do |example |
You can’t perform that action at this time.
0 commit comments