Sha256: 63b41d94749da9aa5d51f81e9db57b6873fe8a2a54a906b14683d94234e63615

Contents?: true

Size: 855 Bytes

Versions: 1

Compression:

Stored size: 855 Bytes

Contents

module Ocp::Registry::Common

	class << self

		def uuid
      SecureRandom.uuid
    end

    def gen_password
			SecureRandom.base64
		end

		def parse_email(email)
			return unless email =~ /[a-z0-9_.-]+@[a-z0-9-]+\.[a-z.]+/
				email =~ /([a-z0-9_.-]+)@([a-z0-9-]+\.[a-z.]+)/
				{
					:name => $1 ,
					:domain => $2
				}
		end

		def hash_filter(hash, fields = [])
			copy = deep_copy(hash)
			do_hash_filter(copy, fields)
		end

		def deep_copy(o)
  		Marshal.load(Marshal.dump(o))
		end

		def json_merge(a,b,reverse = false)
			hash_a = Yajl::load a 
			hash_b = Yajl::load b
			if reverse
				b.merge a
			else
				a.merge b
			end
		end

		private 

		def do_hash_filter(hash, fields = [])
			hash.keep_if do |k,v|
				if v.is_a? Hash
					do_hash_filter(v, fields)
					!v.empty?
				else
					fields.include? k
				end
			end
		end
	end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ocp_registry-0.0.1.alpha lib/ocp_registry/common.rb