Class: RSpecTracer::Tracker::Input Private

Inherits:
Struct
  • Object
show all
Defined in:
lib/rspec_tracer/tracker/input.rb,
lib/rspec_tracer/tracker/input.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Internal Input — see RSpecTracer for the user-facing surface.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#digestObject

Returns the value of attribute digest

Returns:

  • (Object)

    the current value of digest



41
42
43
# File 'lib/rspec_tracer/tracker/input.rb', line 41

def digest
  @digest
end

#identityObject

Returns the value of attribute identity

Returns:

  • (Object)

    the current value of identity



41
42
43
# File 'lib/rspec_tracer/tracker/input.rb', line 41

def identity
  @identity
end

#kindObject

Returns the value of attribute kind

Returns:

  • (Object)

    the current value of kind



41
42
43
# File 'lib/rspec_tracer/tracker/input.rb', line 41

def kind
  @kind
end

#pathObject

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



41
42
43
# File 'lib/rspec_tracer/tracker/input.rb', line 41

def path
  @path
end

Class Method Details

.for_file(path:, kind:, digest:, root:) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Internal helper for the tracer pipeline.



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/rspec_tracer/tracker/input.rb', line 48

def self.for_file(path:, kind:, digest:, root:)
  unless ALLOWED_INPUT_KINDS.include?(kind)
    raise ArgumentError,
          "invalid Input kind: #{kind.inspect}; " \
          "allowed: #{ALLOWED_INPUT_KINDS.to_a.inspect}"
  end

  abs_path = File.expand_path(path)
  identity = "#{kind}:#{relative_path(abs_path, root)}"

  new(path: abs_path, kind: kind, digest: digest, identity: identity).freeze
end

.relative_path(abs_path, root) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Strip ‘root/` prefix from an absolute path. When the path escapes the root (absolute symlink target, vendored gem under a different tree, etc.) we fall back to the full absolute path so identity stays unique - the deterministic rule is “same path under same root => same identity”, nothing stronger.



66
67
68
69
70
71
72
73
# File 'lib/rspec_tracer/tracker/input.rb', line 66

def self.relative_path(abs_path, root)
  root_abs = File.expand_path(root)
  prefix = "#{root_abs}/"

  return abs_path unless abs_path.start_with?(prefix)

  abs_path[prefix.length..]
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Inputs are value-typed and not meant to be subclassed; ‘instance_of?` is precise where `is_a?` would let a subclass with matching identity compare equal.



86
87
88
# File 'lib/rspec_tracer/tracker/input.rb', line 86

def ==(other)
  other.instance_of?(self.class) && identity == other.identity
end

#hashObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Internal method on the tracer pipeline.



94
95
96
# File 'lib/rspec_tracer/tracker/input.rb', line 94

def hash
  identity.hash
end

#stale?(current_digest) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

‘!=` handles every case correctly: nil-vs-nil is NOT stale (absent stayed absent), present-vs-nil and nil-vs-present are stale (file appeared/disappeared), and digest-vs-digest is stale iff the content changed.

Returns:

  • (Boolean)


79
80
81
# File 'lib/rspec_tracer/tracker/input.rb', line 79

def stale?(current_digest)
  current_digest != digest
end