Class: Bricolage::Context

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#environmentObject (readonly)

Returns the value of attribute environment.



61
62
63
# File 'lib/bricolage/context.rb', line 61

def environment
  @environment
end

#loggerObject (readonly)

Returns the value of attribute logger.



62
63
64
# File 'lib/bricolage/context.rb', line 62

def logger
  @logger
end

#option_variablesObject (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.for_options(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_variablesObject



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_variablesObject

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_configurationsObject



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_variablesObject



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_optionsObject



98
99
100
# File 'lib/bricolage/context.rb', line 98

def load_system_options
  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_nameObject



76
77
78
# File 'lib/bricolage/context.rb', line 76

def subsystem_name
  @filesystem.scope
end