Class: Diffend::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/diffend/repository.rb

Overview

Repository for specs

Constant Summary collapse

REPOSITORIES_PATH =

Repositories path

File.join(
  File.expand_path('..', Bundler.bin_path),
  'repositories'
).freeze
SUPPORTED =

List of supported repositories split by command

{
  'install' => %w[
    with_gemfile_lock
    with_gemfile_lock_with_added_gem
    with_gemfile_lock_with_changed_gem_version
    with_gemfile_lock_with_locked_gem_version
    with_gemfile_lock_with_removed_gem
    with_gemfile_lock_with_two_platforms
    with_gemfile_lock_with_two_primary_sources
    with_gemfile_lock_with_two_sources
    without_gemfile_lock
  ].freeze,
  'update' => %w[
    with_gemfile_lock
    with_gemfile_lock_with_added_gem
    with_gemfile_lock_with_removed_gem
    with_gemfile_lock_with_two_primary_sources
    with_gemfile_lock_with_two_sources
    without_gemfile_lock
  ].freeze
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command, name) ⇒ Repository

Returns a new instance of Repository.

Parameters:

  • command (String)

    command executed via bundler

  • name (String)

    repository name



43
44
45
46
47
# File 'lib/diffend/repository.rb', line 43

def initialize(command, name)
  @command = command
  @name = name
  @path = File.join(Dir.tmpdir, SecureRandom.uuid)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



39
40
41
# File 'lib/diffend/repository.rb', line 39

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



39
40
41
# File 'lib/diffend/repository.rb', line 39

def path
  @path
end

Instance Method Details

#bundler_version_stringString

Build bundler version string

Returns:

  • (String)


105
106
107
# File 'lib/diffend/repository.rb', line 105

def bundler_version_string
  @bundler_version_string ||= "bundler_#{Bundler::VERSION.tr('.', '_')}"
end

#cleanObject

Clean isolated instance of a repository



67
68
69
# File 'lib/diffend/repository.rb', line 67

def clean
  FileUtils.rm_rf(path)
end

#file_path(file_name) ⇒ String

Build the path to a specified file within the repository

Parameters:

  • file_name (String)

Returns:

  • (String)


83
84
85
86
87
88
# File 'lib/diffend/repository.rb', line 83

def file_path(file_name)
  File.join(
    path,
    file_name
  )
end

#global_file_path(file_name) ⇒ String

Build global path

Parameters:

  • file_name (String)

Returns:

  • (String)


95
96
97
98
99
100
# File 'lib/diffend/repository.rb', line 95

def global_file_path(file_name)
  File.join(
    REPOSITORIES_PATH,
    file_name
  )
end

#isolate {|path| ... } ⇒ Object

Execute tasks in an isolated instance of a repository

Yields:



72
73
74
75
76
# File 'lib/diffend/repository.rb', line 72

def isolate
  setup
  yield(path)
  clean
end

#orig_pathString

Build repository path

Returns:

  • (String)


52
53
54
55
56
57
58
59
# File 'lib/diffend/repository.rb', line 52

def orig_path
  @orig_path ||= global_file_path(
    File.join(
      bundler_version_string,
      "#{@command}_#{name}"
    )
  )
end

#setupObject

Setup an isolated instance of a repository



62
63
64
# File 'lib/diffend/repository.rb', line 62

def setup
  FileUtils.cp_r(orig_path, path)
end