Class: Herdic::Loader
- Inherits:
-
Object
- Object
- Herdic::Loader
- Includes:
- Enumerable
- Defined in:
- lib/herdic/loader.rb
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(file, original = nil) ⇒ Loader
constructor
A new instance of Loader.
- #load(file, original, included_from = nil) ⇒ Object
Constructor Details
#initialize(file, original = nil) ⇒ Loader
Returns a new instance of Loader.
9 10 11 |
# File 'lib/herdic/loader.rb', line 9 def initialize(file, original = nil) @file, @original = file, original end |
Instance Method Details
#each(&block) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/herdic/loader.rb', line 35 def each(&block) return unless block @block = block load @file, @original end |
#load(file, original, included_from = nil) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/herdic/loader.rb', line 13 def load(file, original, included_from = nil) file = File. file, included_from specs = '' File.open(file, 'r') do |f| specs = f.read end specs = Psych.load specs specs.each do |spec| spec['file'] = original || file if spec['include'] load spec['include'], nil, File.dirname(spec['file']) else @block.call spec end end end |