Class: ConfigKit::Data::FileLoader

Inherits:
Loader
  • Object
show all
Defined in:
lib/config_kit/data/loaders/file_loader.rb

Instance Attribute Summary collapse

Attributes inherited from Loader

#batch_size, #cursor

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Loader

err, #file_count, #finish?, info, inherited, load, #next_batch, #next_cursor

Constructor Details

#initialize(uri_kls, env, codename, app, branch) ⇒ FileLoader

Returns a new instance of FileLoader.



7
8
9
10
11
# File 'lib/config_kit/data/loaders/file_loader.rb', line 7

def initialize(uri_kls, env, codename, app, branch)
  @uri_kls, @env, @codename, @app, @branch = uri_kls, env, codename, app, branch
  @path = File.expand_path('.',File.join(retrieve_path(@uri_kls.path),@codename))
  super()
end

Instance Attribute Details

#filesObject (readonly)

Returns the value of attribute files.



6
7
8
# File 'lib/config_kit/data/loaders/file_loader.rb', line 6

def files
  @files
end

Class Method Details

.loaderObject



4
# File 'lib/config_kit/data/loaders/file_loader.rb', line 4

def self.loader; "file"; end

Instance Method Details

#retrieve_filesObject



37
38
39
40
41
42
43
44
45
# 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, @codename) }
  else
    Dir["#{@path}/**/*.yml"].select {|f| match_for?(f, @app) && match_for?(f, @codename)}
  end
  raise ConfigKit::Data::Loader::LoaderFailure.new('No data file found.') if files.empty?
  files
end

#run(&block) ⇒ Object



13
14
15
16
# File 'lib/config_kit/data/loaders/file_loader.rb', line 13

def run(&block)
  return run_all unless block
  run_batch(&block)
end

#run_allObject



18
19
20
21
22
23
24
# 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) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# 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