Skip to content

Commit

Permalink
remove shouldFallback
Browse files Browse the repository at this point in the history
  • Loading branch information
microsoftly committed Sep 11, 2018
1 parent 000d93d commit a1bcdc9
Showing 1 changed file with 29 additions and 27 deletions.
56 changes: 29 additions & 27 deletions analyzers/ruby/ruby.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,10 @@ func (a *Analyzer) IsBuilt() (bool, error) {
}

func (a *Analyzer) Analyze() (graph.Deps, error) {
shouldFallback := true
strategy := "list-lockfile"

if a.Options.Strategy != "" {
strategy = a.Options.Strategy
shouldFallback = false
}

lockfilePath := a.lockfilePath()
Expand All @@ -145,41 +143,45 @@ func (a *Analyzer) Analyze() (graph.Deps, error) {
case "list-lockfile":
fallthrough
default:
lockfile, err := bundler.FromLockfile(lockfilePath)
if err != nil {
if !shouldFallback {
return graph.Deps{}, err
}
return a.bundlerListLockfileAnalyzerStrategy(lockfilePath)
}
}

return a.lockfileAnalyzerStrategy(lockfilePath)
func (a *Analyzer) bundlerListLockfileAnalyzerStrategy(lockfilePath string) (graph.Deps, error) {
lockfile, err := bundler.FromLockfile(lockfilePath)
if err != nil {
if a.Options.Strategy != "" {
return graph.Deps{}, err
}

gems, err := a.Bundler.List()
if err == nil {
imports, deps := FilteredLockfile(gems, lockfile)
return a.lockfileAnalyzerStrategy(lockfilePath)
}

return graph.Deps{
Direct: imports,
Transitive: deps,
}, nil
}
gems, err := a.Bundler.List()
if err == nil {
imports, deps := FilteredLockfile(gems, lockfile)

if !shouldFallback {
return graph.Deps{}, err
}
return graph.Deps{
Direct: imports,
Transitive: deps,
}, nil
}

deps, err := a.lockfileAnalyzerStrategy(lockfilePath)
if a.Options.Strategy != "" {
return graph.Deps{}, err
}

if err == nil {
return deps, err
}
deps, err := a.lockfileAnalyzerStrategy(lockfilePath)

if !shouldFallback {
return graph.Deps{}, err
}
if err == nil {
return deps, err
}

return a.bundlerListAnalyzerStrategy()
if a.Options.Strategy != "" {
return graph.Deps{}, err
}

return a.bundlerListAnalyzerStrategy()
}

func (a *Analyzer) bundlerListAnalyzerStrategy() (graph.Deps, error) {
Expand Down

0 comments on commit a1bcdc9

Please sign in to comment.