Class: Singer::Paths

Inherits:
Object
  • Object
show all
Defined in:
lib/singer/paths.rb

Overview

helps find files

Class Method Summary collapse

Class Method Details

.output_pathObject



20
21
22
# File 'lib/singer/paths.rb', line 20

def self.output_path(...)
	substitute_variables(File.join(...))
end

.singer_config_dirObject



8
9
10
# File 'lib/singer/paths.rb', line 8

def self.singer_config_dir
	@singer_config_dir ||= File.join(xdg_config_dir, 'singer')
end

.substitute_variables(path) ⇒ Object

will substitute non-forbidden variables, 2 characters or more



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/singer/paths.rb', line 25

def self.substitute_variables(path)
	path.gsub(/__([[:alpha:]][[:word:]]*[[:alpha:]])__/) do |match|
		potential_config = $1.downcase

		if variable_name_can_be_substituted?(potential_config)
			Singer.configuration.send(potential_config)
		else
			match
		end
	end
end

.templates_from_gemObject



16
17
18
# File 'lib/singer/paths.rb', line 16

def self.templates_from_gem
	@templates_from_gem ||= File.expand_path('../../templates', __dir__)
end

.templates_from_userObject



12
13
14
# File 'lib/singer/paths.rb', line 12

def self.templates_from_user
	@templates_from_user ||= File.join(singer_config_dir, 'templates')
end

.variable_name_can_be_substituted?(name) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/singer/paths.rb', line 37

def self.variable_name_can_be_substituted?(name)
	Singer.configuration.respond_to?(name) && !CONFIGURATION_VARIABLES_FORBIDDEN_IN_PATHS.include?(name)
end

.xdg_config_dirObject



4
5
6
# File 'lib/singer/paths.rb', line 4

def self.xdg_config_dir
	@xdg_config_dir ||= ENV.fetch('XDG_CONFIG_DIR', File.join(Dir.home, '.config'))
end