Module: EntityCache::Store::Internal::Build

Defined in:
lib/entity_cache/store/internal/build.rb,
lib/entity_cache/store/internal/build/defaults.rb

Defined Under Namespace

Modules: Defaults

Constant Summary collapse

ScopeError =
Class.new(RuntimeError)

Class Method Summary collapse

Class Method Details

.call(subject, scope: nil) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/entity_cache/store/internal/build.rb', line 5

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

  cls = scope_class(scope)

  cls.build(subject)
end

.default_scope_classObject



13
14
15
# File 'lib/entity_cache/store/internal/build.rb', line 13

def self.default_scope_class
  scope_class(Defaults.scope)
end

.loggerObject



40
41
42
# File 'lib/entity_cache/store/internal/build.rb', line 40

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

.scope_class(scope) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/entity_cache/store/internal/build.rb', line 17

def self.scope_class(scope)
  scopes.fetch(scope) do
    *scopes, final_scope = self.scopes.keys

    scope_list = <<~TEXT
    #{scopes.map(&:inspect) * ', '} or #{final_scope.inspect}
    TEXT

    error_message = %{Scope #{scope.inspect} is unknown. It must be one of: #{scope_list}}

    logger.error(error_message)
    raise ScopeError, error_message
  end
end

.scopesObject



32
33
34
35
36
37
38
# File 'lib/entity_cache/store/internal/build.rb', line 32

def self.scopes
  @scopes ||= {
    :exclusive => Scope::Exclusive,
    :global => Scope::Global,
    :thread => Scope::Thread
  }
end