Class: Gizzard::TransformTreeCommand

Inherits:
BaseTransformCommand show all
Defined in:
lib/gizzard/commands.rb

Instance Attribute Summary

Attributes inherited from Command

#argv, #buffer, #command_options, #global_options, #job_injector, #manager

Instance Method Summary collapse

Methods inherited from BaseTransformCommand

#run

Methods inherited from Command

classify, #confirm!, #get_base_name, #help!, #initialize, make_job_injector, make_manager, #output, #require_tables, #require_template_options, run

Constructor Details

This class inherits a constructor from Gizzard::Command

Instance Method Details

#get_transformationsObject



850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
# File 'lib/gizzard/commands.rb', line 850

def get_transformations
  help!("must have an even number of arguments") unless @argv.length % 2 == 0
  require_template_options

  scheduler_options = command_options.scheduler_options || {}
  copy_wrapper   = scheduler_options[:copy_wrapper]
  skip_copies    = scheduler_options[:skip_copies] || false
  transformations   = {}

  memoized_transforms = {}
  @argv.each_slice(2) do |(template_s, shard_id_s)|
    to_template    = ShardTemplate.parse(template_s)
    shard_id       = ShardId.parse(shard_id_s)
    base_name      = shard_id.table_prefix.split('_').first
    forwarding     = manager.get_forwarding_for_shard(shard_id)
    manifest       = manager.manifest(forwarding.table_id)
    shard          = manifest.trees[forwarding]

    transform_args = [shard.template, to_template, copy_wrapper, skip_copies]
    transformation = memoized_transforms.fetch(transform_args) do |args|
      memoized_transforms[args] = Transformation.new(*args)
    end
    tree = transformations.fetch(transformation) do |t|
      transformations[t] = {}
    end
    tree[forwarding] = shard
  end

  transformations
end