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. Also tracks which verticals are defined.

Instance Attribute Summary collapse

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.



52
53
54
55
# File 'lib/open_graph_reader/object/registry.rb', line 52

def initialize
  @namespaces = {}
  @verticals = Set.new
end

Instance Attribute Details

#verticalsObject (readonly)

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.

See Also:



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

def verticals
  @verticals
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.



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

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

.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.



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

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

.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)


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

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

.verticalsSet<String>

All known verticals

Returns:

  • (Set<String>)


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

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

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:

See Also:



58
59
60
61
# File 'lib/open_graph_reader/object/registry.rb', line 58

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