Class: BuildConfigStep

Inherits:
Object
  • Object
show all
Defined in:
lib/liquidoc.rb

Overview

class BuildConfig

Instance Method Summary collapse

Constructor Details

#initialize(step) ⇒ BuildConfigStep

Returns a new instance of BuildConfigStep.



302
303
304
305
306
307
308
309
# File 'lib/liquidoc.rb', line 302

def initialize step
  @step = step
  if (defined?(@step['action'])).nil?
    raise "StepStructError"
  end
  @step['options'] = nil unless defined?(step['options'])
  validate()
end

Instance Method Details

#buildsObject



339
340
341
# File 'lib/liquidoc.rb', line 339

def builds
  return @step['builds']
end

#commandObject



331
332
333
# File 'lib/liquidoc.rb', line 331

def command
  return @step['command']
end

#dataObject



315
316
317
# File 'lib/liquidoc.rb', line 315

def data
  return @step['data']
end

#messageObject



343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
# File 'lib/liquidoc.rb', line 343

def message
  # dynamically build a human-friendly log message, possibly appending a reason
  unless @step['message']
    reason = ", #{@step['reason']}" if @step['reason']
    noninclusively = ", without carrying the parent directory" if self.options.is_a?(Hash) && self.options['inclusive'] == false && File.directory?(self.source)
    stage = "" ; stage = "[#{self.stage}] " if self.stage
    case self.type
    when "migrate"
      text = ". #{stage}Copies `#{self.source}` to `#{self.target}`#{noninclusively}#{reason}."
    when "parse"
      if self.data.is_a? Array
        if self.data.count > 1
          text = ". Draws data from the following files:"
          self.data.each do |file|
            text.concat("\n  * `#{file}`.")
          end
          text.concat("\n")
        else
          text = ". #{stage}Draws data from `#{self.data[0]}`"
        end
      else
        if self.data
          text = ". #{stage}Draws data from `#{self.data['file']}`"
        else
          text = ". #{stage}Uses data passed via CLI --var options."
        end
      end
      text.concat("#{reason},") if reason
      text.concat(" and parses it as follows:")
      return text
    when "render"
      if self.source
        text = ". #{stage}Using the index file `#{self.source}` as a map#{reason}, and ingesting AsciiDoc attributes from "
        if self.data.is_a? Array
          text.concat("the following data files:")
          self.data.each do |file|
            text.concat("\n  * `#{file}`.")
          end
        else
          text.concat("`#{self.data}`")
        end
        return text
      end
    end
  else
    return @step['message']
  end
end

#optionsObject



327
328
329
# File 'lib/liquidoc.rb', line 327

def options
  return @step['options']
end

#sourceObject



319
320
321
# File 'lib/liquidoc.rb', line 319

def source
  return @step['source']
end

#stageObject



335
336
337
# File 'lib/liquidoc.rb', line 335

def stage
  return @step['stage']
end

#targetObject



323
324
325
# File 'lib/liquidoc.rb', line 323

def target
  return @step['target']
end

#typeObject



311
312
313
# File 'lib/liquidoc.rb', line 311

def type
  return @step['action']
end

#validateObject



392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
# File 'lib/liquidoc.rb', line 392

def validate
  case self.type
  when "parse"
    reqs = ["data,builds"]
  when "migrate"
    reqs = ["source,target"]
  when "render"
    reqs = ["builds"]
  when "execute"
    reqs = ["command"]
  end
  for req in reqs
    if (defined?(@step[req])).nil?
      @logger.error "Every #{@step['action']}-type in the configuration file needs a '#{req}' declaration."
      raise "ConfigStepError"
    end
  end
end