Class: FReCon::Environment
Overview
Public: A class to represent the operational constraints for the FReCon instance.
Instance Attribute Summary collapse
-
#console ⇒ Object
Public: The configuration Hash for the console-related configuration.
-
#database ⇒ Object
Public: The configuration Hash for the database-related configuration.
-
#server ⇒ Object
Public: The configuration Hash for the server-related configuration.
-
#variable ⇒ Object
Public: Get the configuration variable.
Instance Method Summary collapse
-
#default_configuration ⇒ Object
Public: Read and parse the defaults configuration file.
-
#initialize(symbol, server: {}, console: {}, database: {}) ⇒ Environment
constructor
Public: Initialize an Environment.
-
#read_configuration(filename) ⇒ Object
Public: Read a configuration from a given filename.
-
#read_configurations ⇒ Object
Public: Read the various configurations on a system.
-
#system_configuration ⇒ Object
Public: Read and parse the system configuration file.
-
#user_configuration ⇒ Object
Public: Read and parse the user configuration file.
Constructor Details
#initialize(symbol, server: {}, console: {}, database: {}) ⇒ Environment
Public: Initialize an Environment.
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/frecon/base/environment.rb', line 33 def initialize(symbol, server: {}, console: {}, database: {}) @variable = symbol if validate_symbol(symbol) read_configurations @server = @server.merge(server) @console = @console.merge(console) @database = @database.merge(database) @server = @server.merge(server_defaults) @console = @console.merge(console_defaults) @database = @database.merge(database_defaults) end |
Instance Attribute Details
#console ⇒ Object
Public: The configuration Hash for the console-related configuration.
14 15 16 |
# File 'lib/frecon/base/environment.rb', line 14 def console @console end |
#database ⇒ Object
Public: The configuration Hash for the database-related configuration.
Keys will typically include ‘mongoid’, which should be a Hash representation of a valid mongoid.yml file.
20 21 22 |
# File 'lib/frecon/base/environment.rb', line 20 def database @database end |
#server ⇒ Object
Public: The configuration Hash for the server-related configuration.
Keys will typically include ‘port’, ‘host’, etc.
11 12 13 |
# File 'lib/frecon/base/environment.rb', line 11 def server @server end |
#variable ⇒ Object
Public: Get the configuration variable.
Returns the value of @variable.
25 26 27 |
# File 'lib/frecon/base/environment.rb', line 25 def variable @variable end |
Instance Method Details
#default_configuration ⇒ Object
Public: Read and parse the defaults configuration file.
94 95 96 |
# File 'lib/frecon/base/environment.rb', line 94 def default_configuration read_configuration(default_configuration_filename) end |
#read_configuration(filename) ⇒ Object
Public: Read a configuration from a given filename.
Uses YAML to parse the given filename.
filename - String containing the path to a file.
Returns a Hash containing the parsed data from the given file.
86 87 88 89 90 |
# File 'lib/frecon/base/environment.rb', line 86 def read_configuration(filename) YAML.load_file(filename) if (filename && File.exist?(filename) && File.readable?(filename)) end |
#read_configurations ⇒ Object
Public: Read the various configurations on a system.
Reads, then merges, the configurations present on a system. Then, splices out the server, console, and database configurations and assigns them.
If a configuration cannot be found, a value of {} is used for the merging, and it is considered to be simply noneffectual. Defaults should always be specified in the default configuration file.
Returns the merged configuration.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/frecon/base/environment.rb', line 57 def read_configurations # Read the configurations default = default_configuration system = system_configuration user = user_configuration # Create a configuration, initialize it to the default configuration. # # Then, merge with the system configuration, then the user configuration. configuration = default || {} configuration.merge(system || {}) configuration.merge(user || {}) # Grab out the 'server', 'console', and 'database' values from the # configuration and store those in the appropriate instance variables. @server = configuration['server'] || {} @console = configuration['console'] || {} @database = configuration['database'] || {} configuration end |
#system_configuration ⇒ Object
Public: Read and parse the system configuration file.
99 100 101 |
# File 'lib/frecon/base/environment.rb', line 99 def system_configuration read_configuration(system_configuration_filename) end |
#user_configuration ⇒ Object
Public: Read and parse the user configuration file.
104 105 106 |
# File 'lib/frecon/base/environment.rb', line 104 def user_configuration read_configuration(user_configuration_filename) end |