Class: Bricolage::Context
- Inherits:
-
Object
- Object
- Bricolage::Context
- Extended by:
- Forwardable
- Defined in:
- lib/bricolage/context.rb
Constant Summary collapse
- DEFAULT_ENV =
'development'- SYSTEM_OPTION_FILE =
System Parameters
'bricolage.yml'- GLOBAL_VARIABLE_FILE =
'variable.yml'
Instance Attribute Summary collapse
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#option_variables ⇒ Object
readonly
Returns the value of attribute option_variables.
Class Method Summary collapse
- .environment(opt_env = nil) ⇒ Object
- .for_application(home_path = nil, job_path_0 = nil, job_path: nil, environment: nil, option_variables: nil, logger: nil) ⇒ Object
- .home_path(opt_path = nil) ⇒ Object
Instance Method Summary collapse
- #builtin_variables ⇒ Object
- #get_data_source(type, name) ⇒ Object
-
#global_variables ⇒ Object
Variables.
-
#initialize(fs, env, option_variables: nil, data_sources: nil, logger: nil) ⇒ Context
constructor
A new instance of Context.
- #load_configurations ⇒ Object
- #load_global_variables ⇒ Object
- #load_system_options ⇒ Object
- #subsystem(id) ⇒ Object
- #subsystem_name ⇒ Object
Constructor Details
#initialize(fs, env, option_variables: nil, data_sources: nil, logger: nil) ⇒ Context
Returns a new instance of Context.
42 43 44 45 46 47 48 |
# File 'lib/bricolage/context.rb', line 42 def initialize(fs, env, option_variables: nil, data_sources: nil, logger: nil) @logger = logger || default_logger(env) @filesystem = fs @environment = env @option_variables = option_variables || Variables.new @data_sources = data_sources end |
Instance Attribute Details
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
61 62 63 |
# File 'lib/bricolage/context.rb', line 61 def environment @environment end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
62 63 64 |
# File 'lib/bricolage/context.rb', line 62 def logger @logger end |
#option_variables ⇒ Object (readonly)
Returns the value of attribute option_variables.
63 64 65 |
# File 'lib/bricolage/context.rb', line 63 def option_variables @option_variables end |
Class Method Details
.environment(opt_env = nil) ⇒ Object
14 15 16 |
# File 'lib/bricolage/context.rb', line 14 def Context.environment(opt_env = nil) opt_env || ENV['BRICOLAGE_ENV'] || DEFAULT_ENV end |
.for_application(home_path = nil, job_path_0 = nil, job_path: nil, environment: nil, option_variables: nil, logger: nil) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/bricolage/context.rb', line 22 def Context.for_application(home_path = nil, job_path_0 = nil, job_path: nil, environment: nil, option_variables: nil, logger: nil) env = environment(environment) if (job_path ||= job_path_0) fs = FileSystem.for_job_path(job_path, env) if home_path and home_path.realpath.to_s != fs.home_path.realpath.to_s raise OptionError, "--home option and job file is exclusive" end else fs = FileSystem.(home_path, env) end load(fs, env, option_variables: option_variables, logger: logger) end |
.home_path(opt_path = nil) ⇒ Object
18 19 20 |
# File 'lib/bricolage/context.rb', line 18 def Context.home_path(opt_path = nil) FileSystem.home_path(opt_path) end |
Instance Method Details
#builtin_variables ⇒ Object
113 114 115 116 117 118 |
# File 'lib/bricolage/context.rb', line 113 def builtin_variables Variables.define {|vars| vars['bricolage_env'] = @environment vars['bricolage_home'] = home_path.to_s } end |
#get_data_source(type, name) ⇒ Object
65 66 67 |
# File 'lib/bricolage/context.rb', line 65 def get_data_source(type, name) @data_sources.get(type, name) end |
#global_variables ⇒ Object
Variables
106 107 108 109 110 111 |
# File 'lib/bricolage/context.rb', line 106 def global_variables Variables.union( builtin_variables, load_global_variables, ) end |
#load_configurations ⇒ Object
54 55 56 57 58 59 |
# File 'lib/bricolage/context.rb', line 54 def load_configurations @filesystem.config_pathes('prelude.rb').each do |path| EmbeddedCodeAPI.module_eval(File.read(path), path.to_s, 1) if path.exist? end @data_sources = DataSourceFactory.load(self, @logger) end |
#load_global_variables ⇒ Object
122 123 124 |
# File 'lib/bricolage/context.rb', line 122 def load_global_variables load_variables_for_all_scopes(GLOBAL_VARIABLE_FILE) end |
#load_system_options ⇒ Object
98 99 100 |
# File 'lib/bricolage/context.rb', line 98 def load_variables_for_all_scopes(SYSTEM_OPTION_FILE) end |
#subsystem(id) ⇒ Object
69 70 71 72 73 74 |
# File 'lib/bricolage/context.rb', line 69 def subsystem(id) self.class.new(@filesystem.subsystem(id), @environment, option_variables: @option_variables, data_sources: @data_sources, logger: @logger) end |
#subsystem_name ⇒ Object
76 77 78 |
# File 'lib/bricolage/context.rb', line 76 def subsystem_name @filesystem.scope end |