Module: Stenotype::Configuration

Extended by:
Directive
Defined in:
lib/stenotype/configuration.rb

Overview

A module containing freshly-event gem configuration

Examples:

Configuring the library

Stenotype.configure do |config|
  config.enabled = true
  config.targets = [Target1.new, Target2.new]
  config.uuid_generator = SecureRandom

  config.google_cloud do |gc|
    gc.credentials = "abc"
    gc.project_id  = "project"
    gc.topic       = "42"
    gc.async       = true
  end

  config.rails do |rc|
    rc.enable_action_controller_ext = true
    rc.enable_active_job_ext        =  false
  end
end

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#auto_adapter_initializationtrue, false

Returns enables/disables lazy initialization of adapters' clients.

Returns:

  • (true, false)

    enables/disables lazy initialization of adapters' clients



# File 'lib/stenotype/configuration.rb', line 40

#dispatcher#publish

Returns as object responding to method [#publish].

Returns:

  • (#publish)

    as object responding to method [#publish]



# File 'lib/stenotype/configuration.rb', line 46

#enabledtrue, false

Returns a flag indicating whether event emission is enabled.

Returns:

  • (true, false)

    a flag indicating whether event emission is enabled



# File 'lib/stenotype/configuration.rb', line 37

#google_cloudNestedConfiguration

Returns google cloud configuration.

Returns:

  • (NestedConfiguration)

    google cloud configuration.



# File 'lib/stenotype/configuration.rb', line 52

#google_cloud.asynctrue, false

Returns GC publish mode, either async if true, sync if false.

Returns:

  • (true, false)

    GC publish mode, either async if true, sync if false



# File 'lib/stenotype/configuration.rb', line 64

#google_cloud.credentialsString

Returns a string with GC API credential. Refer to GC PubSub documentation.

Returns:

  • (String)

    a string with GC API credential. Refer to GC PubSub documentation



# File 'lib/stenotype/configuration.rb', line 55

#google_cloud.project_idString

Returns a name of the project in GC PubSub.

Returns:

  • (String)

    a name of the project in GC PubSub



# File 'lib/stenotype/configuration.rb', line 58

#google_cloud.topicString

Returns a name of the topic in GC PubSub.

Returns:

  • (String)

    a name of the topic in GC PubSub



# File 'lib/stenotype/configuration.rb', line 61

#graceful_error_handlingtrue, false

Returns a flag for suppressing error raised withing the gem.

Returns:

  • (true, false)

    a flag for suppressing error raised withing the gem



# File 'lib/stenotype/configuration.rb', line 31

#logger=(value) ⇒ Logger

Returns a logger with default severity methods to output gem level messages.

Returns:

  • (Logger)

    a logger with default severity methods to output gem level messages



# File 'lib/stenotype/configuration.rb', line 34

#railsNestedConfiguration

Returns Rails configuration.

Returns:

  • (NestedConfiguration)

    Rails configuration.



# File 'lib/stenotype/configuration.rb', line 67

#rails.enable_action_controller_exttrue, false

Returns A flag of whether ActionController ext is enabled.

Returns:

  • (true, false)

    A flag of whether ActionController ext is enabled



# File 'lib/stenotype/configuration.rb', line 70

#rails.enable_active_job_exttrue, false

Returns A flag of whether ActiveJob ext is enabled.

Returns:

  • (true, false)

    A flag of whether ActiveJob ext is enabled



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/stenotype/configuration.rb', line 76

configuration_options do
  option :graceful_error_handling, default: true
  option :enabled, default: true
  option :targets, default: []
  option :dispatcher, default: Stenotype::Dispatcher
  option :uuid_generator, default: SecureRandom
  option :logger

  nested :google_cloud do
    option :credentials, default: nil
    option :project_id, default: nil
    option :topic, default: nil
    option :async, default: true
  end

  nested :rails do
    option :enable_action_controller_ext, default: true
    option :enable_active_job_ext, default: true
    option :auto_adapter_initialization, default: false
  end
end

#targets=(value) ⇒ Array<#publish>

Returns a list of targets responding to method [#publish].

Returns:

  • (Array<#publish>)

    a list of targets responding to method [#publish]



# File 'lib/stenotype/configuration.rb', line 43

#uuid_generator#uuid

Returns an object responding to method [#uuid].

Returns:

  • (#uuid)

    an object responding to method [#uuid]



# File 'lib/stenotype/configuration.rb', line 49

Class Method Details

.logger{Logger, CustomLogger}

Returns a logger object. Logger.new(STDOUT) by default if another is not set during configuration.

Examples:

With default logger

Stenotype.configure do |config|
  # config.logger = nil # logger not set manually
end
Stenotype.config.logger #=> `Logger.new(STDOUT)` instance

With custom logger

Stenotype.configure do |config|
  config.logger = custom_logger_instance
end
Stenotype.config.logger #=> custom_logger_instance

Returns:

  • ({Logger, CustomLogger})

    a logger object. Logger.new(STDOUT) by default if another is not set during configuration



116
117
118
119
120
# File 'lib/stenotype/configuration.rb', line 116

def logger
  return config.logger if config.logger

  config.logger || Logger.new(STDOUT)
end

.targetsArray<#publish>

TODO:

THIS NEVER GETS CALLED, needs a fix

Returns An array of targets implementing method [#publish].

Examples:

When at least one target is present

Stenotype.configure do |config|
  config.targets = [Target1.new, Target2.new]
end
Stenotype.config.targets #=> [target_obj1, target_obj2]

When no targets have been configured

Stenotype.configure { |config| config.targets = [] }
Stenotype.config.targets #=> Stenotype::NoTargetsSpecifiedError

Returns:

  • (Array<#publish>)

    An array of targets implementing method [#publish]

Raises:



138
139
140
141
142
143
144
# File 'lib/stenotype/configuration.rb', line 138

def targets
  return config.targets unless config.targets.empty?

  raise Stenotype::NoTargetsSpecifiedError,
        "Please configure a target(s) for events to be sent to. "\
        "See #{Stenotype::Configuration} for reference."
end