Class: OpenGraphReader::Object::Registry Private

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Singleton
Defined in:
lib/open_graph_reader/object/registry.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Global registry of namespaces and their representing classes.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRegistry

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Registry.



43
44
45
# File 'lib/open_graph_reader/object/registry.rb', line 43

def initialize
  @namespaces = {}
end

Class Method Details

.[](namespace) ⇒ Class

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Fetch the class associated with the given namespace

Parameters:

  • namespace (String)

    The namespace in colon separated form, for example og:image.

Returns:

  • (Class)

    The matching class.

Raises:

  • (ArgumentError)

    If the given namespace wasn’t registered.



36
# File 'lib/open_graph_reader/object/registry.rb', line 36

def_delegators :instance, :register, :registered?, :[]

.register(namespace, klass) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Register a new namespace in the registry.

Parameters:

  • namespace (String)

    The namespace in colon separated form, for example og:image.

  • klass (Class)

    The class to register. It should include OpenGraphReader::Object.



36
# File 'lib/open_graph_reader/object/registry.rb', line 36

def_delegators :instance, :register, :registered?, :[]

.registered?(namespace) ⇒ Bool

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Check whether a namespace is registered.

Parameters:

  • namespace (String)

    The namespace in colon separated form, for example og:image.

Returns:

  • (Bool)


36
# File 'lib/open_graph_reader/object/registry.rb', line 36

def_delegators :instance, :register, :registered?, :[]

Instance Method Details

#[](namespace) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Raises:

  • (ArgumentError)

See Also:



48
49
50
51
# File 'lib/open_graph_reader/object/registry.rb', line 48

def [] namespace
  raise ArgumentError, "#{namespace} is not a registered namespace" unless registered? namespace
  @namespaces[namespace]
end