Class: IronNails::Configuration
- Inherits:
-
Object
- Object
- IronNails::Configuration
- Defined in:
- lib/ironnails/config/configuration.rb
Overview
This structure has been heavily inspired by the rails framework. The Configuration class holds all the parameters for the Initializer Usually, you’ll create a Configuration file implicitly through the block running on the Initializer, but it’s also possible to create the Configuration instance in advance and pass it in like this:
config = IronNails::Configuration.new
IronNails::Initializer.run(config)
Instance Attribute Summary collapse
-
#application_paths ⇒ Object
readonly
the search paths for ruby source files.
-
#assembly_paths ⇒ Object
readonly
the search paths for .NET binaries.
-
#excluded_files ⇒ Object
readonly
the files that won’t be initialized through this procedure.
-
#log_level ⇒ Object
The log level to use for the default Rails logger.
-
#log_path ⇒ Object
The path to the log file to use.
-
#logger ⇒ Object
The specific logger to use.
-
#namespaces ⇒ Object
readonly
the namespaces that need to be included by default.
-
#root_path ⇒ Object
readonly
the root path for our application.
Instance Method Summary collapse
-
#default_application_paths ⇒ Object
The paths that contain sources for our application.
-
#default_assembly_paths ⇒ Object
The paths that contain .NET binaries.
-
#default_excluded_files ⇒ Object
files to exclude from requiring in our app.
- #default_log_level ⇒ Object
- #default_log_path ⇒ Object
- #default_namespaces ⇒ Object
- #environment ⇒ Object
-
#excluded_file?(file_path) ⇒ Boolean
returns wheter or not the specified path is an excluded file.
-
#initialize(rpath = (File.dirname(__FILE__) + '/../../..')) ⇒ Configuration
constructor
A new instance of Configuration.
- #initialize_with_defaults ⇒ Object
-
#set_root_path! ⇒ Object
Set the root_path to IRONNAILS_ROOT and canonicalize it.
Constructor Details
#initialize(rpath = (File.dirname(__FILE__) + '/../../..')) ⇒ Configuration
Returns a new instance of Configuration.
44 45 46 47 |
# File 'lib/ironnails/config/configuration.rb', line 44 def initialize(rpath = (File.dirname(__FILE__) + '/../../..')) @root_path = rpath initialize_with_defaults end |
Instance Attribute Details
#application_paths ⇒ Object (readonly)
the search paths for ruby source files
18 19 20 |
# File 'lib/ironnails/config/configuration.rb', line 18 def application_paths @application_paths end |
#assembly_paths ⇒ Object (readonly)
the search paths for .NET binaries
21 22 23 |
# File 'lib/ironnails/config/configuration.rb', line 21 def assembly_paths @assembly_paths end |
#excluded_files ⇒ Object (readonly)
the files that won’t be initialized through this procedure
27 28 29 |
# File 'lib/ironnails/config/configuration.rb', line 27 def excluded_files @excluded_files end |
#log_level ⇒ Object
The log level to use for the default Rails logger. In production mode, this defaults to :info
. In development mode, it defaults to :debug
.
32 33 34 |
# File 'lib/ironnails/config/configuration.rb', line 32 def log_level @log_level end |
#log_path ⇒ Object
The path to the log file to use. Defaults to log/##environment.log (e.g. log/development.log or log/production.log).
36 37 38 |
# File 'lib/ironnails/config/configuration.rb', line 36 def log_path @log_path end |
#logger ⇒ Object
The specific logger to use. By default, a logger will be created and initialized using #log_path and #log_level, but a programmer may specifically set the logger to use via this accessor and it will be used directly.
42 43 44 |
# File 'lib/ironnails/config/configuration.rb', line 42 def logger @logger end |
#namespaces ⇒ Object (readonly)
the namespaces that need to be included by default
24 25 26 |
# File 'lib/ironnails/config/configuration.rb', line 24 def namespaces @namespaces end |
#root_path ⇒ Object (readonly)
the root path for our application
15 16 17 |
# File 'lib/ironnails/config/configuration.rb', line 15 def root_path @root_path end |
Instance Method Details
#default_application_paths ⇒ Object
The paths that contain sources for our application. We will require these at a later stage
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/ironnails/config/configuration.rb', line 55 def default_application_paths paths = [] # Followed by the standard includes. paths.concat %w( config lib lib/core_ext app app/models app/controllers app/converters app/helpers ).map { |dir| "#{root_path}/#{dir}" }.select { |dir| File.directory?(dir) } end |
#default_assembly_paths ⇒ Object
The paths that contain .NET binaries
90 91 92 93 |
# File 'lib/ironnails/config/configuration.rb', line 90 def default_assembly_paths paths = [] paths.concat %w( bin ).map{ |dir| "#{root_path}/#{dir}"}.select{ |dir| File.directory?(dir) } end |
#default_excluded_files ⇒ Object
files to exclude from requiring in our app
72 73 74 |
# File 'lib/ironnails/config/configuration.rb', line 72 def default_excluded_files ['config/environment.rb', 'lib/main.rb', 'config/boot.rb', 'bin/IronNails.Library.dll' ].collect{ |dir| "#{root_path}/#{dir}" } end |
#default_log_level ⇒ Object
76 77 78 |
# File 'lib/ironnails/config/configuration.rb', line 76 def default_log_level (IRONNAILS_ENV == 'development' || IRONNAILS_ENV.nil?) ? :debug : :info end |
#default_log_path ⇒ Object
80 81 82 |
# File 'lib/ironnails/config/configuration.rb', line 80 def default_log_path File.join(root_path, 'log', "#{environment}.log") end |
#default_namespaces ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/ironnails/config/configuration.rb', line 95 def default_namespaces %w( System System::Net System::Xml System::IO System::Web System::Text System::Threading System::Windows System::Collections::ObjectModel IronNails::Controller IronNails::View ) end |
#environment ⇒ Object
49 50 51 |
# File 'lib/ironnails/config/configuration.rb', line 49 def environment ::IRONNAILS_ENV end |
#excluded_file?(file_path) ⇒ Boolean
returns wheter or not the specified path is an excluded file
85 86 87 |
# File 'lib/ironnails/config/configuration.rb', line 85 def excluded_file?(file_path) excluded_files.include? file_path end |
#initialize_with_defaults ⇒ Object
111 112 113 114 115 |
# File 'lib/ironnails/config/configuration.rb', line 111 def initialize_with_defaults set_root_path! @application_paths, @assembly_paths, @namespaces, @excluded_files = default_application_paths, default_assembly_paths, default_namespaces, default_excluded_files @log_level, @log_path = default_log_level, default_log_path end |
#set_root_path! ⇒ Object
Set the root_path to IRONNAILS_ROOT and canonicalize it.
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/ironnails/config/configuration.rb', line 118 def set_root_path! raise 'IRONNAILS_ROOT is not set' unless defined?(::IRONNAILS_ROOT) raise 'IRONNAILS_ROOT is not a directory' unless File.directory?(::IRONNAILS_ROOT) @root_path = # Pathname is incompatible with Windows, but Windows doesn't have # real symlinks so File.expand_path is safe. if ENV['OS'] == 'Windows_NT'.freeze File.(::IRONNAILS_ROOT) # Otherwise use Pathname#realpath which respects symlinks. else Pathname.new(::IRONNAILS_ROOT).realpath.to_s end Object.const_set(:RELATIVE_IRONNAILS_ROOT, ::IRONNAILS_ROOT.dup) unless defined?(::RELATIVE_IRONNAILS_ROOT) ::IRONNAILS_ROOT.replace @root_path end |