class Gibbler
Attributes
Set to true for debug output (including all digest inputs)
The delimiter to use when joining Array values before creating a new digest hash. The default is “:”.
Specify a different digest class. The default is Digest::SHA1
.
You could try Digest::SHA256
by doing this:
Object.digest_type = Digest::SHA256
Modify the digest type for this instance. See #digest_type
Public Class Methods
Returns the current debug status (true or false)
# File lib/gibbler.rb, line 268 def debug?; @debug != false; end
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
# File lib/gibbler.rb, line 289 def self.gibbler_debug(*args) return unless Gibbler.debug? p args end
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
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.
# 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
# File lib/gibbler.rb, line 243 def digest *input replace Gibbler.digest(input, digest_type) end
# File lib/gibbler.rb, line 239 def digest_type @digest_type || self.class.digest_type end