Class: DirModel::Import::Dir
- Inherits:
-
Object
- Object
- DirModel::Import::Dir
- Extended by:
- Forwardable
- Defined in:
- lib/dir_model/import/dir.rb
Overview
File
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#current_dir_model ⇒ Object
readonly
Returns the value of attribute current_dir_model.
-
#import_dir_model_class ⇒ Object
readonly
Returns the value of attribute import_dir_model_class.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#previous_dir_model ⇒ Object
readonly
Returns the value of attribute previous_dir_model.
Instance Method Summary collapse
- #each(context = {}) ⇒ Object
-
#initialize(source_path, import_dir_model_class, context = {}) ⇒ Dir
constructor
A new instance of Dir.
- #next(context = {}) ⇒ Object
- #reset ⇒ Object
Constructor Details
#initialize(source_path, import_dir_model_class, context = {}) ⇒ Dir
17 18 19 20 |
# File 'lib/dir_model/import/dir.rb', line 17 def initialize(source_path, import_dir_model_class, context={}) @path, @import_dir_model_class, @context = Path.new(source_path), import_dir_model_class, context.to_h.symbolize_keys reset end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
11 12 13 |
# File 'lib/dir_model/import/dir.rb', line 11 def context @context end |
#current_dir_model ⇒ Object (readonly)
Returns the value of attribute current_dir_model.
12 13 14 |
# File 'lib/dir_model/import/dir.rb', line 12 def current_dir_model @current_dir_model end |
#import_dir_model_class ⇒ Object (readonly)
Returns the value of attribute import_dir_model_class.
10 11 12 |
# File 'lib/dir_model/import/dir.rb', line 10 def import_dir_model_class @import_dir_model_class end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
8 9 10 |
# File 'lib/dir_model/import/dir.rb', line 8 def index @index end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
9 10 11 |
# File 'lib/dir_model/import/dir.rb', line 9 def path @path end |
#previous_dir_model ⇒ Object (readonly)
Returns the value of attribute previous_dir_model.
13 14 15 |
# File 'lib/dir_model/import/dir.rb', line 13 def previous_dir_model @previous_dir_model end |
Instance Method Details
#each(context = {}) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/dir_model/import/dir.rb', line 28 def each(context={}) return to_enum(__callee__) unless block_given? while self.next(context) next if skip? yield current_dir_model end end |
#next(context = {}) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/dir_model/import/dir.rb', line 37 def next(context={}) return if end? context = context.to_h.reverse_merge(self.context) @previous_dir_model = current_dir_model @current_dir_model = import_dir_model_class.next(path, context, previous_dir_model) @index += 1 @current_dir_model = @index = nil if end? current_dir_model end |
#reset ⇒ Object
22 23 24 25 26 |
# File 'lib/dir_model/import/dir.rb', line 22 def reset path.reset! @index = -1 @current_dir_model = nil end |