class Bricolage::Context

Constants

DEFAULT_ENV
GLOBAL_VARIABLE_FILE
SYSTEM_OPTION_FILE

System Parameters

Attributes

environment[R]
logger[R]

Public Class Methods

environment(opt_env = nil) click to toggle source
# 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, global_variables: nil, logger: nil) click to toggle source
# File lib/bricolage/context.rb, line 22
def Context.for_application(home_path = nil, job_path_0 = nil, job_path: nil, environment: nil, global_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.for_options(home_path, env)
  end
  load(fs, env, global_variables: global_variables, logger: logger)
end
home_path(opt_path = nil) click to toggle source
# File lib/bricolage/context.rb, line 18
def Context.home_path(opt_path = nil)
  FileSystem.home_path(opt_path)
end
new(fs, env, global_variables: nil, data_sources: nil, logger: nil) click to toggle source
# File lib/bricolage/context.rb, line 42
def initialize(fs, env, global_variables: nil, data_sources: nil, logger: nil)
  @logger = logger || Logger.default
  @filesystem = fs
  @environment = env
  @opt_global_variables = global_variables || Variables.new
  @data_sources = data_sources
end

Private Class Methods

load(fs, env, global_variables: nil, data_sources: nil, logger: nil) click to toggle source
# File lib/bricolage/context.rb, line 35
def Context.load(fs, env, global_variables: nil, data_sources: nil, logger: nil)
  new(fs, env, global_variables: global_variables, logger: logger).tap {|ctx|
    ctx.load_configurations
  }
end

Public Instance Methods

builtin_variables() click to toggle source
# File lib/bricolage/context.rb, line 109
def builtin_variables
  Variables.define {|vars|
    vars['bricolage_env'] = @environment
    vars['bricolage_home'] = home_path.to_s
  }
end
get_data_source(type, name) click to toggle source
# File lib/bricolage/context.rb, line 60
def get_data_source(type, name)
  @data_sources.get(type, name)
end
global_variables() click to toggle source

Variables

# File lib/bricolage/context.rb, line 101
def global_variables
  Variables.union(
    builtin_variables,
    load_global_variables,
    @opt_global_variables
  )
end
load_configurations() click to toggle source
# File lib/bricolage/context.rb, line 50
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() click to toggle source
# File lib/bricolage/context.rb, line 118
def load_global_variables
  load_variables_for_all_scopes(GLOBAL_VARIABLE_FILE)
end
load_system_options() click to toggle source
# File lib/bricolage/context.rb, line 93
def load_system_options
  load_variables_for_all_scopes(SYSTEM_OPTION_FILE)
end
subsystem(id) click to toggle source
# File lib/bricolage/context.rb, line 64
def subsystem(id)
  self.class.new(@filesystem.subsystem(id), @environment,
    global_variables: @opt_global_variables,
    data_sources: @data_sources,
    logger: @logger)
end
subsystem_name() click to toggle source
# File lib/bricolage/context.rb, line 71
def subsystem_name
  @filesystem.scope
end

Private Instance Methods

load_variables(path) click to toggle source
# File lib/bricolage/context.rb, line 131
def load_variables(path)
  Variables.define {|vars|
    @filesystem.config_file_loader.load_yaml(path).each do |name, value|
      vars[name] = value
    end
  }
end
load_variables_for_all_scopes(basename) click to toggle source
# File lib/bricolage/context.rb, line 122
def load_variables_for_all_scopes(basename)
  subsys_path = scoped? ? [@filesystem.relative(basename)] : []
  vars_list = (config_pathes(basename) + subsys_path).map {|path|
    path.exist? ? load_variables(path) : nil
  }
  Variables.union(*vars_list.compact)
end