Module: CaRuby::Database::Persistifier

Included in:
CaRuby::Database
Defined in:
lib/caruby/database/persistifier.rb

Overview

Database Persistable mediator. A module which includes Persistifier must implement the Reader#fetch_association method.

Instance Method Summary collapse

Instance Method Details

#clearObject

Clears the cache.



33
34
35
# File 'lib/caruby/database/persistifier.rb', line 33

def clear
  @cache.clear if @cache
end

#initializeObject

Adds query capability to this Database.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/caruby/database/persistifier.rb', line 14

def initialize
  super
  # the fetched object cache
  @cache = create_cache
  # the general fetched visitor
  @ftchd_vstr = Jinx::ReferenceVisitor.new() { |ref| ref.class.fetched_domain_attributes }
  # The persistifier visitor recurses to references before adding a lazy loader to the parent.
  # The fetched filter foregoes the visit to a previously fetched reference. The visitor
  # replaces fetched objects with matching cached objects where possible. It is unnecessary
  # to visit a previously persistified cached object.
  pst_flt = Proc.new { |ref| @cache[ref].nil? and not ref.fetched? }
  @pst_vstr = Jinx::ReferenceVisitor.new(:filter => pst_flt, :depth_first => true) do |ref|
    ref.class.fetched_domain_attributes
  end
  # the demand loader
  @lazy_loader = LazyLoader.new { |obj, pa| lazy_load(obj, pa) }
end