Skip to content

Commit

Permalink
correct ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
microsoftly committed Sep 10, 2018
1 parent c46eba5 commit 6a8dd6f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
37 changes: 25 additions & 12 deletions analyzers/ruby/ruby.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@ func (a *Analyzer) IsBuilt() (bool, error) {
}

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

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

lockfilePath := a.getLockfilePath()
lockfilePath := a.lockfilePath()

switch strategy {
case "list":
Expand All @@ -143,14 +143,29 @@ func (a *Analyzer) Analyze() (graph.Deps, error) {
case "list-lockfile":
fallthrough
default:
return a.defaultAnalyzerStrategy(lockfilePath)
lockfile, err := bundler.FromLockfile(lockfilePath)
if err != nil {
return a.lockfileAnalyzerStrategy(lockfilePath)
}

gems, err := a.Bundler.List()
if err != nil {
return graph.Deps{}, err
}

imports, deps := FilteredLockfile(gems, lockfile)

return graph.Deps{
Direct: imports,
Transitive: deps,
}, nil
}
}

func (a *Analyzer) bundlerListAnalyzerStrategy() (graph.Deps, error) {
gems, err := a.Bundler.List()
if err != nil {
lockfilePath := a.getLockfilePath()
lockfilePath := a.lockfilePath()

return a.lockfileAnalyzerStrategy(lockfilePath)
}
Expand All @@ -166,7 +181,7 @@ func (a *Analyzer) bundlerListAnalyzerStrategy() (graph.Deps, error) {
func (a *Analyzer) lockfileAnalyzerStrategy(lockfilePath string) (graph.Deps, error) {
lockfile, err := bundler.FromLockfile(lockfilePath)
if err != nil {
return a.defaultAnalyzerStrategy(lockfilePath)
return a.bundlerListAnalyzerStrategy()
}

imports, deps := FromLockfile(lockfile)
Expand All @@ -177,9 +192,10 @@ func (a *Analyzer) lockfileAnalyzerStrategy(lockfilePath string) (graph.Deps, er
}, nil
}

func (a *Analyzer) defaultAnalyzerStrategy(lockfilePath string) (graph.Deps, error) {
func (a *Analyzer) listLockfileAnalyzerStrategy(lockfilePath string) (graph.Deps, error) {
lockfile, err := bundler.FromLockfile(lockfilePath)
if err != nil {

return graph.Deps{}, err
}

Expand All @@ -196,12 +212,9 @@ func (a *Analyzer) defaultAnalyzerStrategy(lockfilePath string) (graph.Deps, err
}, nil
}

func (a *Analyzer) getLockfilePath() string {
lockfilePath := filepath.Join(a.Module.Dir, "Gemfile.lock")

func (a *Analyzer) lockfilePath() string {
if a.Options.LockfilePath != "" {
lockfilePath = a.Options.LockfilePath
return a.Options.LockfilePath
}

return lockfilePath
return filepath.Join(a.Module.Dir, "Gemfile.lock")
}
3 changes: 1 addition & 2 deletions analyzers/ruby/ruby_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import (
"path/filepath"
"testing"

"github.com/fossas/fossa-cli/buildtools/bundler"

"github.com/stretchr/testify/assert"

"github.com/fossas/fossa-cli/analyzers/ruby"
"github.com/fossas/fossa-cli/buildtools/bundler"
"github.com/fossas/fossa-cli/module"
"github.com/fossas/fossa-cli/pkg"
)
Expand Down

0 comments on commit 6a8dd6f

Please sign in to comment.