module Tainers
Public Class Methods
hash(structure) → consistent hash hexdigest
click to toggle source
Produces a consistent hash hexdigest string for the input structure, handling arrays, hashes, strings, numbers, nesting of such structures, etc.
Hash keys are sorted prior to computing the digest, to ensure that hashes that would be regarded as equal produce the same digest.
Tainers.hash({"a" => "foo", "b" => "bar"}) #=> "5427f704439548cae1911616e2bec3b7cc2dd11c"
# File lib/tainers/hash.rb, line 15 def self.hash structure str = structured_string(structure) Digest::SHA1.hexdigest str end
named_parameters_for(params)
click to toggle source
# File lib/tainers/specification.rb, line 202 def self.named_parameters_for params p = params.dup prefix = p.delete('prefix') prefix = if prefix.nil? || prefix == '' 'Tainers' else prefix.downcase end suffix = p.delete('suffix') suffix = if suffix.nil? '' else "-#{suffix.downcase}" end digest = hash(p) p['name'] = "#{prefix}-#{digest}#{suffix}" p end
specify(args={})
click to toggle source
Returns an image-pulling container specification from the given parameters.
Enforces the naming conventions such that the name for the container will have prefix, suffix, and spec-derived hash as documented elsewhere.
The result will be an instance of Tainers::Specification::ImagePuller
.
# File lib/tainers/specification.rb, line 196 def self.specify args={} Specification::ImagePuller.new( Specification::Bare.new named_parameters_for(args) ) end
Private Class Methods
consistent_structure(structure)
click to toggle source
# File lib/tainers/hash.rb, line 22 def self.consistent_structure structure if Hash === structure s = structure.keys.sort.inject(["{"]) do |a, key| a << consistent_structure(key) a << consistent_structure(structure[key]) a end s << "}" s elsif Array === structure s = structure.collect {|item| consistent_structure item} s.unshift "[" s << "]" s else structure end end
structured_string(structure)
click to toggle source
# File lib/tainers/hash.rb, line 41 def self.structured_string structure consistent_structure(structure).to_json end