Module: Kernel

Defined in:
lib/versioned_blocks.rb

Instance Method Summary collapse

Instance Method Details

#versioned_block(opts = {}, &block) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/versioned_blocks.rb', line 70

def versioned_block(opts = {}, &block)
  versions_to_test = VersionedBlocks.versions_from_opts(opts)
  if block.arity == 2 # if block is asking for the uri and the version
    base_uri = VersionedBlocks.base_uri_from_opts(opts)
    versions = versions_to_test.map{|num| [num, "#{base_uri}v#{num}"]}
  else # just return the version 
    versions = versions_to_test.to_a
  end
  versions.each do |v, uri|
    begin
      block.call(v, uri)
    rescue Exception=> e
      e.message.prepend("When version = #{v}: ") if VersionedBlocks.prepend_errors || (opts[:override]==true && opts[:prepend_errors]==true)
      raise e
    end
  end
end