class ConfigKit::Data::FileLoader
Attributes
files[R]
Public Class Methods
loader()
click to toggle source
# File lib/config_kit/data/loaders/file_loader.rb, line 4 def self.loader; "file"; end
new(uri_kls, env, app, branch)
click to toggle source
Calls superclass method
ConfigKit::Data::Loader::new
# File lib/config_kit/data/loaders/file_loader.rb, line 7 def initialize(uri_kls, env, app, branch) @uri_kls, @env, @app, @branch = uri_kls, env, app, branch @path = File.expand_path('.',File.join(retrieve_path(@uri_kls.path),env)) super() end
Public Instance Methods
retrieve_files()
click to toggle source
# File lib/config_kit/data/loaders/file_loader.rb, line 37 def retrieve_files files = if @app == 'all' Dir["#{@path}/**/*.yml"].select { |f| match_for?(f, @env) } else Dir["#{@path}/**/*.yml"].select {|f| match_for?(f, @app) && match_for?(f, @env)} end raise ConfigKit::Data::Loader::LoaderFailure.new('No data file found.') if files.empty? files end
run(&block)
click to toggle source
# File lib/config_kit/data/loaders/file_loader.rb, line 13 def run(&block) return run_all unless block run_batch(&block) end
run_all()
click to toggle source
# File lib/config_kit/data/loaders/file_loader.rb, line 18 def run_all files_data = {} @files.each do |f| files_data.merge!(load_one(f)) end files_data end
run_batch(&block)
click to toggle source
# File lib/config_kit/data/loaders/file_loader.rb, line 26 def run_batch(&block) while !finish? next_batch files_data = {} @current_files.each do |f| files_data.merge!(load_one(f)) end block.call(files_data) end end
Private Instance Methods
env_app_for(f)
click to toggle source
# File lib/config_kit/data/loaders/file_loader.rb, line 54 def env_app_for(f) File.basename(f).split('.')[0..1] end
load_one(f)
click to toggle source
# File lib/config_kit/data/loaders/file_loader.rb, line 58 def load_one(f) env, app = env_app_for(f) raise ConfigKit::Data::Loader::LoaderFailure.new("Wrong data file env(#{env}) for loaded #{@env}") unless env == @env {app => YAML.load_file(f)} end
match_for?(f,info)
click to toggle source
# File lib/config_kit/data/loaders/file_loader.rb, line 64 def match_for?(f,info) File.basename(f).split('.').find {|a| a == info} end
retrieve_path(path)
click to toggle source
# File lib/config_kit/data/loaders/file_loader.rb, line 48 def retrieve_path(path) split_path = path[1..-1].split('/') return path[1..-1] if split_path[0] == '.' path end