Class: Kaisoku::Configuration
- Inherits:
-
Object
- Object
- Kaisoku::Configuration
- Defined in:
- lib/kaisoku/configuration.rb
Constant Summary collapse
- DEFAULT_BOOT_GLOBS =
[ 'config/**', 'config.ru', 'db/schema.rb', 'db/migrate/**', '.env', '.env.*' ].freeze
- MAP_INVALIDATING_FILES =
[ 'Gemfile.lock', '.ruby-version', '.tool-versions' ].freeze
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#map_path ⇒ Object
readonly
Returns the value of attribute map_path.
-
#method_level_threshold ⇒ Object
readonly
Returns the value of attribute method_level_threshold.
-
#project_root ⇒ Object
readonly
Returns the value of attribute project_root.
-
#track_paths ⇒ Object
readonly
Returns the value of attribute track_paths.
Instance Method Summary collapse
- #absolute_path(path) ⇒ Object
- #boot_impact_file?(path) ⇒ Boolean
-
#initialize(project_root: Dir.pwd, map_path: nil, adapter: 'rspec', track_paths: [], method_level_threshold: 20) ⇒ Configuration
constructor
A new instance of Configuration.
- #invalidates_map?(path) ⇒ Boolean
- #project_file?(path) ⇒ Boolean
- #relative_path(path) ⇒ Object
- #test_file?(path) ⇒ Boolean
Constructor Details
#initialize(project_root: Dir.pwd, map_path: nil, adapter: 'rspec', track_paths: [], method_level_threshold: 20) ⇒ Configuration
Returns a new instance of Configuration.
24 25 26 27 28 29 30 |
# File 'lib/kaisoku/configuration.rb', line 24 def initialize(project_root: Dir.pwd, map_path: nil, adapter: 'rspec', track_paths: [], method_level_threshold: 20) @project_root = File.(project_root) @map_path = map_path || File.join(@project_root, '.kaisoku', 'map.db') @adapter = adapter.to_s @track_paths = track_paths.map { |path| File.(path, @project_root) } @method_level_threshold = method_level_threshold.to_i end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
22 23 24 |
# File 'lib/kaisoku/configuration.rb', line 22 def adapter @adapter end |
#map_path ⇒ Object (readonly)
Returns the value of attribute map_path.
22 23 24 |
# File 'lib/kaisoku/configuration.rb', line 22 def map_path @map_path end |
#method_level_threshold ⇒ Object (readonly)
Returns the value of attribute method_level_threshold.
22 23 24 |
# File 'lib/kaisoku/configuration.rb', line 22 def method_level_threshold @method_level_threshold end |
#project_root ⇒ Object (readonly)
Returns the value of attribute project_root.
22 23 24 |
# File 'lib/kaisoku/configuration.rb', line 22 def project_root @project_root end |
#track_paths ⇒ Object (readonly)
Returns the value of attribute track_paths.
22 23 24 |
# File 'lib/kaisoku/configuration.rb', line 22 def track_paths @track_paths end |
Instance Method Details
#absolute_path(path) ⇒ Object
44 45 46 |
# File 'lib/kaisoku/configuration.rb', line 44 def absolute_path(path) File.(path, project_root) end |
#boot_impact_file?(path) ⇒ Boolean
55 56 57 58 |
# File 'lib/kaisoku/configuration.rb', line 55 def boot_impact_file?(path) relative = relative_path(path) DEFAULT_BOOT_GLOBS.any? { |pattern| File.fnmatch?(pattern, relative, File::FNM_PATHNAME) } end |
#invalidates_map?(path) ⇒ Boolean
60 61 62 |
# File 'lib/kaisoku/configuration.rb', line 60 def invalidates_map?(path) MAP_INVALIDATING_FILES.include?(relative_path(path)) end |
#project_file?(path) ⇒ Boolean
48 49 50 51 52 53 |
# File 'lib/kaisoku/configuration.rb', line 48 def project_file?(path) = File.(path) == project_root || .start_with?("#{project_root}#{File::SEPARATOR}") || track_paths.any? { |tracked| .start_with?("#{tracked}#{File::SEPARATOR}") } end |
#relative_path(path) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/kaisoku/configuration.rb', line 32 def relative_path(path) return path.to_s if path.to_s.start_with?('__') = File.(path, project_root) root = Pathname.new(project_root) target = Pathname.new() target.relative_path_from(root).to_s rescue ArgumentError path.to_s end |
#test_file?(path) ⇒ Boolean
64 65 66 67 |
# File 'lib/kaisoku/configuration.rb', line 64 def test_file?(path) relative = relative_path(path) relative.match?(%r{\A(spec/.+_spec|test/.+_test)\.rb\z}) end |