lib/review/catalog.rb in review-3.2.0 vs lib/review/catalog.rb in review-4.0.0

- old
+ new

@@ -1,45 +1,44 @@ require 'yaml' module ReVIEW class Catalog def initialize(file) - if file.respond_to? :read - @yaml = YAML.load(file.read) + if file.respond_to?(:read) + @yaml = YAML.safe_load(file.read, [Date]) else ## as Object @yaml = file end @yaml ||= {} end def predef - return '' unless @yaml['PREDEF'] - @yaml['PREDEF'].join("\n") + @yaml['PREDEF'] || [] end def chaps - return '' unless @yaml['CHAPS'] + return [] unless @yaml['CHAPS'] @yaml['CHAPS'].map do |entry| if entry.is_a?(String) entry elsif entry.is_a?(Hash) entry.values # chaps in a part end - end.flatten.join("\n") + end.flatten end def parts - return '' unless @yaml['CHAPS'] + return [] unless @yaml['CHAPS'] part_list = @yaml['CHAPS'].map do |entry| if entry.is_a?(Hash) entry.keys end end - part_list.flatten.compact.join("\n") + part_list.flatten.compact end def replace_part(old_name, new_name) @yaml['CHAPS'].map! do |e| if e.is_a?(Hash) and (e.keys.first == old_name) @@ -53,27 +52,25 @@ return [] unless @yaml['CHAPS'] @yaml['CHAPS'].flatten.compact end def appendix - return '' unless @yaml['APPENDIX'] - @yaml['APPENDIX'].join("\n") + @yaml['APPENDIX'] || [] end def postdef - return '' unless @yaml['POSTDEF'] - @yaml['POSTDEF'].join("\n") + @yaml['POSTDEF'] || [] end def to_s YAML.dump(@yaml).gsub(/\A---\n/, '') # remove yaml header end def validate!(config, basedir) filenames = [] if predef.present? - filenames.concat(predef.split(/\n/)) + filenames.concat(predef) end parts_with_chaps.each do |chap| if chap.is_a?(Hash) chap.each_key do |part| if File.extname(part) == '.re' @@ -84,13 +81,13 @@ else filenames.push(chap) end end if appendix.present? - filenames.concat(appendix.split(/\n/)) + filenames.concat(appendix) end if postdef.present? - filenames.concat(postdef.split(/\n/)) + filenames.concat(postdef) end filenames.each do |filename| refile = File.join(basedir, config['contentdir'], filename) unless File.exist?(refile) raise FileNotFound, "file not found in catalog.yml: #{refile}"