Class: Diffend::Voting::Versions::Local

Inherits:
Object
  • Object
show all
Defined in:
lib/diffend/voting/versions/local.rb

Overview

Module responsible for preparing current or current/new versions of gems

Constant Summary collapse

ME_PATH =

Definition of a local path, if it matches it means that we are the source

'.'
ME_SOURCES =

Sources that we expect to match ourselves too

[
  Bundler::Source::Gemspec,
  Bundler::Source::Path
].freeze
DEPENDENCIES =
{
  direct: 0,
  dep: 1
}.freeze
SOURCES =
{
  valid: 0,
  multiple_primary: 1
}.freeze
GEM_SOURCES =
{
  local: 0,
  gemfile: 1
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(definition) ⇒ Hash

Returns local dependencies.

Parameters:

  • definition (Bundler::Definition)

    definition for your source



49
50
51
52
53
54
55
# File 'lib/diffend/voting/versions/local.rb', line 49

def initialize(definition)
  @definition = definition
  @direct_dependencies = Hash[definition.dependencies.map { |val| [val.name, val] }]
  @main_source = definition.send(:sources).rubygems_sources.last
  # Support case without Gemfile.lock
  @locked_specs = @definition.locked_gems ? @definition.locked_gems.specs : []
end

Class Method Details

.call(command, definition) ⇒ Object

Parameters:

  • command (String)

    either install or update

  • definition (Bundler::Definition)

    definition for your source



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/diffend/voting/versions/local.rb', line 32

def call(command, definition)
  Bundler.ui.silence { definition.resolve_remotely! }

  instance = new(definition)

  case command
  when Commands::INSTALL then instance.build_install
  when Commands::UPDATE then instance.build_update
  else
    raise ArgumentError, "invalid command: #{command}"
  end
end

Instance Method Details

#build_installObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/diffend/voting/versions/local.rb', line 57

def build_install
  hash = build_main

  @definition.requested_specs.each do |spec|
    next if skip?(spec.source)

    locked_spec = @locked_specs.find { |s| s.name == spec.name }

    spec2 = locked_spec || spec

    hash['dependencies'][spec2.name] = {
      'platform' => build_spec_platform(spec2),
      'source' => build_spec_source(spec2),
      'type' => build_dependency_type(spec2.name),
      'versions' => build_versions(spec2)
    }
  end

  hash
end

#build_updateObject

Parameters:

  • definition (Bundler::Definition)

    definition for your source



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/diffend/voting/versions/local.rb', line 79

def build_update
  hash = build_main

  @definition.requested_specs.each do |spec|
    next if skip?(spec.source)

    locked_spec = @locked_specs.find { |s| s.name == spec.name }

    hash['dependencies'][spec.name] = {
      'platform' => build_spec_platform(spec),
      'source' => build_spec_source(spec),
      'type' => build_dependency_type(spec.name),
      'versions' => build_versions(spec, locked_spec)
    }
  end

  hash
end