Module: EntityCache::Storage::Temporary::Factory

Defined in:
lib/entity_cache/storage/temporary/factory.rb

Class Method Summary collapse

Class Method Details

.call(subject, scope: nil) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/entity_cache/storage/temporary/factory.rb', line 5

def self.call(subject, scope: nil)
  scope ||= Scope::Defaults::Name.get

  scope_class = self.scope_class scope

  scope_class.build subject
end

.loggerObject



36
37
38
# File 'lib/entity_cache/storage/temporary/factory.rb', line 36

def self.logger
  @logger ||= Log.get(self)
end

.scope_class(scope_name) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/entity_cache/storage/temporary/factory.rb', line 13

def self.scope_class(scope_name)
  scope_class = scopes[scope_name]

  if scope_class.nil?
    *scopes, final_scope = self.scopes.keys
    scopes = "#{scopes * ', '} or #{scope_name}"

    error_message = %{Scope "#{scope_name}" is unknown. It must be one of: #{scopes}}

    logger.error error_message
    raise Scope::Error, error_message
  end

  scope_class
end

.scopesObject



29
30
31
32
33
34
# File 'lib/entity_cache/storage/temporary/factory.rb', line 29

def self.scopes
  @scopes ||= {
    :exclusive => Scope::Exclusive,
    :shared => Scope::Shared
  }
end