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, global_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, 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

Instance Attribute Details

#environmentObject (readonly)

Returns the value of attribute environment.



57
58
59
# File 'lib/bricolage/context.rb', line 57

def environment
  @environment
end

#loggerObject (readonly)

Returns the value of attribute logger.



58
59
60
# File 'lib/bricolage/context.rb', line 58

def logger
  @logger
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, global_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, 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) ⇒ 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



109
110
111
112
113
114
# 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) ⇒ Object



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

def get_data_source(type, name)
  @data_sources.get(type, name)
end

#global_variablesObject

Variables



101
102
103
104
105
106
107
# File 'lib/bricolage/context.rb', line 101

def global_variables
  Variables.union(
    builtin_variables,
    load_global_variables,
    @opt_global_variables
  )
end

#load_configurationsObject



50
51
52
53
54
55
# 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_variablesObject



118
119
120
# File 'lib/bricolage/context.rb', line 118

def load_global_variables
  load_variables_for_all_scopes(GLOBAL_VARIABLE_FILE)
end

#load_system_optionsObject



93
94
95
# File 'lib/bricolage/context.rb', line 93

def load_system_options
  load_variables_for_all_scopes(SYSTEM_OPTION_FILE)
end

#subsystem(id) ⇒ Object



64
65
66
67
68
69
# 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_nameObject



71
72
73
# File 'lib/bricolage/context.rb', line 71

def subsystem_name
  @filesystem.scope
end