Class: Gizzard::Transformation::Op::AddLink

Inherits:
LinkOp show all
Defined in:
lib/gizzard/transformation_op.rb

Instance Attribute Summary

Attributes inherited from LinkOp

#from, #to

Instance Method Summary collapse

Methods inherited from LinkOp

#eql?, #initialize, #inverse?

Methods inherited from BaseOp

#<=>, #eql?, #inspect, #inverse?, #involved_shards

Constructor Details

This class inherits a constructor from Gizzard::Transformation::Op::LinkOp

Instance Method Details

#apply(nameserver, table_id, base_id, table_prefix, translations) ⇒ Object



123
124
125
126
127
128
# File 'lib/gizzard/transformation_op.rb', line 123

def apply(nameserver, table_id, base_id, table_prefix, translations)
  from_shard_id = from.to_shard_id(table_prefix, translations)
  to_shard_id   = to.to_shard_id(table_prefix, translations)

  nameserver.add_link(from_shard_id, to_shard_id, to.weight)
end

#expand(copy_source, involved_in_copy) ⇒ Object



113
114
115
116
117
118
119
120
121
# File 'lib/gizzard/transformation_op.rb', line 113

def expand(copy_source, involved_in_copy)
  if involved_in_copy && @wrapper_type
    wrapper = ShardTemplate.new(@wrapper_type, to.host, to.weight, '', '', [to])
    { :prepare => [AddLink.new(from, wrapper)],
      :cleanup => [self, RemoveLink.new(from, wrapper)] }
  else
    { :prepare => [self] }
  end
end