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.



250
251
252
253
254
255
256
# File 'lib/liquidoc.rb', line 250

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

Instance Method Details

#buildsObject



282
283
284
# File 'lib/liquidoc.rb', line 282

def builds
  return @step['builds']
end

#dataObject



262
263
264
# File 'lib/liquidoc.rb', line 262

def data
  return @step['data']
end

#messageObject



286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
# File 'lib/liquidoc.rb', line 286

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



274
275
276
# File 'lib/liquidoc.rb', line 274

def options
  return @step['options']
end

#sourceObject



266
267
268
# File 'lib/liquidoc.rb', line 266

def source
  return @step['source']
end

#stageObject



278
279
280
# File 'lib/liquidoc.rb', line 278

def stage
  return @step['stage']
end

#targetObject



270
271
272
# File 'lib/liquidoc.rb', line 270

def target
  return @step['target']
end

#typeObject



258
259
260
# File 'lib/liquidoc.rb', line 258

def type
  return @step['action']
end

#validateObject



335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
# File 'lib/liquidoc.rb', line 335

def validate
  case self.type
  when "parse"
    reqs = ["data,builds"]
  when "migrate"
    reqs = ["source,target"]
  when "render"
    reqs = ["builds"]
  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 "ConfigStructError"
    end
  end
end