Module: ActiveCMIS::Internal::Caching::ClassMethods

Defined in:
lib/active_cmis/internal/caching.rb

Overview

A module for internal use only.

Instance Method Summary collapse

Instance Method Details

#cache(*names) ⇒ void

This method returns an undefined value.

Creates a proxy method for the given method names that caches the result.

Parameters are passed and ignored, cached values will be returned regardless of the parameters.

Parameters:

  • Names (Symbol, <Symbol>)

    of methods that will be cached



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/active_cmis/internal/caching.rb', line 16

def cache(*names)
  (@cached_methods ||= []).concat(names).uniq!
  names.each do |name|
    alias_method("#{name}__uncached", name)
    class_eval "      if private_method_defined? :\"\#{name}\"\n        private_method = true\n      end\n      def \#{name}(*a, &b)\n        if defined? @\#{name}\n          @\#{name}\n        else\n          @\#{name} = \#{name}__uncached(*a, &b)\n        end\n      end\n      if private_method\n        private :\"\#{name}__uncached\"\n        private :\"\#{name}\"\n      end\n    RUBY\n  end\n  reloadable\nend\n", __FILE__, __LINE__+1

#cached_reader(*names) ⇒ void

This method returns an undefined value.

Creates methods to retrieve attributes with the given names.

If the given attribute does not yet exist the method #load_from_data will be called

Parameters:

  • Names (Symbol, <Symbol>)

    of desired attributes



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/active_cmis/internal/caching.rb', line 46

def cached_reader(*names)
  (@cached_methods ||= []).concat(names).uniq!
  names.each do |name|
    define_method "#{name}" do
      if instance_variable_defined? "@#{name}"
        instance_variable_get("@#{name}")
      else
        load_from_data # FIXME: make flexible?
        instance_variable_get("@#{name}")
      end
    end
  end
  reloadable
end