Class: Dependabot::Nix::FlakeNixParser
- Inherits:
-
Object
- Object
- Dependabot::Nix::FlakeNixParser
- Extended by:
- T::Sig
- Defined in:
- lib/dependabot/nix/flake_nix_parser.rb
Overview
Parses flake.nix content to locate input URL declarations and extract their components (scheme, owner, repo, ref). Only handles the shorthand URL schemes (github:, gitlab:, sourcehut:) since those are the ones where the ref appears inline in the URL string.
Defined Under Namespace
Classes: InputUrl
Class Method Summary collapse
- .find_input_url(content, input_name) ⇒ Object
- .update_input_ref(content, input_name, new_ref) ⇒ Object
Instance Method Summary collapse
- #find ⇒ Object
-
#initialize(content, input_name) ⇒ FlakeNixParser
constructor
A new instance of FlakeNixParser.
- #update_ref(new_ref) ⇒ Object
Constructor Details
#initialize(content, input_name) ⇒ FlakeNixParser
Returns a new instance of FlakeNixParser.
55 56 57 58 |
# File 'lib/dependabot/nix/flake_nix_parser.rb', line 55 def initialize(content, input_name) @content = content @input_name = input_name end |
Class Method Details
.find_input_url(content, input_name) ⇒ Object
45 46 47 |
# File 'lib/dependabot/nix/flake_nix_parser.rb', line 45 def self.find_input_url(content, input_name) new(content, input_name).find end |
.update_input_ref(content, input_name, new_ref) ⇒ Object
50 51 52 |
# File 'lib/dependabot/nix/flake_nix_parser.rb', line 50 def self.update_input_ref(content, input_name, new_ref) new(content, input_name).update_ref(new_ref) end |
Instance Method Details
#find ⇒ Object
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/dependabot/nix/flake_nix_parser.rb', line 61 def find match = find_url_match return unless match url_str = match[:url] build_shorthand_input(url_str, match) || build_tarball_input(url_str, match) || build_indirect_input(url_str, match) end |
#update_ref(new_ref) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/dependabot/nix/flake_nix_parser.rb', line 73 def update_ref(new_ref) input_url = find return unless input_url return unless input_url.ref # nothing to update if no ref old_url = input_url.full_url new_url = build_updated_url(input_url, new_ref) updated = @content.dup # Replace within the known match boundaries to avoid accidental matches elsewhere updated[input_url.match_start...input_url.match_end] = T.must(updated[input_url.match_start...input_url.match_end]).sub(old_url, new_url) updated end |