Class Webgen::Blackboard
In: lib/webgen/blackboard.rb
Parent: Object
Error RenderError CommandNotFoundError LoadError NodeCreationError ::Rake::TaskLib WebgenTask Helpers Configuration Node Context\n[lib/webgen/context.rb\nlib/webgen/context/nodes.rb\nlib/webgen/context/render.rb\nlib/webgen/context/tags.rb] Tree FileSystem Sitemap Copy Feed Virtual Sitemap Directory Page Fragment Template Metainfo Memory Coderay Sitemap IncludeFile BreadcrumbTrail Langbar TikZ Menu Tags Fragments Resource Website Tidy Head Kramdown Less Xmllint Blocks Comparable Language Path StandardError CmdParse::CommandParser CommandParser CmdParse::Command RunCommand WebguiCommand CreateCommand ApplyCommand WebsiteAccess Main Loggable OutputPathHelpers ExecuteCommand Link Date Relocatable Metainfo ::Kramdown::Converter::Html KramdownHtmlConverter Cache Blackboard WebsiteManager Logger Page ProxyNode Utils Scss RDoc Sass Erb RDiscount Erubis Haml Maruku Builder RedCloth AccessHash TarArchive Stacked FileSystem lib/webgen/cache.rb lib/webgen/error.rb lib/webgen/languages.rb lib/webgen/context/render.rb lib/webgen/website.rb lib/webgen/blackboard.rb lib/webgen/tree.rb lib/webgen/websitemanager.rb lib/webgen/logger.rb lib/webgen/configuration.rb lib/webgen/path.rb lib/webgen/webgentask.rb lib/webgen/page.rb lib/webgen/node.rb ClassMethods WebsiteAccess lib/webgen/cli/run_command.rb lib/webgen/cli/utils.rb lib/webgen/cli/apply_command.rb lib/webgen/cli/webgui_command.rb lib/webgen/cli.rb lib/webgen/cli/create_command.rb Color CLI LanguageManager lib/webgen/output/filesystem.rb Output lib/webgen/common/sitemap.rb Common lib/webgen/sourcehandler/memory.rb lib/webgen/sourcehandler/metainfo.rb lib/webgen/sourcehandler/copy.rb lib/webgen/sourcehandler/directory.rb lib/webgen/sourcehandler.rb lib/webgen/sourcehandler/page.rb lib/webgen/sourcehandler/template.rb lib/webgen/sourcehandler/fragment.rb lib/webgen/sourcehandler/sitemap.rb lib/webgen/sourcehandler/virtual.rb lib/webgen/sourcehandler/feed.rb OutputPathHelpers Base SourceHandler lib/webgen/tag/coderay.rb lib/webgen/tag/relocatable.rb lib/webgen/tag/menu.rb lib/webgen/tag/langbar.rb lib/webgen/tag/executecommand.rb lib/webgen/tag/breadcrumbtrail.rb lib/webgen/tag/metainfo.rb lib/webgen/tag/includefile.rb lib/webgen/tag/link.rb lib/webgen/tag/date.rb lib/webgen/tag/tikz.rb lib/webgen/tag/sitemap.rb Base Tag lib/webgen/contentprocessor/less.rb lib/webgen/contentprocessor/scss.rb lib/webgen/contentprocessor/blocks.rb lib/webgen/contentprocessor/rdoc.rb lib/webgen/contentprocessor/sass.rb lib/webgen/contentprocessor/erb.rb lib/webgen/contentprocessor/rdiscount.rb lib/webgen/contentprocessor/tags.rb lib/webgen/contentprocessor/erubis.rb lib/webgen/contentprocessor/kramdown/html.rb lib/webgen/contentprocessor/haml.rb lib/webgen/contentprocessor/maruku.rb lib/webgen/contentprocessor/xmllint.rb lib/webgen/contentprocessor/kramdown.rb lib/webgen/contentprocessor/head.rb lib/webgen/contentprocessor/builder.rb lib/webgen/contentprocessor/tidy.rb lib/webgen/contentprocessor/redcloth.rb lib/webgen/contentprocessor/fragments.rb lib/webgen/contentprocessor.rb ContentProcessor lib/webgen/source/tararchive.rb lib/webgen/source/stacked.rb lib/webgen/source/resource.rb lib/webgen/source/filesystem.rb Source Loggable Webgen dot/m_82_0.png

A blackboard object provides two features for inter-object communication:

  • services: An object can add a service to the blackboard which can be called by any other object by just specifing the service name. Therefore it is easy to change the underlying implementation of the service and there are no hard dependencies on specific class or method names.
  • listeners: Objects may register themselves for specific messsage names and get notified when such a message gets dispatched.

For a list of all available services and messages have a look at the main Webgen documentation page.

Methods

Public Class methods

Create a new Blackboard object.

[Source]

    # File lib/webgen/blackboard.rb, line 20
20:     def initialize
21:       @listener = {}
22:       @services = {}
23:     end

Public Instance methods

Add the callable_object or the given block as listener for the messages msg_names (one message name or an array of message names).

[Source]

    # File lib/webgen/blackboard.rb, line 27
27:     def add_listener(msg_names = nil, callable_object = nil, &block)
28:       callable_object = callable_object || block
29:       if !callable_object.nil?
30:         raise ArgumentError, "The listener needs to respond to 'call'" unless callable_object.respond_to?(:call)
31:         [msg_names].flatten.compact.each {|name| (@listener[name] ||= []) << callable_object}
32:       else
33:         raise ArgumentError, "You have to provide a callback object or a block"
34:       end
35:     end

Add a service named service_name provided by the callable_object or a block to the blackboard.

[Source]

    # File lib/webgen/blackboard.rb, line 52
52:     def add_service(service_name, callable_object = nil, &block)
53:       callable_object = callable_object || block
54:       if @services.has_key?(service_name)
55:         raise "The service name '#{service_name}' is already taken"
56:       else
57:         raise ArgumentError, "An object providing a service needs to respond to 'call'" unless callable_object.respond_to?(:call)
58:         @services[service_name] = callable_object
59:       end
60:     end

Remove the given object from the dispatcher queues of the message names specified in msg_names.

[Source]

    # File lib/webgen/blackboard.rb, line 39
39:     def del_listener(msg_names, callable_object)
40:       [msg_names].flatten.each {|name| @listener[name].delete(callable_object) if @listener[name]}
41:     end

Delete the service service_name.

[Source]

    # File lib/webgen/blackboard.rb, line 63
63:     def del_service(service_name)
64:       @services.delete(service_name)
65:     end

Dispatch the message msg_name to all listeners for this message, passing the given arguments.

[Source]

    # File lib/webgen/blackboard.rb, line 45
45:     def dispatch_msg(msg_name, *args)
46:       return unless @listener[msg_name]
47:       @listener[msg_name].each {|obj| obj.call(*args)}
48:     end

Invoke the service called service_name with the given arguments.

[Source]

    # File lib/webgen/blackboard.rb, line 68
68:     def invoke(service_name, *args, &block)
69:       if @services.has_key?(service_name)
70:         @services[service_name].call(*args, &block)
71:       else
72:         raise ArgumentError, "No such service named '#{service_name}' available"
73:       end
74:     end

[Validate]