Class: GQL::Registry

Inherits:
Object
  • Object
show all
Extended by:
ActiveSupport::PerThreadRegistry
Defined in:
lib/gql/registry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRegistry

Returns a new instance of Registry.



10
11
12
# File 'lib/gql/registry.rb', line 10

def initialize
  reset
end

Instance Attribute Details

#cacheObject (readonly)

Returns the value of attribute cache.



8
9
10
# File 'lib/gql/registry.rb', line 8

def cache
  @cache
end

Instance Method Details

#fetch(key, baseclass = Field) ⇒ Object Also known as: []



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/gql/registry.rb', line 18

def fetch(key, baseclass = Field)
  cache[key] || begin
    const, name =
      if key.instance_of? ::Class
        [key, key.name]
      else
        [key.constantize, key]
      end

    raise Errors::InvalidClass.new(const, baseclass) unless const <= baseclass

    cache.update name => const, const => const

    cache[key]
  end
end

#resetObject



14
15
16
# File 'lib/gql/registry.rb', line 14

def reset
  @cache = {}
end