Class: ConfigKit::Data::Loader
- Inherits:
-
Object
- Object
- ConfigKit::Data::Loader
- Defined in:
- lib/config_kit/data/loader.rb
Direct Known Subclasses
Defined Under Namespace
Classes: LoaderFailure
Instance Attribute Summary collapse
-
#batch_size ⇒ Object
readonly
Returns the value of attribute batch_size.
-
#cursor ⇒ Object
readonly
Returns the value of attribute cursor.
-
#files ⇒ Object
readonly
Returns the value of attribute files.
Class Method Summary collapse
- .err(message) ⇒ Object
- .info(message) ⇒ Object
- .inherited(subclass) ⇒ Object
- .load(app, from, uri_kls, env, codename, version, &block) ⇒ Object
Instance Method Summary collapse
- #file_count ⇒ Object
- #finish? ⇒ Boolean
-
#initialize(batch_size = 10) ⇒ Loader
constructor
A new instance of Loader.
- #next_batch ⇒ Object
- #next_cursor ⇒ Object
- #retrieve_files ⇒ Object
Constructor Details
#initialize(batch_size = 10) ⇒ Loader
Returns a new instance of Loader.
55 56 57 58 59 60 61 |
# File 'lib/config_kit/data/loader.rb', line 55 def initialize(batch_size=10) @files = [] @batch_size = batch_size @current_files = [] @cursor = 0 @files = retrieve_files end |
Instance Attribute Details
#batch_size ⇒ Object (readonly)
Returns the value of attribute batch_size.
54 55 56 |
# File 'lib/config_kit/data/loader.rb', line 54 def batch_size @batch_size end |
#cursor ⇒ Object (readonly)
Returns the value of attribute cursor.
54 55 56 |
# File 'lib/config_kit/data/loader.rb', line 54 def cursor @cursor end |
#files ⇒ Object (readonly)
Returns the value of attribute files.
54 55 56 |
# File 'lib/config_kit/data/loader.rb', line 54 def files @files end |
Class Method Details
.err(message) ⇒ Object
18 19 20 |
# File 'lib/config_kit/data/loader.rb', line 18 def self.err() STDERR.puts end |
.info(message) ⇒ Object
14 15 16 |
# File 'lib/config_kit/data/loader.rb', line 14 def self.info() STDOUT.puts end |
.inherited(subclass) ⇒ Object
25 26 27 |
# File 'lib/config_kit/data/loader.rb', line 25 def self.inherited(subclass) @loaders << subclass end |
.load(app, from, uri_kls, env, codename, version, &block) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/config_kit/data/loader.rb', line 32 def self.load(app, from, uri_kls, env, codename, version, &block) @loader_names = @loaders.map{ |l| l.loader} @uri_kls, @env, @app, @version, @codename = uri_kls, env, app, version, codename loader = from if loader.nil? ConfigKit.logger.error "from empty source with #{@uri_kls.to_s}" elsif !@loader_names.include?(loader) ConfigKit.logger.error "Unrecognize loader: #{loader} for #{@uri}(#{@codename})" else loader_class = @loaders.find{ |c| c.loader == loader} ConfigKit.logger.debug "#{loader_class.loader} is loading env(#{@env}) app(#{app}) data(#{@version}) codename(#{codename}) from #{uri_kls.to_s}" loader_class.new(@uri_kls, @env, @codename, @app, @version).run(&block) ConfigKit.logger.debug "#{loader_class.loader} is loaded env(#{@env}) app(#{app}) data(#{@version}) codename(#{codename}) from #{uri_kls.to_s}" end rescue => e raise ConfigKit::Data::Loader::LoaderFailure.new e. end |
Instance Method Details
#file_count ⇒ Object
63 64 65 |
# File 'lib/config_kit/data/loader.rb', line 63 def file_count @files.count end |
#finish? ⇒ Boolean
82 83 84 |
# File 'lib/config_kit/data/loader.rb', line 82 def finish? @cursor >= file_count end |
#next_batch ⇒ Object
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/config_kit/data/loader.rb', line 67 def next_batch if finish? @current_files = [] @cursor = file_count return @cursor end _next_cursor = next_cursor @current_files = @files[@cursor.._next_cursor - 1] @cursor = _next_cursor end |
#next_cursor ⇒ Object
78 79 80 |
# File 'lib/config_kit/data/loader.rb', line 78 def next_cursor @cursor + @batch_size > file_count ? file_count : (@cursor + @batch_size) end |
#retrieve_files ⇒ Object
86 87 88 |
# File 'lib/config_kit/data/loader.rb', line 86 def retrieve_files raise NotImplementedError end |