Class: Dependabot::Sbt::FileParser::PropertyValueFinder

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/dependabot/sbt/file_parser/property_value_finder.rb

Constant Summary collapse

VAL_DECLARATION_REGEX =

Matches: val someVersion = “1.2.3” Also: val someVersion: String = “1.2.3” Also: lazy val someVersion = “1.2.3”

T.let(
  /(?:^|\s)(?:lazy\s+)?val\s+(?<name>\w+)(?:\s*:\s*String)?\s*=\s*"(?<value>[^"]+)"/,
  Regexp
)

Instance Method Summary collapse

Constructor Details

#initialize(dependency_files:) ⇒ PropertyValueFinder

Returns a new instance of PropertyValueFinder.



23
24
25
26
# File 'lib/dependabot/sbt/file_parser/property_value_finder.rb', line 23

def initialize(dependency_files:)
  @dependency_files = T.let(dependency_files, T::Array[Dependabot::DependencyFile])
  @properties = T.let({}, T::Hash[String, T::Hash[String, T::Hash[Symbol, String]]])
end

Instance Method Details

#property_details(property_name:, callsite_buildfile:) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/dependabot/sbt/file_parser/property_value_finder.rb', line 32

def property_details(property_name:, callsite_buildfile:)
  # Handle dotted references like "V.scalafixVersion" by looking up the member name
  if property_name.include?(".")
    return dotted_property_details(property_name: property_name, callsite_buildfile: callsite_buildfile)
  end

  # Look in the callsite file first, then fall back to the root build.sbt,
  # then check project/*.scala build definition files
  all_files = [callsite_buildfile, top_level_buildfile].compact
  all_files += project_scala_files
  all_files.uniq!
  all_files.each do |file|
    details = properties(file).fetch(property_name, nil)
    return details if details
  end
  nil
end

#property_value(property_name:, callsite_buildfile:) ⇒ Object



51
52
53
54
55
56
# File 'lib/dependabot/sbt/file_parser/property_value_finder.rb', line 51

def property_value(property_name:, callsite_buildfile:)
  property_details(
    property_name: property_name,
    callsite_buildfile: callsite_buildfile
  )&.fetch(:value)
end