Module: Chook

Defined in:
lib/chook/subject.rb,
lib/chook/event.rb,
lib/chook/procs.rb,
lib/chook/server.rb,
lib/chook/version.rb,
lib/chook/server/log.rb,
lib/chook/server/auth.rb,
lib/chook/test_events.rb,
lib/chook/configuration.rb,
lib/chook/server/routes.rb,
lib/chook/test_subjects.rb,
lib/chook/handled_events.rb,
lib/chook/event/test_event.rb,
lib/chook/handled_subjects.rb,
lib/chook/subject/samplers.rb,
lib/chook/server/routes/log.rb,
lib/chook/server/routes/home.rb,
lib/chook/subject/validators.rb,
lib/chook/event/handled_event.rb,
lib/chook/subject/randomizers.rb,
lib/chook/subject/test_subject.rb,
lib/chook/server/routes/handlers.rb,
lib/chook/subject/handled_subject.rb,
lib/chook/event/handled_event_logger.rb,
lib/chook/server/routes/login_logout.rb,
lib/chook/event/handled_event/handlers.rb,
lib/chook/server/routes/handle_by_name.rb,
lib/chook/server/routes/handle_webhook_event.rb

Overview

Licensed under the Apache License, Version 2.0 (the “Apache License”)

with the following modification; you may not use this file except in
compliance with the Apache License and the following modification to it:
Section 6. Trademarks. is deleted and replaced with:

6. Trademarks. This License does not grant permission to use the trade
   names, trademarks, service marks, or product names of the Licensor
   and its affiliates, except as required to comply with Section 4(c) of
   the License and to reproduce the content of the NOTICE file.

You may obtain a copy of the Apache License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the Apache License with the above modification is
distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the Apache License for the specific
language governing permissions and limitations under the Apache License.

Defined Under Namespace

Modules: HandledEvents, HandledSubjects, Procs, Randomizers, Samplers, TestSubjects, Validators Classes: Configuration, Event, HandledEvent, HandledEventLogger, HandledSubject, Server, Subject, TestEvent, TestEvents, TestSubject

Constant Summary collapse

VERSION =

The version of the Chook framework

'1.1.5'.freeze

Class Method Summary collapse

Class Method Details

.configObject

The single instance of Configuration



213
214
215
# File 'lib/chook/configuration.rb', line 213

def self.config
  Chook::Configuration.instance
end

.event_handler(&block) {|The| ... } ⇒ Proc

This method is used by the Ruby ‘internal’ event-handler files.

those handlers are defined by passing a block to this method, like so:

Chook.event_handler do |event|
  # so something with the event
end

Loading them will call this method and pass in a block with one parameter: a Chook::HandledEvent subclass instance.

The block is then converted to a #handle method in an anonymous object. The object is stored for use by the event identified by the filename.

By storing it as a method in an object, the handlers themselves can use #break or #return to exit (or even #next)

NOTE: the files should be read with ‘load’ not ‘require’, so that they can be re-loaded as needed

Parameters:

  • block (Block)

    the block to be used as an event handler

Yield Parameters:

  • The (JSS::WebHooks::Event subclass)

    event to be handled

Returns:

  • (Proc)

    the block converted to a Proc



55
56
57
58
59
60
61
62
63
# File 'lib/chook/event/handled_event/handlers.rb', line 55

def self.event_handler(&block)
  obj = Object.new
  obj.define_singleton_method(:handle, &block)
  # Loading the file created the object by calling this method
  # but to access it after loading the file, we need to
  # store it in here:
  HandledEvent::Handlers.loaded_handler = obj
  Chook.logger.debug "Code block for 'Chook.event_handler' loaded into \#handle method of runner-object #{obj.object_id}"
end

.log_exception(exception) ⇒ Object

log an exception - multiple log lines the first being the error message the rest being indented backtrace



210
211
212
213
# File 'lib/chook/server/log.rb', line 210

def self.log_exception(exception)
  logger.error exception.to_s
  exception.backtrace.each { |l| logger.error "..#{l}" }
end

.loggerObject

access from everywhere as Chook.logger



204
205
206
# File 'lib/chook/server/log.rb', line 204

def self.logger
  Server::Log.logger
end

.sample_jsonsObject



40
41
42
# File 'lib/chook/event/handled_event.rb', line 40

def self.sample_jsons
  @sample_jsons
end