Class: Arkaan::Utils::MicroService
- Inherits:
-
Object
- Object
- Arkaan::Utils::MicroService
- Includes:
- Singleton
- Defined in:
- lib/virtuaservices/utils/micro_service.rb
Overview
This class is a singleton to load and save parameters for the whole application.
Instance Attribute Summary collapse
-
#instance ⇒ Object
readonly
Returns the value of attribute instance.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#service ⇒ Object
readonly
Returns the value of attribute service.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#deactivate! ⇒ Object
Deactivates the current instance and the associated service if no more instances are available.
-
#from_location(filename) ⇒ Arkaan::utils::MicroService
Sets the location of the file calling the micro service and initializing it so that it’s used as root.
- #get_const(symbol) ⇒ Object
- #get_controllers ⇒ Object
-
#in_standard_mode ⇒ Arkaan::utils::MicroService
Loads the application in standard (production/development) mode, without the test files.
-
#in_test_mode ⇒ Arkaan::utils::MicroService
Loads the application in test mode, by adding the needed files to run the test suite to the standard loading process.
-
#in_websocket_mode ⇒ Arkaan::utils::MicroService
Loads the application as a websockets service.
-
#initialize ⇒ MicroService
constructor
A new instance of MicroService.
-
#loadable? ⇒ Boolean
Determines if the application can be loaded (all the parameters have been correctly set).
-
#path ⇒ String, Boolean
Getter for the path on which the service is mapped.
-
#register_as(service_name) ⇒ Arkaan::utils::MicroService
Look for the service and sets it if it’s found in the database, or set it to nil if not found.
Constructor Details
#initialize ⇒ MicroService
Returns a new instance of MicroService.
24 25 26 27 28 29 30 31 |
# File 'lib/virtuaservices/utils/micro_service.rb', line 24 def initialize @location = false @service = false @instance = false @name = false @type = ENV['INSTANCE_TYPE'] || :heroku @controller_classes = [] end |
Instance Attribute Details
#instance ⇒ Object (readonly)
Returns the value of attribute instance.
19 20 21 |
# File 'lib/virtuaservices/utils/micro_service.rb', line 19 def instance @instance end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
13 14 15 |
# File 'lib/virtuaservices/utils/micro_service.rb', line 13 def location @location end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
10 |
# File 'lib/virtuaservices/utils/micro_service.rb', line 10 attr_reader :service |
#service ⇒ Object (readonly)
Returns the value of attribute service.
10 11 12 |
# File 'lib/virtuaservices/utils/micro_service.rb', line 10 def service @service end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
22 23 24 |
# File 'lib/virtuaservices/utils/micro_service.rb', line 22 def type @type end |
Instance Method Details
#deactivate! ⇒ Object
Deactivates the current instance and the associated service if no more instances are available.
95 96 97 98 |
# File 'lib/virtuaservices/utils/micro_service.rb', line 95 def deactivate! instance.update_attribute(:running, false) service.update_attribute(:test_mode, false) if ENV['TEST_MODE'] end |
#from_location(filename) ⇒ Arkaan::utils::MicroService
Sets the location of the file calling the micro service and initializing it so that it’s used as root.
66 67 68 69 |
# File 'lib/virtuaservices/utils/micro_service.rb', line 66 def from_location(filename) @location = File.dirname(filename) return self end |
#get_const(symbol) ⇒ Object
39 40 41 |
# File 'lib/virtuaservices/utils/micro_service.rb', line 39 def get_const(symbol) return Object.const_get("Controllers::#{symbol.to_s}") end |
#get_controllers ⇒ Object
33 34 35 36 37 |
# File 'lib/virtuaservices/utils/micro_service.rb', line 33 def get_controllers return [] if defined?(Controllers).nil? classes = Controllers.constants.map { |symbol| get_const(symbol) } return classes.select { |symbol| symbol.is_a? Class } end |
#in_standard_mode ⇒ Arkaan::utils::MicroService
Loads the application in standard (production/development) mode, without the test files.
73 74 75 |
# File 'lib/virtuaservices/utils/micro_service.rb', line 73 def in_standard_mode return load_application(test_mode: false) end |
#in_test_mode ⇒ Arkaan::utils::MicroService
Loads the application in test mode, by adding the needed files to run the test suite to the standard loading process.
79 80 81 82 |
# File 'lib/virtuaservices/utils/micro_service.rb', line 79 def in_test_mode @location = File.join(location, '..') return load_application(test_mode: true) end |
#in_websocket_mode ⇒ Arkaan::utils::MicroService
Loads the application as a websockets service. Only the websockets application should use that.
86 87 88 89 90 91 92 |
# File 'lib/virtuaservices/utils/micro_service.rb', line 86 def in_websocket_mode load_mongoid_configuration load_standard_files Arkaan::Monitoring::Websocket.find_or_create_by(url: ENV['WEBSOCKET_URL']).save return self end |
#loadable? ⇒ Boolean
Determines if the application can be loaded (all the parameters have been correctly set)
45 46 47 |
# File 'lib/virtuaservices/utils/micro_service.rb', line 45 def loadable? return !!(service && location) end |
#path ⇒ String, Boolean
Getter for the path on which the service is mapped.
51 52 53 |
# File 'lib/virtuaservices/utils/micro_service.rb', line 51 def path return service ? service.path : false end |
#register_as(service_name) ⇒ Arkaan::utils::MicroService
Look for the service and sets it if it’s found in the database, or set it to nil if not found.
58 59 60 61 |
# File 'lib/virtuaservices/utils/micro_service.rb', line 58 def register_as(service_name) @name = service_name return self end |