Sha256: 841a6f45331a79f78c76a6ca15cdec9bd145907eefbac0c4a2663c39c4fbb4a1

Contents?: true

Size: 1.72 KB

Versions: 8

Compression:

Stored size: 1.72 KB

Contents

require_relative 'platform'

module LicenseFinder
  class Configuration
    def self.with_optional_saved_config(primary_config)
      project_path = Pathname(primary_config.fetch(:project_path, Pathname.pwd)).expand_path
      config_file =  project_path.join('config', 'license_finder.yml')
      saved_config = config_file.exist? ? YAML.load(config_file.read) : {}
      new(primary_config, saved_config)
    end

    def initialize(primary_config, saved_config)
      @primary_config = primary_config
      @saved_config = saved_config
    end

    def valid_project_path?
      if get(:project_path)
        return project_path.exist?
      end
      true
    end

    def gradle_command
      get(:gradle_command) || (
        if Platform.windows?
          wrapper = 'gradlew.bat'
          gradle = 'gradle.bat'
        else
          wrapper = 'gradlew'
          gradle = 'gradle'
        end

        executable = File.exist?(wrapper) ? wrapper : gradle
        "#{executable} --console plain"
      )
    end

    def go_full_version
      get(:go_full_version)
    end

    def gradle_include_groups
      get(:gradle_include_groups)
    end

    def rebar_command
      get(:rebar_command) || 'rebar'
    end

    def rebar_deps_dir
      path = get(:rebar_deps_dir) || 'deps'
      project_path.join(path).expand_path
    end

    def decisions_file_path
      path = get(:decisions_file) || 'doc/dependency_decisions.yml'
      project_path.join(path).expand_path
    end

    def project_path
      Pathname(path_prefix).expand_path
    end

    private

    attr_reader :saved_config

    def get(key)
      @primary_config[key.to_sym] || @saved_config[key.to_s]
    end

    def path_prefix
      get(:project_path) || ''
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
license_finder-2.1.2 lib/license_finder/configuration.rb
license_finder-2.1.1 lib/license_finder/configuration.rb
license_finder-2.1.0 lib/license_finder/configuration.rb
license_finder-2.1.0.rc9 lib/license_finder/configuration.rb
license_finder-2.1.0.rc8 lib/license_finder/configuration.rb
license_finder-2.1.0.rc7 lib/license_finder/configuration.rb
license_finder-2.1.0.rc6 lib/license_finder/configuration.rb
license_finder-2.1.0.rc5 lib/license_finder/configuration.rb