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
23
24
25
26
27
28
29
30
# File 'lib/singer/paths.rb', line 20

def self.output_path(...)
  File.join(...).gsub(/__([[:alpha:]][[:word:]]+)__/) do |match|
    potential_config = $1.downcase

    if variable_name_can_be_substituted?(potential_config)
      CONFIGURATION.send(potential_config)
    else
      match
    end
  end
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

.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)


32
33
34
# File 'lib/singer/paths.rb', line 32

def self.variable_name_can_be_substituted?(name)
  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