Class: GemMirror::Configuration

Inherits:
Confstruct::Configuration
  • Object
show all
Defined in:
lib/gem_mirror/configuration.rb

Overview

Configuration class used for storing data about a mirror such as the destination directory, sources, ignored Gems, etc.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.default_configuration_fileString

Returns:

  • (String)


39
40
41
# File 'lib/gem_mirror/configuration.rb', line 39

def self.default_configuration_file
  File.expand_path("config.rb", Dir.pwd)
end

.marshal_identifierString

Returns the name of the directory that contains the quick specification files.

Returns:

  • (String)


49
50
51
# File 'lib/gem_mirror/configuration.rb', line 49

def self.marshal_identifier
  "Marshal.#{marshal_version}"
end

.marshal_versionString

Returns a String containing the Marshal version.

Returns:

  • (String)


67
68
69
# File 'lib/gem_mirror/configuration.rb', line 67

def self.marshal_version
  "#{Marshal::MAJOR_VERSION}.#{Marshal::MINOR_VERSION}"
end

.template_directoryString

Returns:

  • (String)


32
33
34
# File 'lib/gem_mirror/configuration.rb', line 32

def self.template_directory
  File.expand_path("../../template", __dir__)
end

.versions_fileString

Returns the name of the file that contains an index of all the versions.

Returns:

  • (String)


58
59
60
# File 'lib/gem_mirror/configuration.rb', line 58

def self.versions_file
  "specs.#{marshal_version}.gz"
end

Instance Method Details

#gems_directoryString

Returns:

  • (String)


81
82
83
# File 'lib/gem_mirror/configuration.rb', line 81

def gems_directory
  File.join(destination, "gems")
end

#ignore_gem(name, version) ⇒ Object

Adds a Gem to the list of Gems to ignore.

Parameters:

  • name (String)
  • version (String)


100
101
102
103
# File 'lib/gem_mirror/configuration.rb', line 100

def ignore_gem(name, version)
  ignored_gems[name] ||= []
  ignored_gems[name] << version
end

#ignore_gem?(name, version) ⇒ TrueClass|FalseClass

Checks if a Gem should be ignored.

Parameters:

  • name (String)
  • version (String)

Returns:

  • (TrueClass|FalseClass)


112
113
114
# File 'lib/gem_mirror/configuration.rb', line 112

def ignore_gem?(name, version)
  ignored_gems[name].include?(version)
end

#ignored_gemsHash

Returns a Hash containing various Gems to ignore and their versions.

Returns:

  • (Hash)


90
91
92
# File 'lib/gem_mirror/configuration.rb', line 90

def ignored_gems
  @ignored_gems ||= Hash.new { |hash, key| hash[key] = [] }
end

#loggerLogger

Returns:

  • (Logger)


20
21
22
23
24
25
26
27
# File 'lib/gem_mirror/configuration.rb', line 20

def logger
  @logger = Logger.new($stdout,
                       progname: "gem_mirror",
                       formatter: proc do |severity, datetime, progname, msg|
                         d_format = datetime.strftime("%Y%m%dT%H%M%S%z")
                         "[#{d_format}] severity=#{severity} prog=#{progname} pid=#{Process.pid} message=#{msg}\n"
                       end)
end

#mirror_directoryGemMirror::MirrorDirectory



74
75
76
# File 'lib/gem_mirror/configuration.rb', line 74

def mirror_directory
  @mirror_directory ||= MirrorDirectory.new(gems_directory)
end

#source(name, url, &block) {|source| ... } ⇒ Object

Adds a new source to mirror.

Parameters:

  • name (String)
  • url (String)
  • block (Proc)

Yield Parameters:



133
134
135
136
137
138
# File 'lib/gem_mirror/configuration.rb', line 133

def source(name, url, &block)
  source = Source.new(name, url)
  source.instance_eval(&block)

  sources << source
end

#sourcesArray

Returns a list of sources to mirror.

Returns:

  • (Array)


121
122
123
# File 'lib/gem_mirror/configuration.rb', line 121

def sources
  @sources ||= []
end