Module: GCEMetadata::Dummy

Defined in:
lib/gce_metadata/dummy.rb

Constant Summary collapse

YAML_FILENAME =
'gce_metadata.yml'.freeze
YAML_SEARCH_DIRS =
['./config', '.', '~', '/etc'].freeze
ENV_SPECIFIED_PATH =
"GCE_METADATA_DUMMY_YAML".freeze

Class Method Summary collapse

Class Method Details

.load_yaml(path) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/gce_metadata/dummy.rb', line 28

def load_yaml(path)
	erb = ERB.new(IO.read(path))
	erb.filename = path
	text = erb.result
	GCEMetadata.from_hash(YAML.load(text))
	@loaded_yaml_path = path
end

.loaded_yaml_pathObject



36
37
38
# File 'lib/gce_metadata/dummy.rb', line 36

def loaded_yaml_path
	@loaded_yaml_path
end

.search_and_load_yamlObject



23
24
25
26
# File 'lib/gce_metadata/dummy.rb', line 23

def search_and_load_yaml
	paths = Dir.glob(yaml_paths.map{|path| File.expand_path(path) rescue nil}.compact)
	load_yaml(paths.first) unless paths.empty?
end

.yaml_pathsObject



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/gce_metadata/dummy.rb', line 11

def yaml_paths
	dirs = YAML_SEARCH_DIRS.dup
	if Module.constants.include?('RAILS_ROOT')
		dirs.unshift(File.join(Module.const_get('RAILS_ROOT'), 'config'))
	end
	result = dirs.map{|d| File.join(d, YAML_FILENAME)}
	if (specified_path = ENV[ENV_SPECIFIED_PATH])
		result.unshift(specified_path)
	end
	result
end