Class: Masamune::Configuration
- Inherits:
-
Hashie::Dash
- Object
- Hashie::Dash
- Masamune::Configuration
show all
- Extended by:
- Forwardable
- Includes:
- Hashie::Extensions::IndifferentAccess, Hashie::Extensions::MergeInitializer, HasEnvironment
- Defined in:
- lib/masamune/configuration.rb
Class Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#environment, #environment=
Constructor Details
Returns a new instance of Configuration.
64
65
66
67
68
69
|
# File 'lib/masamune/configuration.rb', line 64
def initialize(*a)
super
self.class.default_commands.each do |command|
commands[command] = Hashie::Mash.new
end
end
|
Class Attribute Details
.default_config_file ⇒ Object
42
43
44
|
# File 'lib/masamune/configuration.rb', line 42
def default_config_file
@default_config_file ||= File.join(File.expand_path('../../../', __FILE__), 'config', 'masamune.yml.erb')
end
|
Class Method Details
.default_commands ⇒ Object
46
47
48
|
# File 'lib/masamune/configuration.rb', line 46
def default_commands
@default_commands ||= %i[aws_emr hive hadoop_streaming hadoop_filesystem s3cmd postgres postgres_admin]
end
|
Instance Method Details
#as_options ⇒ Object
105
106
107
108
109
110
111
112
|
# File 'lib/masamune/configuration.rb', line 105
def as_options
opts = []
opts << '--quiet' if quiet
opts << '--verbose' if verbose
opts << '--debug' if debug
opts << '--dry-run' if dry_run
opts
end
|
#debug=(debug) ⇒ Object
100
101
102
103
|
# File 'lib/masamune/configuration.rb', line 100
def debug=(debug)
self[:debug] = debug
environment.reload_logger!
end
|
#default_config_file ⇒ Object
130
131
132
|
# File 'lib/masamune/configuration.rb', line 130
def default_config_file
self.class.default_config_file
end
|
#load(path) ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/masamune/configuration.rb', line 71
def load(path)
@load_once ||= begin
config_file = filesystem.eval_path(path)
load_yaml_erb_file(config_file).each_pair do |command, value|
if command == 'commands'
commands.merge!(value)
elsif command == 'paths'
load_paths(value)
elsif command == 'params'
raise ArgumentError, 'params section must only contain key value pairs' unless value.is_a?(Hash)
params.merge! value
end
end
logger.debug("Loaded configuration #{config_file}")
load_catalog(configuration.commands.postgres.fetch(:schema_files, []) + configuration.commands.hive.fetch(:schema_files, []))
self
end
end
|
#load_catalog(paths = []) ⇒ Object
90
91
92
93
94
95
96
97
98
|
# File 'lib/masamune/configuration.rb', line 90
def load_catalog(paths = [])
paths.each do |path|
filesystem.glob_sort(path, order: :basename) do |file|
configuration.with_quiet do
catalog.load(file)
end
end
end
end
|
#load_yaml_erb_file(file) ⇒ Object
124
125
126
127
128
|
# File 'lib/masamune/configuration.rb', line 124
def load_yaml_erb_file(file)
t = ERB.new(File.read(file))
t.filename = file
YAML.safe_load(t.result(binding))
end
|
#with_quiet ⇒ Object
116
117
118
119
120
121
122
|
# File 'lib/masamune/configuration.rb', line 116
def with_quiet
prev_quiet = quiet
self.quiet = true
yield
ensure
self.quiet = prev_quiet
end
|