Class: Kaisoku::Configuration

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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.expand_path(project_root)
  @map_path = map_path || File.join(@project_root, '.kaisoku', 'map.db')
  @adapter = adapter.to_s
  @track_paths = track_paths.map { |path| File.expand_path(path, @project_root) }
  @method_level_threshold = method_level_threshold.to_i
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



22
23
24
# File 'lib/kaisoku/configuration.rb', line 22

def adapter
  @adapter
end

#map_pathObject (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_thresholdObject (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_rootObject (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_pathsObject (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.expand_path(path, project_root)
end

#boot_impact_file?(path) ⇒ Boolean

Returns:

  • (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

Returns:

  • (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

Returns:

  • (Boolean)


48
49
50
51
52
53
# File 'lib/kaisoku/configuration.rb', line 48

def project_file?(path)
  expanded = File.expand_path(path)
  expanded == project_root ||
    expanded.start_with?("#{project_root}#{File::SEPARATOR}") ||
    track_paths.any? { |tracked| expanded.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?('__')

  expanded = File.expand_path(path, project_root)
  root = Pathname.new(project_root)
  target = Pathname.new(expanded)

  target.relative_path_from(root).to_s
rescue ArgumentError
  path.to_s
end

#test_file?(path) ⇒ Boolean

Returns:

  • (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