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.
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/frecon/base/environment.rb', line 34 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.
15 16 17 |
# File 'lib/frecon/base/environment.rb', line 15 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.
21 22 23 |
# File 'lib/frecon/base/environment.rb', line 21 def database @database end |
#server ⇒ Object
Public: The configuration Hash for the server-related configuration.
Keys will typically include ‘port’, ‘host’, etc.
12 13 14 |
# File 'lib/frecon/base/environment.rb', line 12 def server @server end |
#variable ⇒ Object
Public: Get the configuration variable.
Returns the value of @variable.
26 27 28 |
# File 'lib/frecon/base/environment.rb', line 26 def variable @variable end |
Instance Method Details
#default_configuration ⇒ Object
Public: Read and parse the defaults configuration file.
95 96 97 |
# File 'lib/frecon/base/environment.rb', line 95 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.
87 88 89 90 91 |
# File 'lib/frecon/base/environment.rb', line 87 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.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/frecon/base/environment.rb', line 58 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.
100 101 102 |
# File 'lib/frecon/base/environment.rb', line 100 def system_configuration read_configuration(system_configuration_filename) end |
#user_configuration ⇒ Object
Public: Read and parse the user configuration file.
105 106 107 |
# File 'lib/frecon/base/environment.rb', line 105 def user_configuration read_configuration(user_configuration_filename) end |