module MicroservicesEngine

Constants

VERSION

Public Class Methods

build() click to toggle source

Returns the engine's current build

# File lib/microservices_engine.rb, line 45
def build
  @build ||= '0.0.0'
end
build=(b) click to toggle source

Setter method for the `build` portion of the engine, includes various validations

# File lib/microservices_engine.rb, line 9
def build=(b)
  @build = b if Rails.env.test? && b == '1.1.1'

  # ---------------- Semantic Versioning ---------------- #
  # 1. All version INCREASES are VALID                    #
  # 2. Version DECREASES are INVALID IF AND ONLY IF none  #
  #    of the more importantversion numbers increase.     #
  # 3. That is to say...                                  #
  #    a. A major decrease is never valid                 #
  #    b. A minor decrease is only valid when the major   #
  #       version increases.                              #
  #    c. A revision decrease is only valid when either   #
  #       the major or minor version increases.           #
  # ----------------------------------------------------- #

  major, minor, rev = b.split('.').map(&:to_i)
  cmajor, cminor, crev = build.split('.').map(&:to_i)

  # ---------------------- Examples ---------------------- #
  # 2.3.2 -> 1.3.2      1.2.3 -> 1.1.3      1.2.3 -> 0.2.3 #
  # 1.2.3 -> 1.2.2      1.2.3 -> 1.1.2      1.2.3 -> 0.2.3 #
  # ------------------------------------------------------ #
  invalid_changes = [
    cmajor > major,
    cminor > minor && !(major > cmajor),
    crev > rev && !(minor > cminor || major > cmajor)
  ]

  if invalid_changes.any?
    raise "Received version is older than existing. Now: #{build}. Given: #{b}"
  end

  @build = b
end
config()

Returns the engine's YML configuration, alias for `reload_config`

Alias for: reload_config
get(resource, path, params = {}) click to toggle source

Redirects an engine `get` call to the appropriate resource

# File lib/microservices_engine.rb, line 70
def get(resource, path, params = {})
  MicroservicesEngine::Connection.get(resource, path, params)
end
reload_config() click to toggle source

Reloads and returns the engine's current YML configuration

# File lib/microservices_engine.rb, line 50
def reload_config
  @config = YAML.load_file('config/mse_router_info.yml')
end
Also aliased as: config
valid_token?(token) click to toggle source

Takes in a token and verifies against the engine's YML configuration files Params:

token

The token to test validity of

# File lib/microservices_engine.rb, line 60
def valid_token?(token)
  return token == 'TEST_ENV_VALID_TOKEN' if Rails.env.test?

  valid_token = config['security_token']
  raise 'Security token is not set! Please set it as soon as possible!' if valid_token.blank?

  token == valid_token
end