class ReVIEW::Catalog
Public Class Methods
new(file)
click to toggle source
# File lib/review/catalog.rb, line 6 def initialize(file) @yaml = if file.respond_to?(:read) YAMLLoader.safe_load(file.read) else ## as Object file end @yaml ||= {} end
Public Instance Methods
appendix()
click to toggle source
# File lib/review/catalog.rb, line 58 def appendix @yaml['APPENDIX'] || [] end
chaps()
click to toggle source
# File lib/review/catalog.rb, line 19 def 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 end
parts()
click to toggle source
# File lib/review/catalog.rb, line 31 def parts return [] unless @yaml['CHAPS'] part_list = @yaml['CHAPS'].map do |entry| if entry.is_a?(Hash) entry.keys end end part_list.flatten.compact end
parts_with_chaps()
click to toggle source
# File lib/review/catalog.rb, line 52 def parts_with_chaps return [] unless @yaml['CHAPS'] @yaml['CHAPS'].flatten.compact end
postdef()
click to toggle source
# File lib/review/catalog.rb, line 62 def postdef @yaml['POSTDEF'] || [] end
predef()
click to toggle source
# File lib/review/catalog.rb, line 15 def predef @yaml['PREDEF'] || [] end
replace_part(old_name, new_name)
click to toggle source
# File lib/review/catalog.rb, line 43 def replace_part(old_name, new_name) @yaml['CHAPS'].map! do |e| if e.is_a?(Hash) && (e.keys.first == old_name) e = { new_name => e.values.first } end e end end
to_s()
click to toggle source
# File lib/review/catalog.rb, line 66 def to_s YAML.dump(@yaml).gsub(/\A---\n/, '') # remove yaml header end
validate!(config, basedir)
click to toggle source
# File lib/review/catalog.rb, line 70 def validate!(config, basedir) filenames = [] if predef.present? 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' filenames.push(part) end end filenames.concat(chap.values.flatten) else filenames.push(chap) end end if appendix.present? filenames.concat(appendix) end if postdef.present? filenames.concat(postdef) end filenames.each do |filename| refile = File.expand_path(File.join(config['contentdir'], filename), basedir) unless File.exist?(refile) raise FileNotFound, "file not found in catalog.yml: #{refile}" end end end