Module: Thingfish::Normalization

Included in:
Strelka::HTTPRequest::Metadata, Datastore, Metastore, Metastore::Memory
Defined in:
lib/thingfish/mixins.rb

Overview

A collection of functions for dealing with object IDs.

Class Method Summary collapse

Class Method Details

.make_object_idObject

Generate a new object ID.



19
20
21
# File 'lib/thingfish/mixins.rb', line 19

def make_object_id
	return normalize_oid( SecureRandom.uuid )
end

.normalize_key(key) ⇒ Object

Return a normalized copy of key.



47
48
49
# File 'lib/thingfish/mixins.rb', line 47

def normalize_key( key )
	return key.to_s.downcase.gsub( /[^\w:]+/, '_' )
end

.normalize_keys(collection) ⇒ Object

Return a copy of the given collection after being normalized.



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/thingfish/mixins.rb', line 31

def normalize_keys( collection )
	if collection.respond_to?( :keys )
		return collection.each_with_object({}) do |(key,val),new_hash|
			n_key = normalize_key( key )
			new_hash[ n_key ] = val
		end

	elsif collection.respond_to?( :map )
		return collection.map {|key| normalize_key(key) }
	end

	return nil
end

.normalize_oid(oid) ⇒ Object

Normalize the given oid.



25
26
27
# File 'lib/thingfish/mixins.rb', line 25

def normalize_oid( oid )
	return oid.to_s.downcase
end