Class: Bruh::Cabal
Overview
Minimal Cabal file handler for version management
Instance Attribute Summary collapse
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #dependencies ⇒ Object
-
#initialize(file_path) ⇒ Cabal
constructor
A new instance of Cabal.
- #update_version(new_version) ⇒ Object
Constructor Details
#initialize(file_path) ⇒ Cabal
Returns a new instance of Cabal.
21 22 23 24 25 26 27 28 |
# File 'lib/bruh/cabal.rb', line 21 def initialize(file_path) @file_path = file_path @content = T.let(File.read(file_path), String) # Extract name and version with specific regexes @name = T.let(extract_field('name'), String) @version = T.let(extract_field('version'), String) end |
Instance Attribute Details
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
18 19 20 |
# File 'lib/bruh/cabal.rb', line 18 def file_path @file_path end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
15 16 17 |
# File 'lib/bruh/cabal.rb', line 15 def name @name end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
12 13 14 |
# File 'lib/bruh/cabal.rb', line 12 def version @version end |
Instance Method Details
#dependencies ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/bruh/cabal.rb', line 48 def dependencies # Extract all build-depends lines deps = [] @content.scan(/build-depends:.*?(?=\n\S|\Z)/m).each do |match| # Extract package names without version constraints match_str = T.cast(match, String) match_str.scan(/\b([a-zA-Z][a-zA-Z0-9-]*)[,\s<>=]/).each do |dep_arr| # dep_arr is an array where the first element is the capture group deps << dep_arr[0] end end deps.uniq end |
#update_version(new_version) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/bruh/cabal.rb', line 31 def update_version(new_version) # Update the version field in the file content updated_content = @content.sub(/^version:\s*[0-9.]+/, "version: #{new_version}") # Only write if something actually changed if updated_content != @content File.write(@file_path, updated_content) # These variables are already declared in initialize, so we don't use T.let again @content = updated_content @version = new_version end new_version end |