class Devpack::Config
Locates and parses .devpack config file
Constants
- FILENAME
- INITIALIZERS_DIRECTORY_NAME
- MAX_PARENTS
Public Class Methods
new(pwd)
click to toggle source
# File lib/devpack/config.rb, line 10 def initialize(pwd) @pwd = Pathname.new(pwd) end
Public Instance Methods
devpack_initializer_paths()
click to toggle source
# File lib/devpack/config.rb, line 30 def devpack_initializer_paths devpack_initializers_path&.glob(File.join('**', '*.rb'))&.map(&:to_s)&.sort || [] end
devpack_initializers_path()
click to toggle source
# File lib/devpack/config.rb, line 26 def devpack_initializers_path @devpack_initializers_path ||= located_path(@pwd, INITIALIZERS_DIRECTORY_NAME, :directory) end
devpack_path()
click to toggle source
# File lib/devpack/config.rb, line 22 def devpack_path @devpack_path ||= located_path(@pwd, FILENAME, :file) end
requested_gems()
click to toggle source
# File lib/devpack/config.rb, line 14 def requested_gems return nil if devpack_path.nil? File.readlines(devpack_path) .map(&filter_comments) .compact end
Private Instance Methods
filter_comments()
click to toggle source
# File lib/devpack/config.rb, line 48 def filter_comments proc do |line| stripped = line.strip next nil if stripped.empty? next nil if stripped.start_with?('#') stripped.gsub(/\s*#.*$/, '') # Remove inline comments (like this one) end end
located_path(next_parent, filename, type)
click to toggle source
# File lib/devpack/config.rb, line 36 def located_path(next_parent, filename, type) loop.with_index(1) do |_, index| return nil if index > MAX_PARENTS path = next_parent.join(filename) next_parent = next_parent.parent next unless File.exist?(path) && File.public_send("#{type}?", path) return path end end