Class: Gibbler
- Includes:
- Digest::InstanceMethods
- Defined in:
- lib/gibbler.rb,
lib/gibbler.rb,
lib/gibbler.rb,
lib/gibbler.rb,
lib/gibbler/aliases.rb,
lib/gibbler/history.rb
Overview
Gibbler
“Hola, Tanneritos”
Defined Under Namespace
Modules: Array, Complex, DateTime, File, Hash, History, Nil, Object, Range, String, Time, VERSION Classes: BadDigest, Digest, Error, NoHistory, NoRevert
Class Attribute Summary collapse
-
.debug ⇒ Object
Set to true for debug output (including all digest inputs).
-
.default_base ⇒ Object
Returns the value of attribute default_base.
-
.delimiter ⇒ Object
The delimiter to use when joining Array values before creating a new digest hash.
-
.digest_type ⇒ Object
Specify a different digest class.
-
.secret ⇒ Object
Returns the value of attribute secret.
Instance Attribute Summary collapse
- #digest_type ⇒ Object
-
#input ⇒ Object
readonly
Returns the value of attribute input.
Class Method Summary collapse
-
.debug? ⇒ Boolean
Returns the current debug status (true or false).
-
.digest(input, digest_type = nil) ⇒ Object
Sends
input
to Digest::SHA1.hexdigest. - .gibbler_debug(*args) ⇒ Object
-
.included(obj) ⇒ Object
Raises an exception.
Instance Method Summary collapse
- #digest(*input) ⇒ Object
-
#initialize(*input) ⇒ Gibbler
constructor
Creates a digest from the given
input
.
Methods included from Digest::InstanceMethods
#==, #===, #base, #base36, #short, #shorten, #shorter, #tiny, #to_i, #to_s
Methods inherited from String
Methods included from History
#commit, #find_long, #gibbler_commit, #gibbler_find_long, #gibbler_history, #gibbler_history?, #gibbler_object, #gibbler_revert!, #gibbler_stamp, #gibbler_valid?, #history, #history?, mutex, #object, #revert!, #stamp, #valid?
Methods included from String
Methods included from Object
#__gibbler, #digest_cache, #freeze, #gibbled?, #gibbler, #gibbler_debug, #gibbler_fields, gibbler_fields
Constructor Details
#initialize(*input) ⇒ Gibbler
Creates a digest from the given input
. See Gibbler.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.
231 232 233 234 235 236 237 238 |
# 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 |
Class Attribute Details
.debug ⇒ Object
Set to true for debug output (including all digest inputs)
266 267 268 |
# File 'lib/gibbler.rb', line 266 def debug @debug end |
.default_base ⇒ Object
Returns the value of attribute default_base.
33 34 35 |
# File 'lib/gibbler.rb', line 33 def default_base @default_base end |
.delimiter ⇒ Object
The delimiter to use when joining Array values before creating a new digest hash. The default is “:”.
264 265 266 |
# File 'lib/gibbler.rb', line 264 def delimiter @delimiter end |
.digest_type ⇒ Object
261 262 263 |
# File 'lib/gibbler.rb', line 261 def digest_type @digest_type end |
.secret ⇒ Object
Returns the value of attribute secret.
33 34 35 |
# File 'lib/gibbler.rb', line 33 def secret @secret end |
Instance Attribute Details
#digest_type ⇒ Object
239 240 241 |
# File 'lib/gibbler.rb', line 239 def digest_type @digest_type || self.class.digest_type end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
225 226 227 |
# File 'lib/gibbler.rb', line 225 def input @input end |
Class Method Details
.debug? ⇒ Boolean
Returns the current debug status (true or false)
268 |
# File 'lib/gibbler.rb', line 268 def debug?; @debug != false; end |
.digest(input, digest_type = nil) ⇒ Object
Sends input
to Digest::SHA1.hexdigest. If another digest class has been specified, that class will be used instead. If Gibbler.secret is set, str
will be prepended with the value.
If input
is an Array, it will be flattened and joined.
See: digest_type
279 280 281 282 283 284 285 286 287 |
# 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) ⇒ Object
289 290 291 292 |
# File 'lib/gibbler.rb', line 289 def self.gibbler_debug(*args) return unless Gibbler.debug? p args end |
.included(obj) ⇒ Object
Raises an exception. The correct usage is to include a Gibbler::Object:
-
Gibbler::Complex
-
Gibbler::String
-
Gibbler::Object
-
etc …
299 300 301 |
# File 'lib/gibbler.rb', line 299 def self.included(obj) raise "You probably want to include Gibbler::Complex or Gibbler::Object" end |