Class: Singer::Paths
- Inherits:
-
Object
- Object
- Singer::Paths
- Defined in:
- lib/singer/paths.rb
Overview
helps find files
Class Method Summary collapse
- .output_path ⇒ Object
- .singer_config_dir ⇒ Object
-
.substitute_variables(path) ⇒ Object
will substitute non-forbidden variables, 2 characters or more.
- .templates_from_gem ⇒ Object
- .templates_from_user ⇒ Object
- .variable_name_can_be_substituted?(name) ⇒ Boolean
- .xdg_config_dir ⇒ Object
Class Method Details
.output_path ⇒ Object
20 21 22 |
# File 'lib/singer/paths.rb', line 20 def self.output_path(...) substitute_variables(File.join(...)) end |
.singer_config_dir ⇒ Object
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_gem ⇒ Object
16 17 18 |
# File 'lib/singer/paths.rb', line 16 def self.templates_from_gem @templates_from_gem ||= File.('../../templates', __dir__) end |
.templates_from_user ⇒ Object
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
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_dir ⇒ Object
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 |