class Gibbler

Attributes

debug[RW]

Set to true for debug output (including all digest inputs)

default_base[RW]
delimiter[RW]

The delimiter to use when joining Array values before creating a new digest hash. The default is “:”.

digest_type[RW]

Specify a different digest class. The default is Digest::SHA1. You could try Digest::SHA256 by doing this:

Object.digest_type = Digest::SHA256
secret[RW]
digest_type[W]

Modify the digest type for this instance. See #digest_type

input[R]

Public Class Methods

debug?() click to toggle source

Returns the current debug status (true or false)

# File lib/gibbler.rb, line 268
def debug?;  @debug != false; end
digest(input, digest_type=nil) click to toggle source

Sends input to Digest::SHA1.hexdigest. If another digest class has been specified, that class will be used instead. If ::secret is set, str will be prepended with the value.

If input is an Array, it will be flattened and joined.

See: #digest_type

# File lib/gibbler.rb, line 279
def self.digest(input, digest_type=nil)
  input = input.flatten.collect(&:to_s).join(delimiter) if ::Array === input
  return if input.empty?
  digest_type ||= @digest_type
  input = [Gibbler.secret, input].join(delimiter) unless Gibbler.secret.nil?
  dig = digest_type.hexdigest(input)
  dig = dig.to_i(16).to_s(Gibbler.default_base) if 16 != Gibbler.default_base
  dig
end
gibbler_debug(*args) click to toggle source
# File lib/gibbler.rb, line 289
def self.gibbler_debug(*args)
  return unless Gibbler.debug?
  p args
end
included(obj) click to toggle source

Raises an exception. The correct usage is to include a Gibbler::Object:

# File lib/gibbler.rb, line 299
def self.included(obj)
  raise "You probably want to include Gibbler::Complex or Gibbler::Object"
end
new(*input) click to toggle source

Creates a digest from the given input. See #digest.

If only one argument is given and it's a digest, this will simply create an instance of that digest. In other words, it won't calculate a new digest based on that input.

Calls superclass method
# File lib/gibbler.rb, line 231
def initialize *input
  if input.size == 1 && Gibbler::Digest::InstanceMethods === input.first
    super input.first
  else
    input.collect!(&:to_s)
    super Gibbler.digest(input) || ''
  end
end

Public Instance Methods

digest(*input) click to toggle source
# File lib/gibbler.rb, line 243
def digest *input
  replace Gibbler.digest(input, digest_type)
end
digest_type() click to toggle source
# File lib/gibbler.rb, line 239
def digest_type
  @digest_type || self.class.digest_type
end