arkaan 0.6.2 → 0.6.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/arkaan/utils.rb +2 -2
- data/lib/arkaan/utils/micro_service.rb +59 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b55f4b19871258edaa210f4803de26d312ff87a
|
4
|
+
data.tar.gz: 385cdfa3c03601ea33e3c789cf68b418305c2d38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 044482743f1eb117fa8ca0001540c406702f3a6c4adb9f0b568b33b0ebb992f65a1bdeb5d4dacfd85fd60f43f3b1685a26c8377392a065af2f7d91f21d14f8a5
|
7
|
+
data.tar.gz: 4e302ff1f70e0bf36afd2e558244f2e5ca4f6e22b4532b47e9f2364be9cdca00243da68510d5a1f760e9889dd86bc64863e58a972ceb71565bc648a5af4d10d4
|
data/lib/arkaan/utils.rb
CHANGED
@@ -2,7 +2,7 @@ module Arkaan
|
|
2
2
|
# Utility classes for the different micro-services of the suite.
|
3
3
|
# @author Vincent Courtois <courtois.vincent@outlook.com>
|
4
4
|
module Utils
|
5
|
-
autoload :Controller, 'arkaan/utils/controller'
|
6
|
-
autoload :
|
5
|
+
autoload :Controller , 'arkaan/utils/controller'
|
6
|
+
autoload :MicroService, 'arkaan/utils/micro_service'
|
7
7
|
end
|
8
8
|
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module Arkaan
|
2
|
+
module Utils
|
3
|
+
# The MicroService class is the loader for a micro service in general.
|
4
|
+
# @author Vincent Courtois <courtois.vincent@outlook.com>
|
5
|
+
class MicroService
|
6
|
+
|
7
|
+
# @!attribute [r] root
|
8
|
+
# @return [String] the root path of the application, from where each path is deduced.
|
9
|
+
attr_reader :root
|
10
|
+
|
11
|
+
attr_reader :name
|
12
|
+
|
13
|
+
# loads the application by requiring the files from the folders they're supposed to be in.
|
14
|
+
# @param name [String] the snake-cased name of the application, for service registration purpose mainly.
|
15
|
+
# @param root [String]
|
16
|
+
def initialize(name:, root:)
|
17
|
+
@root = root
|
18
|
+
@name = name
|
19
|
+
end
|
20
|
+
|
21
|
+
# Loads the necessary components for the application by requiring the needed files.
|
22
|
+
# @param test_mode [Boolean] TRUE if the application i supposed to be launched from the spec_helper, FALSE otherwise.
|
23
|
+
def load(test_mode: false)
|
24
|
+
self.require_mongoid_config(root)
|
25
|
+
self.require_folder(root, 'decorators')
|
26
|
+
self.require_folder(root, 'controllers')
|
27
|
+
if test_mode
|
28
|
+
self.require_folder(root, 'spec', 'support')
|
29
|
+
self.require_folder(root, 'spec', 'shared')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Creates the service instance if necessary, and returns it.
|
34
|
+
# @return [Arkaan::Monitoring::Service] the service in the registry corresponding to this micro-service.
|
35
|
+
def registered_service
|
36
|
+
service = Arkaan::Monitoring::Service.where(key: @name).first
|
37
|
+
if service.nil?
|
38
|
+
service = Arkaan::Monitoring::Service.create!(key: @name, path: "/#{@name}", premium: true, active: true)
|
39
|
+
end
|
40
|
+
if service.instances.where(url: ENV['SERVICE_URL']).first.nil?
|
41
|
+
Arkaan::Monitoring::Instance.create!(url: ENV['SERVICE_URL'], running: true, service: service, active: true)
|
42
|
+
end
|
43
|
+
return service
|
44
|
+
end
|
45
|
+
|
46
|
+
# Require all the files from a folder iteratively by assembling the parts given as parameters.
|
47
|
+
# @param paths_elements [Array<String>] the elements to assemble to form the path of the folder.
|
48
|
+
def require_folder(*paths_elements)
|
49
|
+
File.join(path_elements, '**', '*.rb').each { |filename| block.call(filename) }
|
50
|
+
end
|
51
|
+
|
52
|
+
# Requires and loads the mongoid configuration from its default location.
|
53
|
+
# @param root [String] the root folder of the application from where require the configuration path;
|
54
|
+
def require_mongoid_config(root)
|
55
|
+
Mongoid.load!(File.join(root, 'config', 'mongoid.yml'))
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arkaan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vincent Courtois
|
@@ -209,6 +209,7 @@ files:
|
|
209
209
|
- lib/arkaan/permissions/right.rb
|
210
210
|
- lib/arkaan/utils.rb
|
211
211
|
- lib/arkaan/utils/controller.rb
|
212
|
+
- lib/arkaan/utils/micro_service.rb
|
212
213
|
- lib/arkaan/utils/seeder.rb
|
213
214
|
homepage: https://rubygems.org/gems/arkaan
|
214
215
|
licenses:
|