Class: Bricolage::SrcTableParam

Inherits:
Param
  • Object
show all
Defined in:
lib/bricolage/parameters.rb

Instance Attribute Summary

Attributes inherited from Param

#arg_spec, #description, #name

Instance Method Summary collapse

Methods inherited from Param

#have_arg?, #inspect, #optional?, #publish?, #required?

Constructor Details

#initialize(name = 'src-tables', arg_spec = 'VAR:[SCHEMA.]TABLE', description = 'Source table name.', optional: true, publish: true) ⇒ SrcTableParam

Returns a new instance of SrcTableParam.



523
524
525
526
527
528
529
530
531
# File 'lib/bricolage/parameters.rb', line 523

def initialize(
    name = 'src-tables',
    arg_spec = 'VAR:[SCHEMA.]TABLE',
    description = 'Source table name.',
    optional: true,   # Source tables may not exist (e.g. data loading)
    publish: true
)
  super name, arg_spec, description, optional: optional, publish: publish
end

Instance Method Details

#default_value(ctx, vars) ⇒ Object



551
552
553
# File 'lib/bricolage/parameters.rb', line 551

def default_value(ctx, vars)
  {}
end

#materialize(h, ctx, vars) ⇒ Object



555
556
557
558
559
560
561
# File 'lib/bricolage/parameters.rb', line 555

def materialize(h, ctx, vars)
  map = {}
  h.each do |name, spec|
    map[name] = TableSpec.parse(expand(spec, vars))
  end
  map
end

#option_nameObject



533
534
535
# File 'lib/bricolage/parameters.rb', line 533

def option_name
  'src-table'
end

#parse_option_value(value, h) ⇒ Object



537
538
539
540
541
542
543
544
# File 'lib/bricolage/parameters.rb', line 537

def parse_option_value(value, h)
  var, spec = value.split(':', 2)
  if not var or var.empty?
    raise ParameterError, "missing variable name: #{value.inspect}"
  end
  (h ||= {})[var] = spec
  h   # accumulator
end

#parse_value(h) ⇒ Object

Raises:



546
547
548
549
# File 'lib/bricolage/parameters.rb', line 546

def parse_value(h)
  raise ParameterError, "bad type for parameter #{name}: #{h.class}" unless h.kind_of?(Hash)
  h.empty? ? nil : h
end

#variables(h) ⇒ Object



563
564
565
# File 'lib/bricolage/parameters.rb', line 563

def variables(h)
  h.map {|name, value| ResolvedVariable.new(name, value.to_s) }
end