Module: ActiveSpy

Defined in:
lib/active_spy.rb,
lib/active_spy/base.rb,
lib/active_spy/spy/spy.rb,
lib/active_spy/rails/spy.rb,
lib/active_spy/rails/base.rb,
lib/active_spy/rails/engine.rb,
lib/active_spy/spy/spy_list.rb,
lib/active_spy/configuration.rb,
lib/active_spy/rails/listener.rb,
lib/active_spy/rails/hook_list.rb,
lib/active_spy/rails/validation.rb,
lib/rails/generators/active_spy/install/install_generator.rb

Overview

Base module for the gem

Defined Under Namespace

Modules: Generators, Rails, Spy Classes: Base, Configuration, Engine, SpyList

Class Method Summary collapse

Class Method Details

.configureObject

Class method to set the service’s name, host and port.



24
25
26
27
28
# File 'lib/active_spy.rb', line 24

def self.configure
  Configuration.instance_eval do
    yield(self)
  end
end

.register_serviceObject

Class method to register the service in an event-runner instance.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/active_spy.rb', line 33

def self.register_service
  host        = ActiveSpy::Configuration.event_host
  port        = ActiveSpy::Configuration.event_port
  verify_ssl  = ActiveSpy::Configuration.event_verify_ssl
  @base_url   = "#{host}:#{port}/services"

  return if self.service_registered?
  service = { service: ActiveSpy::Configuration.settings }.to_json

  params = { headers: { content_type: :json }, method: :post, url: @base_url, payload: service }
  params[:verify_ssl] = verify_ssl if verify_ssl

  RestClient::Request.execute(params)
end

.service_registered?Boolean

Check if the service was already registetered in the configured event runner instance.

Returns:

  • (Boolean)


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/active_spy.rb', line 52

def self.service_registered?
  name        = ActiveSpy::Configuration.name
  verify_ssl  = ActiveSpy::Configuration.event_verify_ssl
  url         = "#{@base_url}/#{name.downcase.gsub(' ', '-').strip}"

  begin
    if verify_ssl
      RestClient::Request.execute(method: :get, url: url, verify_ssl: verify_ssl)
    else
      RestClient.get url
    end
  rescue RestClient::ResourceNotFound
    return false
  else
    return true
  end
end