class Libis::Ingester::Database::Seed
Attributes
config[RW]
datadir[RW]
Public Class Methods
new(sources)
click to toggle source
# File lib/libis/ingester/database.rb, line 61 def initialize(sources) @datadir = [] @config = {} sources.each do |source| case source when Hash @config.merge!(source.key_symbols_to_strings(recursive: true)) when String raise RuntimeError, "'#{source}' not found." unless File.exist?(source) if File.directory?(source) @datadir << source elsif File.file?(source) cfg = read_yaml(source) cfg = cfg.seed if cfg.seed @config.merge(cfg) end else raise RuntimeError, 'Should supply a hash or file/directory name.' end end end
Public Instance Methods
load_data()
click to toggle source
noinspection RubyResolve
# File lib/libis/ingester/database.rb, line 84 def load_data load_organization load_user load_access_right load_retention_period load_representation_info load_ingest_model load_workflow load_job end
Private Instance Methods
each_config(postfix) { |c| ... }
click to toggle source
# File lib/libis/ingester/database.rb, line 119 def each_config(postfix) case (cfg = @config[postfix]) when Array cfg.map {|c| yield c} when Hash yield cfg else #skip end @datadir.each do |dir| Dir.glob("*_#{postfix}.cfg", base: dir).each do |filename| full_name = File.join(dir, filename) yield read_yaml(full_name), full_name end end end
each_config_(postfix) { |cfg| ... }
click to toggle source
# File lib/libis/ingester/database.rb, line 136 def each_config_(postfix) cfg_list = [] @datadir.each do |dir| Dir.entries(dir).each do |filename| next unless filename =~ /_#{postfix}\.cfg$/ cfg_list << read_yaml(File.join(dir, filename)) end end case @config[postfix] when Array cfg_list += @config[postfix] when Hash cfg_list << @config[postfix] else #skip end cfg_list.compact.map do |cfg| block_given? ? yield(cfg) : cfg end end
load_config(options = {}) { |cfg| ... }
click to toggle source
# File lib/libis/ingester/database.rb, line 111 def load_config(options = {}) each_config(options[:postfix]) do |cfg, fname = 'site config'| puts " - #{cfg['name']} [#{fname}]" if cfg['name'] yield(cfg) if block_given? options[:klass].from_hash(cfg) end end
method_missing(name, *args, &block)
click to toggle source
Calls superclass method
# File lib/libis/ingester/database.rb, line 97 def method_missing(name, *args, &block) if name =~ /^load_(.*)$/ puts "Loading #{$1}s ..." options = { postfix: $1.to_s, klass: "Libis::Ingester::#{$1.classify}".constantize } options.merge!(args[0]) if args[0] && args[0].is_a?(Hash) load_config options, &block else super end end
read_yaml(file)
click to toggle source
# File lib/libis/ingester/database.rb, line 157 def read_yaml(file) config = Libis::Tools::ConfigFile.new({}, preserve_original_keys: false) config << file config.to_h.key_symbols_to_strings(recursive: true) rescue StandardError => e puts "ERROR while parsing file '#{file}'" raise e end