Module: Harbinger

Defined in:
lib/harbinger.rb,
lib/harbinger/engine.rb,
lib/harbinger/message.rb,
lib/harbinger/version.rb,
lib/harbinger/channels.rb,
lib/harbinger/reporters.rb,
lib/harbinger/exceptions.rb,
lib/harbinger/configuration.rb,
app/helpers/harbinger/application_helper.rb,
lib/harbinger/reporters/request_reporter.rb,
app/controllers/harbinger/messages_controller.rb,
app/models/harbinger/database_channel_message.rb,
app/controllers/harbinger/application_controller.rb,
lib/generators/harbinger/install/install_generator.rb,
app/models/harbinger/database_channel_message_element.rb

Defined Under Namespace

Modules: ApplicationHelper, Channels, Reporters Classes: ApplicationController, Configuration, ConfigurationError, DatabaseChannelMessage, DatabaseChannelMessageElement, Engine, InstallGenerator, Message, MessagesController

Constant Summary collapse

VERSION =
"0.2.3"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject

See Also:



13
14
15
# File 'lib/harbinger.rb', line 13

def configuration
  @configuration ||= Configuration.new
end

Class Method Details

.build_message(options = {}) ⇒ Object

Responsible for building a :message from the various :reporters.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :message (Message)

    The message you want to amend. If none is provided, then one is created.

  • :reporters (Object, Array<Object>)

    One or more Objects that Harbinger will visit and extract message elements from.

See Also:



53
54
55
56
57
58
59
# File 'lib/harbinger.rb', line 53

def build_message(options = {})
  reporters = Array(options.fetch(:reporters)).flatten.compact
  message = options.fetch(:message) { default_message }

  reporters.each { |context| reporter_for(context).accept(message) }
  message
end

.call(options) ⇒ Object

Responsible for building a :message from the various :reporters and then delivering the :message to the appropriate :channels.

Parameters:

  • options (Hash)

Options Hash (options):

  • :message (Message)

    The message you want to amend. If none is provided, then one is created.

  • :reporters (Object, Array<Object>)

    One or more Objects that Harbinger will visit and extract message elements from.

  • :channels (Symbol, Array<Symbol>)

    One or more channels that Harbinger will deliver the :message to

See Also:



39
40
41
42
# File 'lib/harbinger.rb', line 39

def call(options)
  message = build_message(options)
  deliver_message(message, options)
end

.configure {|configuration| ... } ⇒ Object



22
23
24
# File 'lib/harbinger.rb', line 22

def configure
  yield(configuration)
end

.database_storageObject



106
107
108
# File 'lib/harbinger.rb', line 106

def database_storage
  configuration.database_storage
end

.default_channelsObject



96
97
98
# File 'lib/harbinger.rb', line 96

def default_channels
  configuration.default_channels
end

.deliver_message(message, options = {}) ⇒ Object

Responsible for delivering a :message to the appropriate :channels.

Parameters:

  • message (Message)

    The message you want to amend. If none is provided, then one is created.

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :channels (Symbol, Array<Symbol>)

    One or more channels that Harbinger will deliver the :message to

See Also:



70
71
72
73
74
75
76
77
# File 'lib/harbinger.rb', line 70

def deliver_message(message, options = {})
  channels = options.fetch(:channels) { default_channels }
  Array(channels).flatten.compact.each do |channel_name|
    channel = channel_for(channel_name)
    channel.deliver(message)
  end
  true
end

.loggerObject



101
102
103
# File 'lib/harbinger.rb', line 101

def logger
  configuration.logger
end

.table_name_prefixObject

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.

As per an isolated_namespace Rails engine. But the isolated namespace creates issues.



114
115
116
# File 'lib/harbinger.rb', line 114

def table_name_prefix
  'harbinger_'
end

.use_relative_model_naming?Boolean

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.

Because I am not using isolate_namespace for Orcid::Engine I need this for the application router to find the appropriate routes.

Returns:

  • (Boolean)


121
122
123
# File 'lib/harbinger.rb', line 121

def use_relative_model_naming?
  true
end