Module: MicroservicesEngine
- Defined in:
- lib/microservices_engine.rb,
lib/microservices_engine/engine.rb,
lib/microservices_engine/version.rb,
app/models/microservices_engine/connection.rb,
app/controllers/microservices_engine/v1/data_controller.rb,
app/controllers/microservices_engine/application_controller.rb
Defined Under Namespace
Modules: V1 Classes: ApplicationController, Connection, Engine
Constant Summary collapse
- VERSION =
'0.1.2'
Class Method Summary collapse
-
.build ⇒ Object
Returns the engine’s current build.
-
.build=(b) ⇒ Object
Setter method for the ‘build` portion of the engine, includes various validations.
-
.get(resource, path, params = {}) ⇒ Object
Redirects an engine ‘get` call to the appropriate resource.
-
.reload_config ⇒ Object
(also: config)
Reloads and returns the engine’s current YML configuration.
-
.valid_token?(token) ⇒ Boolean
- Takes in a token and verifies against the engine’s YML configuration files Params:
token
-
The token to test validity of.
- Takes in a token and verifies against the engine’s YML configuration files Params:
Class Method Details
.build ⇒ Object
Returns the engine’s current build
45 46 47 |
# File 'lib/microservices_engine.rb', line 45 def build @build ||= '0.0.0' end |
.build=(b) ⇒ Object
Setter method for the ‘build` portion of the engine, includes various validations
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# 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 |
.get(resource, path, params = {}) ⇒ Object
Redirects an engine ‘get` call to the appropriate resource
70 71 72 |
# File 'lib/microservices_engine.rb', line 70 def get(resource, path, params = {}) MicroservicesEngine::Connection.get(resource, path, params) end |
.reload_config ⇒ Object Also known as: config
Reloads and returns the engine’s current YML configuration
50 51 52 |
# File 'lib/microservices_engine.rb', line 50 def reload_config @config = YAML.load_file('config/mse_router_info.yml') end |
.valid_token?(token) ⇒ Boolean
Takes in a token and verifies against the engine’s YML configuration files Params:
token
-
The token to test validity of
60 61 62 63 64 65 66 67 |
# 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 |