@@ -13,9 +13,9 @@ class FileResources
1313 # Public method: Convert file resources to text. See the description of the class
1414 # just above for details.
1515 # @param obj [OctocatalogDiff::Catalog] Catalog object (will be modified)
16- def self . convert_file_resources ( obj )
16+ def self . convert_file_resources ( obj , environment = 'production' )
1717 return unless obj . valid? && obj . compilation_dir . is_a? ( String ) && !obj . compilation_dir . empty?
18- _convert_file_resources ( obj . resources , obj . compilation_dir )
18+ _convert_file_resources ( obj . resources , obj . compilation_dir , environment )
1919 begin
2020 obj . catalog_json = ::JSON . generate ( obj . catalog )
2121 rescue ::JSON ::GeneratorError => exc
@@ -45,36 +45,39 @@ def self.file_path(src, modulepaths)
4545 end
4646
4747 # Internal method: Parse environment.conf to find the modulepath
48- # @param compilation_dir [String] Compilation directory
48+ # @param dir [String] Directory in which to look for environment.conf
4949 # @return [Array] Module paths
50- def self . module_path ( compilation_dir )
51- environment_conf = File . join ( compilation_dir , 'environment.conf' )
52- unless File . file? ( environment_conf )
53- return [ File . join ( compilation_dir , 'modules' ) ]
54- end
50+ def self . module_path ( dir )
51+ environment_conf = File . join ( dir , 'environment.conf' )
52+ return [ File . join ( dir , 'modules' ) ] unless File . file? ( environment_conf )
5553
5654 # This doesn't support multi-line, continuations with backslash, etc.
5755 # Does it need to??
5856 if File . read ( environment_conf ) =~ /^modulepath\s *=\s *(.+)/
59- Regexp . last_match ( 1 ) . split ( /:/ ) . map ( &:strip ) . reject { |x | x =~ /^\$ / } . map { |x | File . join ( compilation_dir , x ) }
57+ result = [ ]
58+ Regexp . last_match ( 1 ) . split ( /:/ ) . map ( &:strip ) . each do |path |
59+ next if path . start_with? ( '$' )
60+ result << File . expand_path ( path , dir )
61+ end
62+ result
6063 else
61- [ File . join ( compilation_dir , 'modules' ) ]
64+ [ File . join ( dir , 'modules' ) ]
6265 end
6366 end
6467
6568 # Internal method: Static method to convert file resources. The compilation directory is
6669 # required, or else this is a no-op. The passed-in array of resources is modified by this method.
6770 # @param resources [Array<Hash>] Array of catalog resources
6871 # @param compilation_dir [String] Compilation directory (so files can be looked up)
69- def self . _convert_file_resources ( resources , compilation_dir )
72+ def self . _convert_file_resources ( resources , compilation_dir , environment = 'production' )
7073 # Calculate compilation directory. There is not explicit error checking here because
7174 # there is on-demand, explicit error checking for each file within the modification loop.
7275 return unless compilation_dir . is_a? ( String ) && compilation_dir != ''
7376
74- # Making sure that compilation_dir/environments/production /modules exists (and by inference,
75- # that compilation_dir/environments/production is pointing at the right place). Otherwise, try to find
77+ # Making sure that compilation_dir/environments/<env> /modules exists (and by inference,
78+ # that compilation_dir/environments/<env> is pointing at the right place). Otherwise, try to find
7679 # compilation_dir/modules. If neither of those exist, this code can't run.
77- env_dir = File . join ( compilation_dir , 'environments' , 'production' )
80+ env_dir = File . join ( compilation_dir , 'environments' , environment )
7881 modulepaths = module_path ( env_dir ) + module_path ( compilation_dir )
7982 modulepaths . select! { |x | File . directory? ( x ) }
8083 return if modulepaths . empty?
0 commit comments