Class: PuppetGenerator::Middleware::ReadInput

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet_generator/middleware/read_input.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ ReadInput

Returns a new instance of ReadInput.



5
6
7
# File 'lib/puppet_generator/middleware/read_input.rb', line 5

def initialize(app)
  @app = app
end

Instance Method Details

#call(task) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/puppet_generator/middleware/read_input.rb', line 9

def call(task)
  PuppetGenerator.logger.debug(self.class.name){ "Read data from input \"#{task.meta[:source]}\"." }

  raise Exceptions::FilesystemError unless PuppetGenerator::Models::Importer.existing_source?(task.meta[:source].to_s)
  raise Exceptions::InvalidSource   unless PuppetGenerator::Models::Importer.valid_source?(task.meta[:source].to_s)

  importer = PuppetGenerator::Models::Importer.find( reads_from: task.meta[:source].to_s, enabled: true )
  raise PuppetGenerator::Exceptions::InvalidSource unless importer 
  PuppetGenerator.logger.debug(self.class.name){ "Using importer \"#{importer.name}\" to read data." }

  PuppetGenerator.logger.info(self.class.name){ "Reading input from \"#{importer.name}\"." }
  task.body = importer.read( task.meta[:source] )
  PuppetGenerator.logger.debug(self.class.name) { "Count input lines: #{task.body.size}" }

  @app.call(task)
end