Class: MemoryModel::Collection::LoaderDelegate

Inherits:
BasicObject
Includes:
Enumerable
Defined in:
lib/memory_model/collection/loader_delegate.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(records) ⇒ LoaderDelegate

Returns a new instance of LoaderDelegate.



27
28
29
# File 'lib/memory_model/collection/loader_delegate.rb', line 27

def initialize(records)
  @records = records
end

Class Method Details

.cacheObject



18
19
20
# File 'lib/memory_model/collection/loader_delegate.rb', line 18

def cache
  @cache ||= ::ActiveSupport::Cache.lookup_store :memory_store
end

.delegate_and_load(*methods) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/memory_model/collection/loader_delegate.rb', line 10

def delegate_and_load(*methods)
  methods.each do |method|
    define_method method do |*args, &block|
      @records.send(method, *args, &block).try(:load)
    end
  end
end

Instance Method Details

#classObject



45
46
47
# File 'lib/memory_model/collection/loader_delegate.rb', line 45

def class
  LoaderDelegate
end

#each(&block) ⇒ Object



31
32
33
# File 'lib/memory_model/collection/loader_delegate.rb', line 31

def each(&block)
  loaded_records.each(&block)
end

#kind_of?(klass) ⇒ Boolean Also known as: is_a?

Returns:

  • (Boolean)


35
36
37
# File 'lib/memory_model/collection/loader_delegate.rb', line 35

def kind_of?(klass)
  klass == self.class
end

#methodsObject



41
42
43
# File 'lib/memory_model/collection/loader_delegate.rb', line 41

def methods
  LoaderDelegate.ancestors.map(&:instance_methods).flatten.uniq
end