Module: Storable::DefaultProcessors

Included in:
Storable
Defined in:
lib/storable.rb

Overview

These methods can be used by Storable objects as custom field processors.

e.g.

class A < Storable
  field :name => String, &hash_proc_processor
end

Instance Method Summary collapse

Instance Method Details

#gibbler_id_processorObject

If the object already has a value for @id use it, otherwise return the current digest.

This allows an object to have a preset ID.



542
543
544
545
546
# File 'lib/storable.rb', line 542

def gibbler_id_processor
  Proc.new do |val|
    @id || self.gibbler
  end
end

#hash_proc_processorObject

Replace a hash of Proc objects with a hash of



520
521
522
523
524
525
526
527
528
529
530
# File 'lib/storable.rb', line 520

def hash_proc_processor
  Proc.new do |procs|
    a = {}
    unless procs.nil?
      procs.each_pair { |n,v|
        a[n] = (Proc === v) ? v.source : v
      }
    end
    a
  end
end

#proc_processorObject



531
532
533
534
535
536
# File 'lib/storable.rb', line 531

def proc_processor
  Proc.new do |val|
    ret = (Proc === val) ? val.source : val
    ret
  end
end