Loading lib/labkit/covered_experience/registry.rb +7 −16 Original line number Diff line number Diff line Loading @@ -18,8 +18,8 @@ module Labkit # @param dir [String, Pathname] Directory path containing YAML file definitions # Defaults to 'config/covered_experiences' relative to the calling application's root def initialize(dir: nil) @dir = dir def initialize(dir: File.join("config", "covered_experiences")) @dir = Pathname.new(Dir.pwd).join(dir) @experiences = load_on_demand @invalid_definitions = {} end Loading @@ -45,8 +45,8 @@ module Labkit # # @return [Hash] Hash with lazy loading behavior def load_on_demand unless directory_exists?(directory_path) warn("Directory not readable: #{directory_path}") unless directory_exists? warn("Directory not readable: #{@dir}") return {} end Loading @@ -66,22 +66,13 @@ module Labkit read_experience(file_path, experience_id) if file_path end # Resolve the directory path, using default if @dir not provided. # Expands relative paths from the current working directory. # # @return [Pathname] Resolved directory path def directory_path dir = @dir || File.join("config", "covered_experiences") Pathname.new(Dir.pwd).join(dir) end def directory_exists?(directory_path) directory_path.exist? && directory_path.directory? && directory_path.readable? def directory_exists? @dir.exist? && @dir.directory? && @dir.readable? end def experience_definitions @experience_definitions ||= directory_path.glob('*.yml').each_with_object({}) do |file_path, hash| # rubocop:disable Rails/IndexBy @dir.glob('*.yml').each_with_object({}) do |file_path, hash| # rubocop:disable Rails/IndexBy hash[file_path.basename('.yml').to_s] = file_path end end Loading Loading
lib/labkit/covered_experience/registry.rb +7 −16 Original line number Diff line number Diff line Loading @@ -18,8 +18,8 @@ module Labkit # @param dir [String, Pathname] Directory path containing YAML file definitions # Defaults to 'config/covered_experiences' relative to the calling application's root def initialize(dir: nil) @dir = dir def initialize(dir: File.join("config", "covered_experiences")) @dir = Pathname.new(Dir.pwd).join(dir) @experiences = load_on_demand @invalid_definitions = {} end Loading @@ -45,8 +45,8 @@ module Labkit # # @return [Hash] Hash with lazy loading behavior def load_on_demand unless directory_exists?(directory_path) warn("Directory not readable: #{directory_path}") unless directory_exists? warn("Directory not readable: #{@dir}") return {} end Loading @@ -66,22 +66,13 @@ module Labkit read_experience(file_path, experience_id) if file_path end # Resolve the directory path, using default if @dir not provided. # Expands relative paths from the current working directory. # # @return [Pathname] Resolved directory path def directory_path dir = @dir || File.join("config", "covered_experiences") Pathname.new(Dir.pwd).join(dir) end def directory_exists?(directory_path) directory_path.exist? && directory_path.directory? && directory_path.readable? def directory_exists? @dir.exist? && @dir.directory? && @dir.readable? end def experience_definitions @experience_definitions ||= directory_path.glob('*.yml').each_with_object({}) do |file_path, hash| # rubocop:disable Rails/IndexBy @dir.glob('*.yml').each_with_object({}) do |file_path, hash| # rubocop:disable Rails/IndexBy hash[file_path.basename('.yml').to_s] = file_path end end Loading