Skip to content

Commit

Permalink
rails: prefer Gemfile over .ruby-version (#4119)
Browse files Browse the repository at this point in the history
rails: prefer gemfile to `.ruby-version`
  • Loading branch information
alichay authored Dec 17, 2024
1 parent 82a8738 commit 339cefc
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions scanner/rails.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,22 @@ func configureRails(sourceDir string, config *ScannerConfig) (*SourceInfo, error

var rubyVersion string

// add ruby version from .ruby-version file
versionFile, err := os.ReadFile(".ruby-version")
// add ruby version from Gemfile
gemfile, err := os.ReadFile("Gemfile")
if err == nil {
re := regexp.MustCompile(`ruby-(\d+\.\d+\.\d+)`)
matches := re.FindStringSubmatch(string(versionFile))
re := regexp.MustCompile(`(?m)^ruby\s+["'](\d+\.\d+\.\d+)["']`)
matches := re.FindStringSubmatch(string(gemfile))
if len(matches) >= 2 {
rubyVersion = matches[1]
}
}

if rubyVersion == "" {
// add ruby version from Gemfile
gemfile, err := os.ReadFile("Gemfile")
// add ruby version from .ruby-version file
versionFile, err := os.ReadFile(".ruby-version")
if err == nil {
re := regexp.MustCompile(`(?m)^ruby\s+["'](\d+\.\d+\.\d+)["']`)
matches := re.FindStringSubmatch(string(gemfile))
re := regexp.MustCompile(`ruby-(\d+\.\d+\.\d+)`)
matches := re.FindStringSubmatch(string(versionFile))
if len(matches) >= 2 {
rubyVersion = matches[1]
}
Expand Down

0 comments on commit 339cefc

Please sign in to comment.