Class: Gembuild::Pkgbuild

Inherits:
Object
  • Object
show all
Defined in:
lib/gembuild/pkgbuild.rb

Overview

Class used to create a PKGBUILD file for a rubygem.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gemname, existing_pkgbuild = nil) ⇒ Gembuild::Pkgbuild

Create a new Pkgbuild instance.

Parameters:

  • gemname (String)

    The rubygem for which to create a PKGBUILD.

  • existing_pkgbuild (nil, String) (defaults to: nil)

    An old PKGBUILD that can be parsed for maintainer and contributor information.

Raises:


93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/gembuild/pkgbuild.rb', line 93

def initialize(gemname, existing_pkgbuild = nil)
  unless existing_pkgbuild.nil? || existing_pkgbuild.is_a?(String)
    fail Gembuild::InvalidPkgbuildError
  end

  @gemname = gemname
  @pkgname = "ruby-#{@gemname}"

  set_package_defaults

  no_parse_pkgbuild = existing_pkgbuild.nil? || existing_pkgbuild.empty?
  parse_existing_pkgbuild(existing_pkgbuild) unless no_parse_pkgbuild
end

Instance Attribute Details

#archArray

Returns the supported architectures.

Returns:

  • (Array)

    the supported architectures

See Also:


78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/gembuild/pkgbuild.rb', line 78

class Pkgbuild
  attr_accessor :arch, :checksum, :checksum_type, :contributor, :depends,
                :description, :epoch, :gemname, :license, :maintainer,
                :makedepends, :noextract, :options, :pkgname, :pkgrel,
                :pkgver, :source, :url

  # Create a new Pkgbuild instance.
  #
  # @raise [Gembuild::InvalidPkgbuildError] if something other than a
  #   string or nil is passed as the existing pkgbuild
  #
  # @param gemname [String] The rubygem for which to create a PKGBUILD.
  # @param existing_pkgbuild [nil, String] An old PKGBUILD that can be
  #   parsed for maintainer and contributor information.
  # @return [Gembuild::Pkgbuild] a new Pkgbuild instance
  def initialize(gemname, existing_pkgbuild = nil)
    unless existing_pkgbuild.nil? || existing_pkgbuild.is_a?(String)
      fail Gembuild::InvalidPkgbuildError
    end

    @gemname = gemname
    @pkgname = "ruby-#{@gemname}"

    set_package_defaults

    no_parse_pkgbuild = existing_pkgbuild.nil? || existing_pkgbuild.empty?
    parse_existing_pkgbuild(existing_pkgbuild) unless no_parse_pkgbuild
  end

  # Parse the old pkgbuild (if it exists) to get information about old
  # maintainers or contributors or about other dependencies that have been
  # added but that can not be scraped from rubygems.org.
  #
  # @param pkgbuild [String] The old PKGBUILD to parse.
  # @return [Hash] a hash containing the values scraped from the PKGBUILD
  def parse_existing_pkgbuild(pkgbuild)
    pkgbuild.match(/^# Maintainer: (.*)$/) { |m| @maintainer = m[1] }

    @contributor = pkgbuild.scan(/^# Contributor: (.*)$/).flatten

    deps = parse_existing_dependencies(pkgbuild)
    deps.each do |dep|
      @depends << dep
    end

    { maintainer: maintainer, contributor: contributor, depends: deps }
  end

  # Create a new Pkgbuild instance with all information from the scraped
  # sources assigned.
  #
  # @param gemname [String] The rubygem for which to create a Pkgbuild.
  # @param existing_pkgbuild [String, nil] An old PKGBUILD that can be
  #   parsed for maintainer information.
  # @return [Gembuild::Pkgbuild] a new Pkgbuild instance
  def self.create(gemname, existing_pkgbuild = nil)
    pkgbuild = Pkgbuild.new(gemname, existing_pkgbuild)

    pkgbuild.fetch_maintainer

    gem_details = Gembuild::GemScraper.new(gemname).scrape!
    aur_details = Gembuild::AurScraper.new(pkgbuild.pkgname).scrape!

    pkgbuild.assign_gem_details(gem_details)
    pkgbuild.assign_aur_details(aur_details)

    pkgbuild
  end

  # Generate a PKGBUILD from the class using the pkgbuild erb template.
  #
  # @return [String] the PKGBUILD
  def render
    ERB.new(template, 0, '-').result(binding)
  end

  # Get the PKGBUILD erb template.
  #
  # @return [String] the pkgbuild erb template
  def template
    File.read(File.join(File.dirname(__FILE__), 'pkgbuild.erb'))
  end

  # Write the PKGBUILD to disk.
  #
  # @param path [String] The directory to write the PKGBUILD.
  # @return [Fixnum] the number of bytes written
  def write(path = '')
    File.write(File.join(File.expand_path(path), 'PKGBUILD'), render)
  end

  # Obfuscate the maintainer/contributors' email addresses to (help to)
  # prevent spam.
  #
  # @param contact_information [String] The maintainer or contributor
  #   byline.
  # @return [String] the information with the @s and .s exchanged
  def format_contact_information(contact_information)
    contact_information.gsub('@', ' at ').gsub('.', ' dot ')
  end

  # Set the correct maintainer for the PKGBUILD.
  #
  # If the current maintainer is nil (no old pkgbuild was passed), then do
  # nothing. If there is a maintainer then compare it to the configured
  # maintainer and if they are different then make the old maintainer a
  # contributor before setting the correct maintainer. If the maintainer is
  # nil then just set the confgured maintainer.
  #
  # @return [String] the pkgbuild maintainer
  def fetch_maintainer
    configured_maintainer = Gembuild.configure
    m = "#{configured_maintainer[:name]} <#{configured_maintainer[:email]}>"
    new_maintainer = format_contact_information(m)

    unless maintainer.nil? || new_maintainer == maintainer
      @contributor.unshift(maintainer)
    end

    @maintainer = new_maintainer
  end

  # Add the data scraped from rubygems.org to the pkgbuild.
  #
  # @param details [Hash] The results from GemScraper scrape.
  # @return [void]
  def assign_gem_details(details)
    @pkgver = details.fetch(:version)
    @description = details.fetch(:description)
    @checksum = details.fetch(:checksum)
    @license = details.fetch(:license)
    @url = details.fetch(:homepage)

    details.fetch(:dependencies).each do |dependency|
      @depends << "ruby-#{dependency}"
    end
  end

  # Assign version information based on the information gathered from the
  # AUR.
  #
  # @param details [Hash, nil] The results from AurScraper scrape or nil if
  #   the package does not yet exist on the AUR.
  # @return [void]
  def assign_aur_details(details)
    if details.nil?
      @epoch = 0
      @pkgrel = 1
    else
      perform_version_reconciliation(details)
    end
  end

  private

  # Set the static variables of a new pkgbuild.
  #
  # @return [nil]
  def set_package_defaults
    @checksum_type = 'sha256'
    @arch = ['any']
    @makedepends = ['rubygems']
    @depends = ['ruby']
    @source = ['https://rubygems.org/downloads/$_gemname-$pkgver.gem']
    @noextract = ['$_gemname-$pkgver.gem']
    @options = ['!emptydirs']
    @contributor = []

    nil
  end

  # Scrape dependencies from an existing pkgbuild.
  #
  # @param pkgbuild [String] The PKGBUILD to search.
  # @return [Array] all existing dependencies that are not ruby or gems
  def parse_existing_dependencies(pkgbuild)
    match = pkgbuild.match(/^depends=\((.*?)\)$/m)[1]

    # First step is to remove the leading and trailing quotes. Then convert
    # all whitespace (newlines, tabs, multiple spaces, etc.) to single
    # spaces. Then, make sure that strings are quoted with ' not ".
    # Finally, split the packages into an array.
    deps = match[1..-2].gsub(/[[:space:]]+/, ' ').tr('"', "'").split("' '")

    deps.reject { |e| e.match(/^ruby/) }
  rescue
    []
  end

  # Assign the correct pkgrel and epoch depending on the current pkgver on
  # the AUR and the version of the gem from rubygems.org.
  #
  # @param details [Hash] The results from AurScraper scrape
  # @return [void]
  def perform_version_reconciliation(details)
    @epoch = details.fetch(:epoch)
    @pkgrel = 1

    if pkgver < details.fetch(:pkgver)
      @epoch += 1
    elsif @pkgver == details.fetch(:pkgver)
      @pkgrel = details.fetch(:pkgrel) + 1
    end
  end
end

#checksumString

Returns the sha256 sum of the gemfile.

Returns:

  • (String)

    the sha256 sum of the gemfile

See Also:


78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/gembuild/pkgbuild.rb', line 78

class Pkgbuild
  attr_accessor :arch, :checksum, :checksum_type, :contributor, :depends,
                :description, :epoch, :gemname, :license, :maintainer,
                :makedepends, :noextract, :options, :pkgname, :pkgrel,
                :pkgver, :source, :url

  # Create a new Pkgbuild instance.
  #
  # @raise [Gembuild::InvalidPkgbuildError] if something other than a
  #   string or nil is passed as the existing pkgbuild
  #
  # @param gemname [String] The rubygem for which to create a PKGBUILD.
  # @param existing_pkgbuild [nil, String] An old PKGBUILD that can be
  #   parsed for maintainer and contributor information.
  # @return [Gembuild::Pkgbuild] a new Pkgbuild instance
  def initialize(gemname, existing_pkgbuild = nil)
    unless existing_pkgbuild.nil? || existing_pkgbuild.is_a?(String)
      fail Gembuild::InvalidPkgbuildError
    end

    @gemname = gemname
    @pkgname = "ruby-#{@gemname}"

    set_package_defaults

    no_parse_pkgbuild = existing_pkgbuild.nil? || existing_pkgbuild.empty?
    parse_existing_pkgbuild(existing_pkgbuild) unless no_parse_pkgbuild
  end

  # Parse the old pkgbuild (if it exists) to get information about old
  # maintainers or contributors or about other dependencies that have been
  # added but that can not be scraped from rubygems.org.
  #
  # @param pkgbuild [String] The old PKGBUILD to parse.
  # @return [Hash] a hash containing the values scraped from the PKGBUILD
  def parse_existing_pkgbuild(pkgbuild)
    pkgbuild.match(/^# Maintainer: (.*)$/) { |m| @maintainer = m[1] }

    @contributor = pkgbuild.scan(/^# Contributor: (.*)$/).flatten

    deps = parse_existing_dependencies(pkgbuild)
    deps.each do |dep|
      @depends << dep
    end

    { maintainer: maintainer, contributor: contributor, depends: deps }
  end

  # Create a new Pkgbuild instance with all information from the scraped
  # sources assigned.
  #
  # @param gemname [String] The rubygem for which to create a Pkgbuild.
  # @param existing_pkgbuild [String, nil] An old PKGBUILD that can be
  #   parsed for maintainer information.
  # @return [Gembuild::Pkgbuild] a new Pkgbuild instance
  def self.create(gemname, existing_pkgbuild = nil)
    pkgbuild = Pkgbuild.new(gemname, existing_pkgbuild)

    pkgbuild.fetch_maintainer

    gem_details = Gembuild::GemScraper.new(gemname).scrape!
    aur_details = Gembuild::AurScraper.new(pkgbuild.pkgname).scrape!

    pkgbuild.assign_gem_details(gem_details)
    pkgbuild.assign_aur_details(aur_details)

    pkgbuild
  end

  # Generate a PKGBUILD from the class using the pkgbuild erb template.
  #
  # @return [String] the PKGBUILD
  def render
    ERB.new(template, 0, '-').result(binding)
  end

  # Get the PKGBUILD erb template.
  #
  # @return [String] the pkgbuild erb template
  def template
    File.read(File.join(File.dirname(__FILE__), 'pkgbuild.erb'))
  end

  # Write the PKGBUILD to disk.
  #
  # @param path [String] The directory to write the PKGBUILD.
  # @return [Fixnum] the number of bytes written
  def write(path = '')
    File.write(File.join(File.expand_path(path), 'PKGBUILD'), render)
  end

  # Obfuscate the maintainer/contributors' email addresses to (help to)
  # prevent spam.
  #
  # @param contact_information [String] The maintainer or contributor
  #   byline.
  # @return [String] the information with the @s and .s exchanged
  def format_contact_information(contact_information)
    contact_information.gsub('@', ' at ').gsub('.', ' dot ')
  end

  # Set the correct maintainer for the PKGBUILD.
  #
  # If the current maintainer is nil (no old pkgbuild was passed), then do
  # nothing. If there is a maintainer then compare it to the configured
  # maintainer and if they are different then make the old maintainer a
  # contributor before setting the correct maintainer. If the maintainer is
  # nil then just set the confgured maintainer.
  #
  # @return [String] the pkgbuild maintainer
  def fetch_maintainer
    configured_maintainer = Gembuild.configure
    m = "#{configured_maintainer[:name]} <#{configured_maintainer[:email]}>"
    new_maintainer = format_contact_information(m)

    unless maintainer.nil? || new_maintainer == maintainer
      @contributor.unshift(maintainer)
    end

    @maintainer = new_maintainer
  end

  # Add the data scraped from rubygems.org to the pkgbuild.
  #
  # @param details [Hash] The results from GemScraper scrape.
  # @return [void]
  def assign_gem_details(details)
    @pkgver = details.fetch(:version)
    @description = details.fetch(:description)
    @checksum = details.fetch(:checksum)
    @license = details.fetch(:license)
    @url = details.fetch(:homepage)

    details.fetch(:dependencies).each do |dependency|
      @depends << "ruby-#{dependency}"
    end
  end

  # Assign version information based on the information gathered from the
  # AUR.
  #
  # @param details [Hash, nil] The results from AurScraper scrape or nil if
  #   the package does not yet exist on the AUR.
  # @return [void]
  def assign_aur_details(details)
    if details.nil?
      @epoch = 0
      @pkgrel = 1
    else
      perform_version_reconciliation(details)
    end
  end

  private

  # Set the static variables of a new pkgbuild.
  #
  # @return [nil]
  def set_package_defaults
    @checksum_type = 'sha256'
    @arch = ['any']
    @makedepends = ['rubygems']
    @depends = ['ruby']
    @source = ['https://rubygems.org/downloads/$_gemname-$pkgver.gem']
    @noextract = ['$_gemname-$pkgver.gem']
    @options = ['!emptydirs']
    @contributor = []

    nil
  end

  # Scrape dependencies from an existing pkgbuild.
  #
  # @param pkgbuild [String] The PKGBUILD to search.
  # @return [Array] all existing dependencies that are not ruby or gems
  def parse_existing_dependencies(pkgbuild)
    match = pkgbuild.match(/^depends=\((.*?)\)$/m)[1]

    # First step is to remove the leading and trailing quotes. Then convert
    # all whitespace (newlines, tabs, multiple spaces, etc.) to single
    # spaces. Then, make sure that strings are quoted with ' not ".
    # Finally, split the packages into an array.
    deps = match[1..-2].gsub(/[[:space:]]+/, ' ').tr('"', "'").split("' '")

    deps.reject { |e| e.match(/^ruby/) }
  rescue
    []
  end

  # Assign the correct pkgrel and epoch depending on the current pkgver on
  # the AUR and the version of the gem from rubygems.org.
  #
  # @param details [Hash] The results from AurScraper scrape
  # @return [void]
  def perform_version_reconciliation(details)
    @epoch = details.fetch(:epoch)
    @pkgrel = 1

    if pkgver < details.fetch(:pkgver)
      @epoch += 1
    elsif @pkgver == details.fetch(:pkgver)
      @pkgrel = details.fetch(:pkgrel) + 1
    end
  end
end

#checksum_typeString

Returns the type of checksum (will always be sha256).

Returns:

  • (String)

    the type of checksum (will always be sha256)

See Also:


78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/gembuild/pkgbuild.rb', line 78

class Pkgbuild
  attr_accessor :arch, :checksum, :checksum_type, :contributor, :depends,
                :description, :epoch, :gemname, :license, :maintainer,
                :makedepends, :noextract, :options, :pkgname, :pkgrel,
                :pkgver, :source, :url

  # Create a new Pkgbuild instance.
  #
  # @raise [Gembuild::InvalidPkgbuildError] if something other than a
  #   string or nil is passed as the existing pkgbuild
  #
  # @param gemname [String] The rubygem for which to create a PKGBUILD.
  # @param existing_pkgbuild [nil, String] An old PKGBUILD that can be
  #   parsed for maintainer and contributor information.
  # @return [Gembuild::Pkgbuild] a new Pkgbuild instance
  def initialize(gemname, existing_pkgbuild = nil)
    unless existing_pkgbuild.nil? || existing_pkgbuild.is_a?(String)
      fail Gembuild::InvalidPkgbuildError
    end

    @gemname = gemname
    @pkgname = "ruby-#{@gemname}"

    set_package_defaults

    no_parse_pkgbuild = existing_pkgbuild.nil? || existing_pkgbuild.empty?
    parse_existing_pkgbuild(existing_pkgbuild) unless no_parse_pkgbuild
  end

  # Parse the old pkgbuild (if it exists) to get information about old
  # maintainers or contributors or about other dependencies that have been
  # added but that can not be scraped from rubygems.org.
  #
  # @param pkgbuild [String] The old PKGBUILD to parse.
  # @return [Hash] a hash containing the values scraped from the PKGBUILD
  def parse_existing_pkgbuild(pkgbuild)
    pkgbuild.match(/^# Maintainer: (.*)$/) { |m| @maintainer = m[1] }

    @contributor = pkgbuild.scan(/^# Contributor: (.*)$/).flatten

    deps = parse_existing_dependencies(pkgbuild)
    deps.each do |dep|
      @depends << dep
    end

    { maintainer: maintainer, contributor: contributor, depends: deps }
  end

  # Create a new Pkgbuild instance with all information from the scraped
  # sources assigned.
  #
  # @param gemname [String] The rubygem for which to create a Pkgbuild.
  # @param existing_pkgbuild [String, nil] An old PKGBUILD that can be
  #   parsed for maintainer information.
  # @return [Gembuild::Pkgbuild] a new Pkgbuild instance
  def self.create(gemname, existing_pkgbuild = nil)
    pkgbuild = Pkgbuild.new(gemname, existing_pkgbuild)

    pkgbuild.fetch_maintainer

    gem_details = Gembuild::GemScraper.new(gemname).scrape!
    aur_details = Gembuild::AurScraper.new(pkgbuild.pkgname).scrape!

    pkgbuild.assign_gem_details(gem_details)
    pkgbuild.assign_aur_details(aur_details)

    pkgbuild
  end

  # Generate a PKGBUILD from the class using the pkgbuild erb template.
  #
  # @return [String] the PKGBUILD
  def render
    ERB.new(template, 0, '-').result(binding)
  end

  # Get the PKGBUILD erb template.
  #
  # @return [String] the pkgbuild erb template
  def template
    File.read(File.join(File.dirname(__FILE__), 'pkgbuild.erb'))
  end

  # Write the PKGBUILD to disk.
  #
  # @param path [String] The directory to write the PKGBUILD.
  # @return [Fixnum] the number of bytes written
  def write(path = '')
    File.write(File.join(File.expand_path(path), 'PKGBUILD'), render)
  end

  # Obfuscate the maintainer/contributors' email addresses to (help to)
  # prevent spam.
  #
  # @param contact_information [String] The maintainer or contributor
  #   byline.
  # @return [String] the information with the @s and .s exchanged
  def format_contact_information(contact_information)
    contact_information.gsub('@', ' at ').gsub('.', ' dot ')
  end

  # Set the correct maintainer for the PKGBUILD.
  #
  # If the current maintainer is nil (no old pkgbuild was passed), then do
  # nothing. If there is a maintainer then compare it to the configured
  # maintainer and if they are different then make the old maintainer a
  # contributor before setting the correct maintainer. If the maintainer is
  # nil then just set the confgured maintainer.
  #
  # @return [String] the pkgbuild maintainer
  def fetch_maintainer
    configured_maintainer = Gembuild.configure
    m = "#{configured_maintainer[:name]} <#{configured_maintainer[:email]}>"
    new_maintainer = format_contact_information(m)

    unless maintainer.nil? || new_maintainer == maintainer
      @contributor.unshift(maintainer)
    end

    @maintainer = new_maintainer
  end

  # Add the data scraped from rubygems.org to the pkgbuild.
  #
  # @param details [Hash] The results from GemScraper scrape.
  # @return [void]
  def assign_gem_details(details)
    @pkgver = details.fetch(:version)
    @description = details.fetch(:description)
    @checksum = details.fetch(:checksum)
    @license = details.fetch(:license)
    @url = details.fetch(:homepage)

    details.fetch(:dependencies).each do |dependency|
      @depends << "ruby-#{dependency}"
    end
  end

  # Assign version information based on the information gathered from the
  # AUR.
  #
  # @param details [Hash, nil] The results from AurScraper scrape or nil if
  #   the package does not yet exist on the AUR.
  # @return [void]
  def assign_aur_details(details)
    if details.nil?
      @epoch = 0
      @pkgrel = 1
    else
      perform_version_reconciliation(details)
    end
  end

  private

  # Set the static variables of a new pkgbuild.
  #
  # @return [nil]
  def set_package_defaults
    @checksum_type = 'sha256'
    @arch = ['any']
    @makedepends = ['rubygems']
    @depends = ['ruby']
    @source = ['https://rubygems.org/downloads/$_gemname-$pkgver.gem']
    @noextract = ['$_gemname-$pkgver.gem']
    @options = ['!emptydirs']
    @contributor = []

    nil
  end

  # Scrape dependencies from an existing pkgbuild.
  #
  # @param pkgbuild [String] The PKGBUILD to search.
  # @return [Array] all existing dependencies that are not ruby or gems
  def parse_existing_dependencies(pkgbuild)
    match = pkgbuild.match(/^depends=\((.*?)\)$/m)[1]

    # First step is to remove the leading and trailing quotes. Then convert
    # all whitespace (newlines, tabs, multiple spaces, etc.) to single
    # spaces. Then, make sure that strings are quoted with ' not ".
    # Finally, split the packages into an array.
    deps = match[1..-2].gsub(/[[:space:]]+/, ' ').tr('"', "'").split("' '")

    deps.reject { |e| e.match(/^ruby/) }
  rescue
    []
  end

  # Assign the correct pkgrel and epoch depending on the current pkgver on
  # the AUR and the version of the gem from rubygems.org.
  #
  # @param details [Hash] The results from AurScraper scrape
  # @return [void]
  def perform_version_reconciliation(details)
    @epoch = details.fetch(:epoch)
    @pkgrel = 1

    if pkgver < details.fetch(:pkgver)
      @epoch += 1
    elsif @pkgver == details.fetch(:pkgver)
      @pkgrel = details.fetch(:pkgrel) + 1
    end
  end
end

#contributorArray

Returns an array of the contributors to the pkgbuild.

Returns:

  • (Array)

    an array of the contributors to the pkgbuild


78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/gembuild/pkgbuild.rb', line 78

class Pkgbuild
  attr_accessor :arch, :checksum, :checksum_type, :contributor, :depends,
                :description, :epoch, :gemname, :license, :maintainer,
                :makedepends, :noextract, :options, :pkgname, :pkgrel,
                :pkgver, :source, :url

  # Create a new Pkgbuild instance.
  #
  # @raise [Gembuild::InvalidPkgbuildError] if something other than a
  #   string or nil is passed as the existing pkgbuild
  #
  # @param gemname [String] The rubygem for which to create a PKGBUILD.
  # @param existing_pkgbuild [nil, String] An old PKGBUILD that can be
  #   parsed for maintainer and contributor information.
  # @return [Gembuild::Pkgbuild] a new Pkgbuild instance
  def initialize(gemname, existing_pkgbuild = nil)
    unless existing_pkgbuild.nil? || existing_pkgbuild.is_a?(String)
      fail Gembuild::InvalidPkgbuildError
    end

    @gemname = gemname
    @pkgname = "ruby-#{@gemname}"

    set_package_defaults

    no_parse_pkgbuild = existing_pkgbuild.nil? || existing_pkgbuild.empty?
    parse_existing_pkgbuild(existing_pkgbuild) unless no_parse_pkgbuild
  end

  # Parse the old pkgbuild (if it exists) to get information about old
  # maintainers or contributors or about other dependencies that have been
  # added but that can not be scraped from rubygems.org.
  #
  # @param pkgbuild [String] The old PKGBUILD to parse.
  # @return [Hash] a hash containing the values scraped from the PKGBUILD
  def parse_existing_pkgbuild(pkgbuild)
    pkgbuild.match(/^# Maintainer: (.*)$/) { |m| @maintainer = m[1] }

    @contributor = pkgbuild.scan(/^# Contributor: (.*)$/).flatten

    deps = parse_existing_dependencies(pkgbuild)
    deps.each do |dep|
      @depends << dep
    end

    { maintainer: maintainer, contributor: contributor, depends: deps }
  end

  # Create a new Pkgbuild instance with all information from the scraped
  # sources assigned.
  #
  # @param gemname [String] The rubygem for which to create a Pkgbuild.
  # @param existing_pkgbuild [String, nil] An old PKGBUILD that can be
  #   parsed for maintainer information.
  # @return [Gembuild::Pkgbuild] a new Pkgbuild instance
  def self.create(gemname, existing_pkgbuild = nil)
    pkgbuild = Pkgbuild.new(gemname, existing_pkgbuild)

    pkgbuild.fetch_maintainer

    gem_details = Gembuild::GemScraper.new(gemname).scrape!
    aur_details = Gembuild::AurScraper.new(pkgbuild.pkgname).scrape!

    pkgbuild.assign_gem_details(gem_details)
    pkgbuild.assign_aur_details(aur_details)

    pkgbuild
  end

  # Generate a PKGBUILD from the class using the pkgbuild erb template.
  #
  # @return [String] the PKGBUILD
  def render
    ERB.new(template, 0, '-').result(binding)
  end

  # Get the PKGBUILD erb template.
  #
  # @return [String] the pkgbuild erb template
  def template
    File.read(File.join(File.dirname(__FILE__), 'pkgbuild.erb'))
  end

  # Write the PKGBUILD to disk.
  #
  # @param path [String] The directory to write the PKGBUILD.
  # @return [Fixnum] the number of bytes written
  def write(path = '')
    File.write(File.join(File.expand_path(path), 'PKGBUILD'), render)
  end

  # Obfuscate the maintainer/contributors' email addresses to (help to)
  # prevent spam.
  #
  # @param contact_information [String] The maintainer or contributor
  #   byline.
  # @return [String] the information with the @s and .s exchanged
  def format_contact_information(contact_information)
    contact_information.gsub('@', ' at ').gsub('.', ' dot ')
  end

  # Set the correct maintainer for the PKGBUILD.
  #
  # If the current maintainer is nil (no old pkgbuild was passed), then do
  # nothing. If there is a maintainer then compare it to the configured
  # maintainer and if they are different then make the old maintainer a
  # contributor before setting the correct maintainer. If the maintainer is
  # nil then just set the confgured maintainer.
  #
  # @return [String] the pkgbuild maintainer
  def fetch_maintainer
    configured_maintainer = Gembuild.configure
    m = "#{configured_maintainer[:name]} <#{configured_maintainer[:email]}>"
    new_maintainer = format_contact_information(m)

    unless maintainer.nil? || new_maintainer == maintainer
      @contributor.unshift(maintainer)
    end

    @maintainer = new_maintainer
  end

  # Add the data scraped from rubygems.org to the pkgbuild.
  #
  # @param details [Hash] The results from GemScraper scrape.
  # @return [void]
  def assign_gem_details(details)
    @pkgver = details.fetch(:version)
    @description = details.fetch(:description)
    @checksum = details.fetch(:checksum)
    @license = details.fetch(:license)
    @url = details.fetch(:homepage)

    details.fetch(:dependencies).each do |dependency|
      @depends << "ruby-#{dependency}"
    end
  end

  # Assign version information based on the information gathered from the
  # AUR.
  #
  # @param details [Hash, nil] The results from AurScraper scrape or nil if
  #   the package does not yet exist on the AUR.
  # @return [void]
  def assign_aur_details(details)
    if details.nil?
      @epoch = 0
      @pkgrel = 1
    else
      perform_version_reconciliation(details)
    end
  end

  private

  # Set the static variables of a new pkgbuild.
  #
  # @return [nil]
  def set_package_defaults
    @checksum_type = 'sha256'
    @arch = ['any']
    @makedepends = ['rubygems']
    @depends = ['ruby']
    @source = ['https://rubygems.org/downloads/$_gemname-$pkgver.gem']
    @noextract = ['$_gemname-$pkgver.gem']
    @options = ['!emptydirs']
    @contributor = []

    nil
  end

  # Scrape dependencies from an existing pkgbuild.
  #
  # @param pkgbuild [String] The PKGBUILD to search.
  # @return [Array] all existing dependencies that are not ruby or gems
  def parse_existing_dependencies(pkgbuild)
    match = pkgbuild.match(/^depends=\((.*?)\)$/m)[1]

    # First step is to remove the leading and trailing quotes. Then convert
    # all whitespace (newlines, tabs, multiple spaces, etc.) to single
    # spaces. Then, make sure that strings are quoted with ' not ".
    # Finally, split the packages into an array.
    deps = match[1..-2].gsub(/[[:space:]]+/, ' ').tr('"', "'").split("' '")

    deps.reject { |e| e.match(/^ruby/) }
  rescue
    []
  end

  # Assign the correct pkgrel and epoch depending on the current pkgver on
  # the AUR and the version of the gem from rubygems.org.
  #
  # @param details [Hash] The results from AurScraper scrape
  # @return [void]
  def perform_version_reconciliation(details)
    @epoch = details.fetch(:epoch)
    @pkgrel = 1

    if pkgver < details.fetch(:pkgver)
      @epoch += 1
    elsif @pkgver == details.fetch(:pkgver)
      @pkgrel = details.fetch(:pkgrel) + 1
    end
  end
end

#dependsArray

Returns an array of the package's dependencies (always ruby plus any other gems listed as dependencies).

Returns:

  • (Array)

    an array of the package's dependencies (always ruby plus any other gems listed as dependencies)

See Also:


78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/gembuild/pkgbuild.rb', line 78

class Pkgbuild
  attr_accessor :arch, :checksum, :checksum_type, :contributor, :depends,
                :description, :epoch, :gemname, :license, :maintainer,
                :makedepends, :noextract, :options, :pkgname, :pkgrel,
                :pkgver, :source, :url

  # Create a new Pkgbuild instance.
  #
  # @raise [Gembuild::InvalidPkgbuildError] if something other than a
  #   string or nil is passed as the existing pkgbuild
  #
  # @param gemname [String] The rubygem for which to create a PKGBUILD.
  # @param existing_pkgbuild [nil, String] An old PKGBUILD that can be
  #   parsed for maintainer and contributor information.
  # @return [Gembuild::Pkgbuild] a new Pkgbuild instance
  def initialize(gemname, existing_pkgbuild = nil)
    unless existing_pkgbuild.nil? || existing_pkgbuild.is_a?(String)
      fail Gembuild::InvalidPkgbuildError
    end

    @gemname = gemname
    @pkgname = "ruby-#{@gemname}"

    set_package_defaults

    no_parse_pkgbuild = existing_pkgbuild.nil? || existing_pkgbuild.empty?
    parse_existing_pkgbuild(existing_pkgbuild) unless no_parse_pkgbuild
  end

  # Parse the old pkgbuild (if it exists) to get information about old
  # maintainers or contributors or about other dependencies that have been
  # added but that can not be scraped from rubygems.org.
  #
  # @param pkgbuild [String] The old PKGBUILD to parse.
  # @return [Hash] a hash containing the values scraped from the PKGBUILD
  def parse_existing_pkgbuild(pkgbuild)
    pkgbuild.match(/^# Maintainer: (.*)$/) { |m| @maintainer = m[1] }

    @contributor = pkgbuild.scan(/^# Contributor: (.*)$/).flatten

    deps = parse_existing_dependencies(pkgbuild)
    deps.each do |dep|
      @depends << dep
    end

    { maintainer: maintainer, contributor: contributor, depends: deps }
  end

  # Create a new Pkgbuild instance with all information from the scraped
  # sources assigned.
  #
  # @param gemname [String] The rubygem for which to create a Pkgbuild.
  # @param existing_pkgbuild [String, nil] An old PKGBUILD that can be
  #   parsed for maintainer information.
  # @return [Gembuild::Pkgbuild] a new Pkgbuild instance
  def self.create(gemname, existing_pkgbuild = nil)
    pkgbuild = Pkgbuild.new(gemname, existing_pkgbuild)

    pkgbuild.fetch_maintainer

    gem_details = Gembuild::GemScraper.new(gemname).scrape!
    aur_details = Gembuild::AurScraper.new(pkgbuild.pkgname).scrape!

    pkgbuild.assign_gem_details(gem_details)
    pkgbuild.assign_aur_details(aur_details)

    pkgbuild
  end

  # Generate a PKGBUILD from the class using the pkgbuild erb template.
  #
  # @return [String] the PKGBUILD
  def render
    ERB.new(template, 0, '-').result(binding)
  end

  # Get the PKGBUILD erb template.
  #
  # @return [String] the pkgbuild erb template
  def template
    File.read(File.join(File.dirname(__FILE__), 'pkgbuild.erb'))
  end

  # Write the PKGBUILD to disk.
  #
  # @param path [String] The directory to write the PKGBUILD.
  # @return [Fixnum] the number of bytes written
  def write(path = '')
    File.write(File.join(File.expand_path(path), 'PKGBUILD'), render)
  end

  # Obfuscate the maintainer/contributors' email addresses to (help to)
  # prevent spam.
  #
  # @param contact_information [String] The maintainer or contributor
  #   byline.
  # @return [String] the information with the @s and .s exchanged
  def format_contact_information(contact_information)
    contact_information.gsub('@', ' at ').gsub('.', ' dot ')
  end

  # Set the correct maintainer for the PKGBUILD.
  #
  # If the current maintainer is nil (no old pkgbuild was passed), then do
  # nothing. If there is a maintainer then compare it to the configured
  # maintainer and if they are different then make the old maintainer a
  # contributor before setting the correct maintainer. If the maintainer is
  # nil then just set the confgured maintainer.
  #
  # @return [String] the pkgbuild maintainer
  def fetch_maintainer
    configured_maintainer = Gembuild.configure
    m = "#{configured_maintainer[:name]} <#{configured_maintainer[:email]}>"
    new_maintainer = format_contact_information(m)

    unless maintainer.nil? || new_maintainer == maintainer
      @contributor.unshift(maintainer)
    end

    @maintainer = new_maintainer
  end

  # Add the data scraped from rubygems.org to the pkgbuild.
  #
  # @param details [Hash] The results from GemScraper scrape.
  # @return [void]
  def assign_gem_details(details)
    @pkgver = details.fetch(:version)
    @description = details.fetch(:description)
    @checksum = details.fetch(:checksum)
    @license = details.fetch(:license)
    @url = details.fetch(:homepage)

    details.fetch(:dependencies).each do |dependency|
      @depends << "ruby-#{dependency}"
    end
  end

  # Assign version information based on the information gathered from the
  # AUR.
  #
  # @param details [Hash, nil] The results from AurScraper scrape or nil if
  #   the package does not yet exist on the AUR.
  # @return [void]
  def assign_aur_details(details)
    if details.nil?
      @epoch = 0
      @pkgrel = 1
    else
      perform_version_reconciliation(details)
    end
  end

  private

  # Set the static variables of a new pkgbuild.
  #
  # @return [nil]
  def set_package_defaults
    @checksum_type = 'sha256'
    @arch = ['any']
    @makedepends = ['rubygems']
    @depends = ['ruby']
    @source = ['https://rubygems.org/downloads/$_gemname-$pkgver.gem']
    @noextract = ['$_gemname-$pkgver.gem']
    @options = ['!emptydirs']
    @contributor = []

    nil
  end

  # Scrape dependencies from an existing pkgbuild.
  #
  # @param pkgbuild [String] The PKGBUILD to search.
  # @return [Array] all existing dependencies that are not ruby or gems
  def parse_existing_dependencies(pkgbuild)
    match = pkgbuild.match(/^depends=\((.*?)\)$/m)[1]

    # First step is to remove the leading and trailing quotes. Then convert
    # all whitespace (newlines, tabs, multiple spaces, etc.) to single
    # spaces. Then, make sure that strings are quoted with ' not ".
    # Finally, split the packages into an array.
    deps = match[1..-2].gsub(/[[:space:]]+/, ' ').tr('"', "'").split("' '")

    deps.reject { |e| e.match(/^ruby/) }
  rescue
    []
  end

  # Assign the correct pkgrel and epoch depending on the current pkgver on
  # the AUR and the version of the gem from rubygems.org.
  #
  # @param details [Hash] The results from AurScraper scrape
  # @return [void]
  def perform_version_reconciliation(details)
    @epoch = details.fetch(:epoch)
    @pkgrel = 1

    if pkgver < details.fetch(:pkgver)
      @epoch += 1
    elsif @pkgver == details.fetch(:pkgver)
      @pkgrel = details.fetch(:pkgrel) + 1
    end
  end
end

#descriptionString

Returns the package description.

Returns:

  • (String)

    the package description

See Also:


78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/gembuild/pkgbuild.rb', line 78

class Pkgbuild
  attr_accessor :arch, :checksum, :checksum_type, :contributor, :depends,
                :description, :epoch, :gemname, :license, :maintainer,
                :makedepends, :noextract, :options, :pkgname, :pkgrel,
                :pkgver, :source, :url

  # Create a new Pkgbuild instance.
  #
  # @raise [Gembuild::InvalidPkgbuildError] if something other than a
  #   string or nil is passed as the existing pkgbuild
  #
  # @param gemname [String] The rubygem for which to create a PKGBUILD.
  # @param existing_pkgbuild [nil, String] An old PKGBUILD that can be
  #   parsed for maintainer and contributor information.
  # @return [Gembuild::Pkgbuild] a new Pkgbuild instance
  def initialize(gemname, existing_pkgbuild = nil)
    unless existing_pkgbuild.nil? || existing_pkgbuild.is_a?(String)
      fail Gembuild::InvalidPkgbuildError
    end

    @gemname = gemname
    @pkgname = "ruby-#{@gemname}"

    set_package_defaults

    no_parse_pkgbuild = existing_pkgbuild.nil? || existing_pkgbuild.empty?
    parse_existing_pkgbuild(existing_pkgbuild) unless no_parse_pkgbuild
  end

  # Parse the old pkgbuild (if it exists) to get information about old
  # maintainers or contributors or about other dependencies that have been
  # added but that can not be scraped from rubygems.org.
  #
  # @param pkgbuild [String] The old PKGBUILD to parse.
  # @return [Hash] a hash containing the values scraped from the PKGBUILD
  def parse_existing_pkgbuild(pkgbuild)
    pkgbuild.match(/^# Maintainer: (.*)$/) { |m| @maintainer = m[1] }

    @contributor = pkgbuild.scan(/^# Contributor: (.*)$/).flatten

    deps = parse_existing_dependencies(pkgbuild)
    deps.each do |dep|
      @depends << dep
    end

    { maintainer: maintainer, contributor: contributor, depends: deps }
  end

  # Create a new Pkgbuild instance with all information from the scraped
  # sources assigned.
  #
  # @param gemname [String] The rubygem for which to create a Pkgbuild.
  # @param existing_pkgbuild [String, nil] An old PKGBUILD that can be
  #   parsed for maintainer information.
  # @return [Gembuild::Pkgbuild] a new Pkgbuild instance
  def self.create(gemname, existing_pkgbuild = nil)
    pkgbuild = Pkgbuild.new(gemname, existing_pkgbuild)

    pkgbuild.fetch_maintainer

    gem_details = Gembuild::GemScraper.new(gemname).scrape!
    aur_details = Gembuild::AurScraper.new(pkgbuild.pkgname).scrape!

    pkgbuild.assign_gem_details(gem_details)
    pkgbuild.assign_aur_details(aur_details)

    pkgbuild
  end

  # Generate a PKGBUILD from the class using the pkgbuild erb template.
  #
  # @return [String] the PKGBUILD
  def render
    ERB.new(template, 0, '-').result(binding)
  end

  # Get the PKGBUILD erb template.
  #
  # @return [String] the pkgbuild erb template
  def template
    File.read(File.join(File.dirname(__FILE__), 'pkgbuild.erb'))
  end

  # Write the PKGBUILD to disk.
  #
  # @param path [String] The directory to write the PKGBUILD.
  # @return [Fixnum] the number of bytes written
  def write(path = '')
    File.write(File.join(File.expand_path(path), 'PKGBUILD'), render)
  end

  # Obfuscate the maintainer/contributors' email addresses to (help to)
  # prevent spam.
  #
  # @param contact_information [String] The maintainer or contributor
  #   byline.
  # @return [String] the information with the @s and .s exchanged
  def format_contact_information(contact_information)
    contact_information.gsub('@', ' at ').gsub('.', ' dot ')
  end

  # Set the correct maintainer for the PKGBUILD.
  #
  # If the current maintainer is nil (no old pkgbuild was passed), then do
  # nothing. If there is a maintainer then compare it to the configured
  # maintainer and if they are different then make the old maintainer a
  # contributor before setting the correct maintainer. If the maintainer is
  # nil then just set the confgured maintainer.
  #
  # @return [String] the pkgbuild maintainer
  def fetch_maintainer
    configured_maintainer = Gembuild.configure
    m = "#{configured_maintainer[:name]} <#{configured_maintainer[:email]}>"
    new_maintainer = format_contact_information(m)

    unless maintainer.nil? || new_maintainer == maintainer
      @contributor.unshift(maintainer)
    end

    @maintainer = new_maintainer
  end

  # Add the data scraped from rubygems.org to the pkgbuild.
  #
  # @param details [Hash] The results from GemScraper scrape.
  # @return [void]
  def assign_gem_details(details)
    @pkgver = details.fetch(:version)
    @description = details.fetch(:description)
    @checksum = details.fetch(:checksum)
    @license = details.fetch(:license)
    @url = details.fetch(:homepage)

    details.fetch(:dependencies).each do |dependency|
      @depends << "ruby-#{dependency}"
    end
  end

  # Assign version information based on the information gathered from the
  # AUR.
  #
  # @param details [Hash, nil] The results from AurScraper scrape or nil if
  #   the package does not yet exist on the AUR.
  # @return [void]
  def assign_aur_details(details)
    if details.nil?
      @epoch = 0
      @pkgrel = 1
    else
      perform_version_reconciliation(details)
    end
  end

  private

  # Set the static variables of a new pkgbuild.
  #
  # @return [nil]
  def set_package_defaults
    @checksum_type = 'sha256'
    @arch = ['any']
    @makedepends = ['rubygems']
    @depends = ['ruby']
    @source = ['https://rubygems.org/downloads/$_gemname-$pkgver.gem']
    @noextract = ['$_gemname-$pkgver.gem']
    @options = ['!emptydirs']
    @contributor = []

    nil
  end

  # Scrape dependencies from an existing pkgbuild.
  #
  # @param pkgbuild [String] The PKGBUILD to search.
  # @return [Array] all existing dependencies that are not ruby or gems
  def parse_existing_dependencies(pkgbuild)
    match = pkgbuild.match(/^depends=\((.*?)\)$/m)[1]

    # First step is to remove the leading and trailing quotes. Then convert
    # all whitespace (newlines, tabs, multiple spaces, etc.) to single
    # spaces. Then, make sure that strings are quoted with ' not ".
    # Finally, split the packages into an array.
    deps = match[1..-2].gsub(/[[:space:]]+/, ' ').tr('"', "'").split("' '")

    deps.reject { |e| e.match(/^ruby/) }
  rescue
    []
  end

  # Assign the correct pkgrel and epoch depending on the current pkgver on
  # the AUR and the version of the gem from rubygems.org.
  #
  # @param details [Hash] The results from AurScraper scrape
  # @return [void]
  def perform_version_reconciliation(details)
    @epoch = details.fetch(:epoch)
    @pkgrel = 1

    if pkgver < details.fetch(:pkgver)
      @epoch += 1
    elsif @pkgver == details.fetch(:pkgver)
      @pkgrel = details.fetch(:pkgrel) + 1
    end
  end
end

#epochFixnum

Returns the package's epoch value.

Returns:

  • (Fixnum)

    the package's epoch value

See Also:


78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/gembuild/pkgbuild.rb', line 78

class Pkgbuild
  attr_accessor :arch, :checksum, :checksum_type, :contributor, :depends,
                :description, :epoch, :gemname, :license, :maintainer,
                :makedepends, :noextract, :options, :pkgname, :pkgrel,
                :pkgver, :source, :url

  # Create a new Pkgbuild instance.
  #
  # @raise [Gembuild::InvalidPkgbuildError] if something other than a
  #   string or nil is passed as the existing pkgbuild
  #
  # @param gemname [String] The rubygem for which to create a PKGBUILD.
  # @param existing_pkgbuild [nil, String] An old PKGBUILD that can be
  #   parsed for maintainer and contributor information.
  # @return [Gembuild::Pkgbuild] a new Pkgbuild instance
  def initialize(gemname, existing_pkgbuild = nil)
    unless existing_pkgbuild.nil? || existing_pkgbuild.is_a?(String)
      fail Gembuild::InvalidPkgbuildError
    end

    @gemname = gemname
    @pkgname = "ruby-#{@gemname}"

    set_package_defaults

    no_parse_pkgbuild = existing_pkgbuild.nil? || existing_pkgbuild.empty?
    parse_existing_pkgbuild(existing_pkgbuild) unless no_parse_pkgbuild
  end

  # Parse the old pkgbuild (if it exists) to get information about old
  # maintainers or contributors or about other dependencies that have been
  # added but that can not be scraped from rubygems.org.
  #
  # @param pkgbuild [String] The old PKGBUILD to parse.
  # @return [Hash] a hash containing the values scraped from the PKGBUILD
  def parse_existing_pkgbuild(pkgbuild)
    pkgbuild.match(/^# Maintainer: (.*)$/) { |m| @maintainer = m[1] }

    @contributor = pkgbuild.scan(/^# Contributor: (.*)$/).flatten

    deps = parse_existing_dependencies(pkgbuild)
    deps.each do |dep|
      @depends << dep
    end

    { maintainer: maintainer, contributor: contributor, depends: deps }
  end

  # Create a new Pkgbuild instance with all information from the scraped
  # sources assigned.
  #
  # @param gemname [String] The rubygem for which to create a Pkgbuild.
  # @param existing_pkgbuild [String, nil] An old PKGBUILD that can be
  #   parsed for maintainer information.
  # @return [Gembuild::Pkgbuild] a new Pkgbuild instance
  def self.create(gemname, existing_pkgbuild = nil)
    pkgbuild = Pkgbuild.new(gemname, existing_pkgbuild)

    pkgbuild.fetch_maintainer

    gem_details = Gembuild::GemScraper.new(gemname).scrape!
    aur_details = Gembuild::AurScraper.new(pkgbuild.pkgname).scrape!

    pkgbuild.assign_gem_details(gem_details)
    pkgbuild.assign_aur_details(aur_details)

    pkgbuild
  end

  # Generate a PKGBUILD from the class using the pkgbuild erb template.
  #
  # @return [String] the PKGBUILD
  def render
    ERB.new(template, 0, '-').result(binding)
  end

  # Get the PKGBUILD erb template.
  #
  # @return [String] the pkgbuild erb template
  def template
    File.read(File.join(File.dirname(__FILE__), 'pkgbuild.erb'))
  end

  # Write the PKGBUILD to disk.
  #
  # @param path [String] The directory to write the PKGBUILD.
  # @return [Fixnum] the number of bytes written
  def write(path = '')
    File.write(File.join(File.expand_path(path), 'PKGBUILD'), render)
  end

  # Obfuscate the maintainer/contributors' email addresses to (help to)
  # prevent spam.
  #
  # @param contact_information [String] The maintainer or contributor
  #   byline.
  # @return [String] the information with the @s and .s exchanged
  def format_contact_information(contact_information)
    contact_information.gsub('@', ' at ').gsub('.', ' dot ')
  end

  # Set the correct maintainer for the PKGBUILD.
  #
  # If the current maintainer is nil (no old pkgbuild was passed), then do
  # nothing. If there is a maintainer then compare it to the configured
  # maintainer and if they are different then make the old maintainer a
  # contributor before setting the correct maintainer. If the maintainer is
  # nil then just set the confgured maintainer.
  #
  # @return [String] the pkgbuild maintainer
  def fetch_maintainer
    configured_maintainer = Gembuild.configure
    m = "#{configured_maintainer[:name]} <#{configured_maintainer[:email]}>"
    new_maintainer = format_contact_information(m)

    unless maintainer.nil? || new_maintainer == maintainer
      @contributor.unshift(maintainer)
    end

    @maintainer = new_maintainer
  end

  # Add the data scraped from rubygems.org to the pkgbuild.
  #
  # @param details [Hash] The results from GemScraper scrape.
  # @return [void]
  def assign_gem_details(details)
    @pkgver = details.fetch(:version)
    @description = details.fetch(:description)
    @checksum = details.fetch(:checksum)
    @license = details.fetch(:license)
    @url = details.fetch(:homepage)

    details.fetch(:dependencies).each do |dependency|
      @depends << "ruby-#{dependency}"
    end
  end

  # Assign version information based on the information gathered from the
  # AUR.
  #
  # @param details [Hash, nil] The results from AurScraper scrape or nil if
  #   the package does not yet exist on the AUR.
  # @return [void]
  def assign_aur_details(details)
    if details.nil?
      @epoch = 0
      @pkgrel = 1
    else
      perform_version_reconciliation(details)
    end
  end

  private

  # Set the static variables of a new pkgbuild.
  #
  # @return [nil]
  def set_package_defaults
    @checksum_type = 'sha256'
    @arch = ['any']
    @makedepends = ['rubygems']
    @depends = ['ruby']
    @source = ['https://rubygems.org/downloads/$_gemname-$pkgver.gem']
    @noextract = ['$_gemname-$pkgver.gem']
    @options = ['!emptydirs']
    @contributor = []

    nil
  end

  # Scrape dependencies from an existing pkgbuild.
  #
  # @param pkgbuild [String] The PKGBUILD to search.
  # @return [Array] all existing dependencies that are not ruby or gems
  def parse_existing_dependencies(pkgbuild)
    match = pkgbuild.match(/^depends=\((.*?)\)$/m)[1]

    # First step is to remove the leading and trailing quotes. Then convert
    # all whitespace (newlines, tabs, multiple spaces, etc.) to single
    # spaces. Then, make sure that strings are quoted with ' not ".
    # Finally, split the packages into an array.
    deps = match[1..-2].gsub(/[[:space:]]+/, ' ').tr('"', "'").split("' '")

    deps.reject { |e| e.match(/^ruby/) }
  rescue
    []
  end

  # Assign the correct pkgrel and epoch depending on the current pkgver on
  # the AUR and the version of the gem from rubygems.org.
  #
  # @param details [Hash] The results from AurScraper scrape
  # @return [void]
  def perform_version_reconciliation(details)
    @epoch = details.fetch(:epoch)
    @pkgrel = 1

    if pkgver < details.fetch(:pkgver)
      @epoch += 1
    elsif @pkgver == details.fetch(:pkgver)
      @pkgrel = details.fetch(:pkgrel) + 1
    end
  end
end

#gemnameString

Returns the ruby gem for which to generate a PKGBUILD.

Returns:

  • (String)

    the ruby gem for which to generate a PKGBUILD


78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/gembuild/pkgbuild.rb', line 78

class Pkgbuild
  attr_accessor :arch, :checksum, :checksum_type, :contributor, :depends,
                :description, :epoch, :gemname, :license, :maintainer,
                :makedepends, :noextract, :options, :pkgname, :pkgrel,
                :pkgver, :source, :url

  # Create a new Pkgbuild instance.
  #
  # @raise [Gembuild::InvalidPkgbuildError] if something other than a
  #   string or nil is passed as the existing pkgbuild
  #
  # @param gemname [String] The rubygem for which to create a PKGBUILD.
  # @param existing_pkgbuild [nil, String] An old PKGBUILD that can be
  #   parsed for maintainer and contributor information.
  # @return [Gembuild::Pkgbuild] a new Pkgbuild instance
  def initialize(gemname, existing_pkgbuild = nil)
    unless existing_pkgbuild.nil? || existing_pkgbuild.is_a?(String)
      fail Gembuild::InvalidPkgbuildError
    end

    @gemname = gemname
    @pkgname = "ruby-#{@gemname}"

    set_package_defaults

    no_parse_pkgbuild = existing_pkgbuild.nil? || existing_pkgbuild.empty?
    parse_existing_pkgbuild(existing_pkgbuild) unless no_parse_pkgbuild
  end

  # Parse the old pkgbuild (if it exists) to get information about old
  # maintainers or contributors or about other dependencies that have been
  # added but that can not be scraped from rubygems.org.
  #
  # @param pkgbuild [String] The old PKGBUILD to parse.
  # @return [Hash] a hash containing the values scraped from the PKGBUILD
  def parse_existing_pkgbuild(pkgbuild)
    pkgbuild.match(/^# Maintainer: (.*)$/) { |m| @maintainer = m[1] }

    @contributor = pkgbuild.scan(/^# Contributor: (.*)$/).flatten

    deps = parse_existing_dependencies(pkgbuild)
    deps.each do |dep|
      @depends << dep
    end

    { maintainer: maintainer, contributor: contributor, depends: deps }
  end

  # Create a new Pkgbuild instance with all information from the scraped
  # sources assigned.
  #
  # @param gemname [String] The rubygem for which to create a Pkgbuild.
  # @param existing_pkgbuild [String, nil] An old PKGBUILD that can be
  #   parsed for maintainer information.
  # @return [Gembuild::Pkgbuild] a new Pkgbuild instance
  def self.create(gemname, existing_pkgbuild = nil)
    pkgbuild = Pkgbuild.new(gemname, existing_pkgbuild)

    pkgbuild.fetch_maintainer

    gem_details = Gembuild::GemScraper.new(gemname).scrape!
    aur_details = Gembuild::AurScraper.new(pkgbuild.pkgname).scrape!

    pkgbuild.assign_gem_details(gem_details)
    pkgbuild.assign_aur_details(aur_details)

    pkgbuild
  end

  # Generate a PKGBUILD from the class using the pkgbuild erb template.
  #
  # @return [String] the PKGBUILD
  def render
    ERB.new(template, 0, '-').result(binding)
  end

  # Get the PKGBUILD erb template.
  #
  # @return [String] the pkgbuild erb template
  def template
    File.read(File.join(File.dirname(__FILE__), 'pkgbuild.erb'))
  end

  # Write the PKGBUILD to disk.
  #
  # @param path [String] The directory to write the PKGBUILD.
  # @return [Fixnum] the number of bytes written
  def write(path = '')
    File.write(File.join(File.expand_path(path), 'PKGBUILD'), render)
  end

  # Obfuscate the maintainer/contributors' email addresses to (help to)
  # prevent spam.
  #
  # @param contact_information [String] The maintainer or contributor
  #   byline.
  # @return [String] the information with the @s and .s exchanged
  def format_contact_information(contact_information)
    contact_information.gsub('@', ' at ').gsub('.', ' dot ')
  end

  # Set the correct maintainer for the PKGBUILD.
  #
  # If the current maintainer is nil (no old pkgbuild was passed), then do
  # nothing. If there is a maintainer then compare it to the configured
  # maintainer and if they are different then make the old maintainer a
  # contributor before setting the correct maintainer. If the maintainer is
  # nil then just set the confgured maintainer.
  #
  # @return [String] the pkgbuild maintainer
  def fetch_maintainer
    configured_maintainer = Gembuild.configure
    m = "#{configured_maintainer[:name]} <#{configured_maintainer[:email]}>"
    new_maintainer = format_contact_information(m)

    unless maintainer.nil? || new_maintainer == maintainer
      @contributor.unshift(maintainer)
    end

    @maintainer = new_maintainer
  end

  # Add the data scraped from rubygems.org to the pkgbuild.
  #
  # @param details [Hash] The results from GemScraper scrape.
  # @return [void]
  def assign_gem_details(details)
    @pkgver = details.fetch(:version)
    @description = details.fetch(:description)
    @checksum = details.fetch(:checksum)
    @license = details.fetch(:license)
    @url = details.fetch(:homepage)

    details.fetch(:dependencies).each do |dependency|
      @depends << "ruby-#{dependency}"
    end
  end

  # Assign version information based on the information gathered from the
  # AUR.
  #
  # @param details [Hash, nil] The results from AurScraper scrape or nil if
  #   the package does not yet exist on the AUR.
  # @return [void]
  def assign_aur_details(details)
    if details.nil?
      @epoch = 0
      @pkgrel = 1
    else
      perform_version_reconciliation(details)
    end
  end

  private

  # Set the static variables of a new pkgbuild.
  #
  # @return [nil]
  def set_package_defaults
    @checksum_type = 'sha256'
    @arch = ['any']
    @makedepends = ['rubygems']
    @depends = ['ruby']
    @source = ['https://rubygems.org/downloads/$_gemname-$pkgver.gem']
    @noextract = ['$_gemname-$pkgver.gem']
    @options = ['!emptydirs']
    @contributor = []

    nil
  end

  # Scrape dependencies from an existing pkgbuild.
  #
  # @param pkgbuild [String] The PKGBUILD to search.
  # @return [Array] all existing dependencies that are not ruby or gems
  def parse_existing_dependencies(pkgbuild)
    match = pkgbuild.match(/^depends=\((.*?)\)$/m)[1]

    # First step is to remove the leading and trailing quotes. Then convert
    # all whitespace (newlines, tabs, multiple spaces, etc.) to single
    # spaces. Then, make sure that strings are quoted with ' not ".
    # Finally, split the packages into an array.
    deps = match[1..-2].gsub(/[[:space:]]+/, ' ').tr('"', "'").split("' '")

    deps.reject { |e| e.match(/^ruby/) }
  rescue
    []
  end

  # Assign the correct pkgrel and epoch depending on the current pkgver on
  # the AUR and the version of the gem from rubygems.org.
  #
  # @param details [Hash] The results from AurScraper scrape
  # @return [void]
  def perform_version_reconciliation(details)
    @epoch = details.fetch(:epoch)
    @pkgrel = 1

    if pkgver < details.fetch(:pkgver)
      @epoch += 1
    elsif @pkgver == details.fetch(:pkgver)
      @pkgrel = details.fetch(:pkgrel) + 1
    end
  end
end

#licenseArray

Returns an array of licenses for the gem.

Returns:

  • (Array)

    an array of licenses for the gem

See Also:


78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/gembuild/pkgbuild.rb', line 78

class Pkgbuild
  attr_accessor :arch, :checksum, :checksum_type, :contributor, :depends,
                :description, :epoch, :gemname, :license, :maintainer,
                :makedepends, :noextract, :options, :pkgname, :pkgrel,
                :pkgver, :source, :url

  # Create a new Pkgbuild instance.
  #
  # @raise [Gembuild::InvalidPkgbuildError] if something other than a
  #   string or nil is passed as the existing pkgbuild
  #
  # @param gemname [String] The rubygem for which to create a PKGBUILD.
  # @param existing_pkgbuild [nil, String] An old PKGBUILD that can be
  #   parsed for maintainer and contributor information.
  # @return [Gembuild::Pkgbuild] a new Pkgbuild instance
  def initialize(gemname, existing_pkgbuild = nil)
    unless existing_pkgbuild.nil? || existing_pkgbuild.is_a?(String)
      fail Gembuild::InvalidPkgbuildError
    end

    @gemname = gemname
    @pkgname = "ruby-#{@gemname}"

    set_package_defaults

    no_parse_pkgbuild = existing_pkgbuild.nil? || existing_pkgbuild.empty?
    parse_existing_pkgbuild(existing_pkgbuild) unless no_parse_pkgbuild
  end

  # Parse the old pkgbuild (if it exists) to get information about old
  # maintainers or contributors or about other dependencies that have been
  # added but that can not be scraped from rubygems.org.
  #
  # @param pkgbuild [String] The old PKGBUILD to parse.
  # @return [Hash] a hash containing the values scraped from the PKGBUILD
  def parse_existing_pkgbuild(pkgbuild)
    pkgbuild.match(/^# Maintainer: (.*)$/) { |m| @maintainer = m[1] }

    @contributor = pkgbuild.scan(/^# Contributor: (.*)$/).flatten

    deps = parse_existing_dependencies(pkgbuild)
    deps.each do |dep|
      @depends << dep
    end

    { maintainer: maintainer, contributor: contributor, depends: deps }
  end

  # Create a new Pkgbuild instance with all information from the scraped
  # sources assigned.
  #
  # @param gemname [String] The rubygem for which to create a Pkgbuild.
  # @param existing_pkgbuild [String, nil] An old PKGBUILD that can be
  #   parsed for maintainer information.
  # @return [Gembuild::Pkgbuild] a new Pkgbuild instance
  def self.create(gemname, existing_pkgbuild = nil)
    pkgbuild = Pkgbuild.new(gemname, existing_pkgbuild)

    pkgbuild.fetch_maintainer

    gem_details = Gembuild::GemScraper.new(gemname).scrape!
    aur_details = Gembuild::AurScraper.new(pkgbuild.pkgname).scrape!

    pkgbuild.assign_gem_details(gem_details)
    pkgbuild.assign_aur_details(aur_details)

    pkgbuild
  end

  # Generate a PKGBUILD from the class using the pkgbuild erb template.
  #
  # @return [String] the PKGBUILD
  def render
    ERB.new(template, 0, '-').result(binding)
  end

  # Get the PKGBUILD erb template.
  #
  # @return [String] the pkgbuild erb template
  def template
    File.read(File.join(File.dirname(__FILE__), 'pkgbuild.erb'))
  end

  # Write the PKGBUILD to disk.
  #
  # @param path [String] The directory to write the PKGBUILD.
  # @return [Fixnum] the number of bytes written
  def write(path = '')
    File.write(File.join(File.expand_path(path), 'PKGBUILD'), render)
  end

  # Obfuscate the maintainer/contributors' email addresses to (help to)
  # prevent spam.
  #
  # @param contact_information [String] The maintainer or contributor
  #   byline.
  # @return [String] the information with the @s and .s exchanged
  def format_contact_information(contact_information)
    contact_information.gsub('@', ' at ').gsub('.', ' dot ')
  end

  # Set the correct maintainer for the PKGBUILD.
  #
  # If the current maintainer is nil (no old pkgbuild was passed), then do
  # nothing. If there is a maintainer then compare it to the configured
  # maintainer and if they are different then make the old maintainer a
  # contributor before setting the correct maintainer. If the maintainer is
  # nil then just set the confgured maintainer.
  #
  # @return [String] the pkgbuild maintainer
  def fetch_maintainer
    configured_maintainer = Gembuild.configure
    m = "#{configured_maintainer[:name]} <#{configured_maintainer[:email]}>"
    new_maintainer = format_contact_information(m)

    unless maintainer.nil? || new_maintainer == maintainer
      @contributor.unshift(maintainer)
    end

    @maintainer = new_maintainer
  end

  # Add the data scraped from rubygems.org to the pkgbuild.
  #
  # @param details [Hash] The results from GemScraper scrape.
  # @return [void]
  def assign_gem_details(details)
    @pkgver = details.fetch(:version)
    @description = details.fetch(:description)
    @checksum = details.fetch(:checksum)
    @license = details.fetch(:license)
    @url = details.fetch(:homepage)

    details.fetch(:dependencies).each do |dependency|
      @depends << "ruby-#{dependency}"
    end
  end

  # Assign version information based on the information gathered from the
  # AUR.
  #
  # @param details [Hash, nil] The results from AurScraper scrape or nil if
  #   the package does not yet exist on the AUR.
  # @return [void]
  def assign_aur_details(details)
    if details.nil?
      @epoch = 0
      @pkgrel = 1
    else
      perform_version_reconciliation(details)
    end
  end

  private

  # Set the static variables of a new pkgbuild.
  #
  # @return [nil]
  def set_package_defaults
    @checksum_type = 'sha256'
    @arch = ['any']
    @makedepends = ['rubygems']
    @depends = ['ruby']
    @source = ['https://rubygems.org/downloads/$_gemname-$pkgver.gem']
    @noextract = ['$_gemname-$pkgver.gem']
    @options = ['!emptydirs']
    @contributor = []

    nil
  end

  # Scrape dependencies from an existing pkgbuild.
  #
  # @param pkgbuild [String] The PKGBUILD to search.
  # @return [Array] all existing dependencies that are not ruby or gems
  def parse_existing_dependencies(pkgbuild)
    match = pkgbuild.match(/^depends=\((.*?)\)$/m)[1]

    # First step is to remove the leading and trailing quotes. Then convert
    # all whitespace (newlines, tabs, multiple spaces, etc.) to single
    # spaces. Then, make sure that strings are quoted with ' not ".
    # Finally, split the packages into an array.
    deps = match[1..-2].gsub(/[[:space:]]+/, ' ').tr('"', "'").split("' '")

    deps.reject { |e| e.match(/^ruby/) }
  rescue
    []
  end

  # Assign the correct pkgrel and epoch depending on the current pkgver on
  # the AUR and the version of the gem from rubygems.org.
  #
  # @param details [Hash] The results from AurScraper scrape
  # @return [void]
  def perform_version_reconciliation(details)
    @epoch = details.fetch(:epoch)
    @pkgrel = 1

    if pkgver < details.fetch(:pkgver)
      @epoch += 1
    elsif @pkgver == details.fetch(:pkgver)
      @pkgrel = details.fetch(:pkgrel) + 1
    end
  end
end

#maintainerString

Returns the package's maintainer.

Returns:

  • (String)

    the package's maintainer


78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/gembuild/pkgbuild.rb', line 78

class Pkgbuild
  attr_accessor :arch, :checksum, :checksum_type, :contributor, :depends,
                :description, :epoch, :gemname, :license, :maintainer,
                :makedepends, :noextract, :options, :pkgname, :pkgrel,
                :pkgver, :source, :url

  # Create a new Pkgbuild instance.
  #
  # @raise [Gembuild::InvalidPkgbuildError] if something other than a
  #   string or nil is passed as the existing pkgbuild
  #
  # @param gemname [String] The rubygem for which to create a PKGBUILD.
  # @param existing_pkgbuild [nil, String] An old PKGBUILD that can be
  #   parsed for maintainer and contributor information.
  # @return [Gembuild::Pkgbuild] a new Pkgbuild instance
  def initialize(gemname, existing_pkgbuild = nil)
    unless existing_pkgbuild.nil? || existing_pkgbuild.is_a?(String)
      fail Gembuild::InvalidPkgbuildError
    end

    @gemname = gemname
    @pkgname = "ruby-#{@gemname}"

    set_package_defaults

    no_parse_pkgbuild = existing_pkgbuild.nil? || existing_pkgbuild.empty?
    parse_existing_pkgbuild(existing_pkgbuild) unless no_parse_pkgbuild
  end

  # Parse the old pkgbuild (if it exists) to get information about old
  # maintainers or contributors or about other dependencies that have been
  # added but that can not be scraped from rubygems.org.
  #
  # @param pkgbuild [String] The old PKGBUILD to parse.
  # @return [Hash] a hash containing the values scraped from the PKGBUILD
  def parse_existing_pkgbuild(pkgbuild)
    pkgbuild.match(/^# Maintainer: (.*)$/) { |m| @maintainer = m[1] }

    @contributor = pkgbuild.scan(/^# Contributor: (.*)$/).flatten

    deps = parse_existing_dependencies(pkgbuild)
    deps.each do |dep|
      @depends << dep
    end

    { maintainer: maintainer, contributor: contributor, depends: deps }
  end

  # Create a new Pkgbuild instance with all information from the scraped
  # sources assigned.
  #
  # @param gemname [String] The rubygem for which to create a Pkgbuild.
  # @param existing_pkgbuild [String, nil] An old PKGBUILD that can be
  #   parsed for maintainer information.
  # @return [Gembuild::Pkgbuild] a new Pkgbuild instance
  def self.create(gemname, existing_pkgbuild = nil)
    pkgbuild = Pkgbuild.new(gemname, existing_pkgbuild)

    pkgbuild.fetch_maintainer

    gem_details = Gembuild::GemScraper.new(gemname).scrape!
    aur_details = Gembuild::AurScraper.new(pkgbuild.pkgname).scrape!

    pkgbuild.assign_gem_details(gem_details)
    pkgbuild.assign_aur_details(aur_details)

    pkgbuild
  end

  # Generate a PKGBUILD from the class using the pkgbuild erb template.
  #
  # @return [String] the PKGBUILD
  def render
    ERB.new(template, 0, '-').result(binding)
  end

  # Get the PKGBUILD erb template.
  #
  # @return [String] the pkgbuild erb template
  def template
    File.read(File.join(File.dirname(__FILE__), 'pkgbuild.erb'))
  end

  # Write the PKGBUILD to disk.
  #
  # @param path [String] The directory to write the PKGBUILD.
  # @return [Fixnum] the number of bytes written
  def write(path = '')
    File.write(File.join(File.expand_path(path), 'PKGBUILD'), render)
  end

  # Obfuscate the maintainer/contributors' email addresses to (help to)
  # prevent spam.
  #
  # @param contact_information [String] The maintainer or contributor
  #   byline.
  # @return [String] the information with the @s and .s exchanged
  def format_contact_information(contact_information)
    contact_information.gsub('@', ' at ').gsub('.', ' dot ')
  end

  # Set the correct maintainer for the PKGBUILD.
  #
  # If the current maintainer is nil (no old pkgbuild was passed), then do
  # nothing. If there is a maintainer then compare it to the configured
  # maintainer and if they are different then make the old maintainer a
  # contributor before setting the correct maintainer. If the maintainer is
  # nil then just set the confgured maintainer.
  #
  # @return [String] the pkgbuild maintainer
  def fetch_maintainer
    configured_maintainer = Gembuild.configure
    m = "#{configured_maintainer[:name]} <#{configured_maintainer[:email]}>"
    new_maintainer = format_contact_information(m)

    unless maintainer.nil? || new_maintainer == maintainer
      @contributor.unshift(maintainer)
    end

    @maintainer = new_maintainer
  end

  # Add the data scraped from rubygems.org to the pkgbuild.
  #
  # @param details [Hash] The results from GemScraper scrape.
  # @return [void]
  def assign_gem_details(details)
    @pkgver = details.fetch(:version)
    @description = details.fetch(:description)
    @checksum = details.fetch(:checksum)
    @license = details.fetch(:license)
    @url = details.fetch(:homepage)

    details.fetch(:dependencies).each do |dependency|
      @depends << "ruby-#{dependency}"
    end
  end

  # Assign version information based on the information gathered from the
  # AUR.
  #
  # @param details [Hash, nil] The results from AurScraper scrape or nil if
  #   the package does not yet exist on the AUR.
  # @return [void]
  def assign_aur_details(details)
    if details.nil?
      @epoch = 0
      @pkgrel = 1
    else
      perform_version_reconciliation(details)
    end
  end

  private

  # Set the static variables of a new pkgbuild.
  #
  # @return [nil]
  def set_package_defaults
    @checksum_type = 'sha256'
    @arch = ['any']
    @makedepends = ['rubygems']
    @depends = ['ruby']
    @source = ['https://rubygems.org/downloads/$_gemname-$pkgver.gem']
    @noextract = ['$_gemname-$pkgver.gem']
    @options = ['!emptydirs']
    @contributor = []

    nil
  end

  # Scrape dependencies from an existing pkgbuild.
  #
  # @param pkgbuild [String] The PKGBUILD to search.
  # @return [Array] all existing dependencies that are not ruby or gems
  def parse_existing_dependencies(pkgbuild)
    match = pkgbuild.match(/^depends=\((.*?)\)$/m)[1]

    # First step is to remove the leading and trailing quotes. Then convert
    # all whitespace (newlines, tabs, multiple spaces, etc.) to single
    # spaces. Then, make sure that strings are quoted with ' not ".
    # Finally, split the packages into an array.
    deps = match[1..-2].gsub(/[[:space:]]+/, ' ').tr('"', "'").split("' '")

    deps.reject { |e| e.match(/^ruby/) }
  rescue
    []
  end

  # Assign the correct pkgrel and epoch depending on the current pkgver on
  # the AUR and the version of the gem from rubygems.org.
  #
  # @param details [Hash] The results from AurScraper scrape
  # @return [void]
  def perform_version_reconciliation(details)
    @epoch = details.fetch(:epoch)
    @pkgrel = 1

    if pkgver < details.fetch(:pkgver)
      @epoch += 1
    elsif @pkgver == details.fetch(:pkgver)
      @pkgrel = details.fetch(:pkgrel) + 1
    end
  end
end

#makedependsArray

Returns a list of the dependencies needed to build the package (normally just the package rubygems).

Returns:

  • (Array)

    a list of the dependencies needed to build the package (normally just the package rubygems)

See Also:


78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/gembuild/pkgbuild.rb', line 78

class Pkgbuild
  attr_accessor :arch, :checksum, :checksum_type, :contributor, :depends,
                :description, :epoch, :gemname, :license, :maintainer,
                :makedepends, :noextract, :options, :pkgname, :pkgrel,
                :pkgver, :source, :url

  # Create a new Pkgbuild instance.
  #
  # @raise [Gembuild::InvalidPkgbuildError] if something other than a
  #   string or nil is passed as the existing pkgbuild
  #
  # @param gemname [String] The rubygem for which to create a PKGBUILD.
  # @param existing_pkgbuild [nil, String] An old PKGBUILD that can be
  #   parsed for maintainer and contributor information.
  # @return [Gembuild::Pkgbuild] a new Pkgbuild instance
  def initialize(gemname, existing_pkgbuild = nil)
    unless existing_pkgbuild.nil? || existing_pkgbuild.is_a?(String)
      fail Gembuild::InvalidPkgbuildError
    end

    @gemname = gemname
    @pkgname = "ruby-#{@gemname}"

    set_package_defaults

    no_parse_pkgbuild = existing_pkgbuild.nil? || existing_pkgbuild.empty?
    parse_existing_pkgbuild(existing_pkgbuild) unless no_parse_pkgbuild
  end

  # Parse the old pkgbuild (if it exists) to get information about old
  # maintainers or contributors or about other dependencies that have been
  # added but that can not be scraped from rubygems.org.
  #
  # @param pkgbuild [String] The old PKGBUILD to parse.
  # @return [Hash] a hash containing the values scraped from the PKGBUILD
  def parse_existing_pkgbuild(pkgbuild)
    pkgbuild.match(/^# Maintainer: (.*)$/) { |m| @maintainer = m[1] }

    @contributor = pkgbuild.scan(/^# Contributor: (.*)$/).flatten

    deps = parse_existing_dependencies(pkgbuild)
    deps.each do |dep|
      @depends << dep
    end

    { maintainer: maintainer, contributor: contributor, depends: deps }
  end

  # Create a new Pkgbuild instance with all information from the scraped
  # sources assigned.
  #
  # @param gemname [String] The rubygem for which to create a Pkgbuild.
  # @param existing_pkgbuild [String, nil] An old PKGBUILD that can be
  #   parsed for maintainer information.
  # @return [Gembuild::Pkgbuild] a new Pkgbuild instance
  def self.create(gemname, existing_pkgbuild = nil)
    pkgbuild = Pkgbuild.new(gemname, existing_pkgbuild)

    pkgbuild.fetch_maintainer

    gem_details = Gembuild::GemScraper.new(gemname).scrape!
    aur_details = Gembuild::AurScraper.new(pkgbuild.pkgname).scrape!

    pkgbuild.assign_gem_details(gem_details)
    pkgbuild.assign_aur_details(aur_details)

    pkgbuild
  end

  # Generate a PKGBUILD from the class using the pkgbuild erb template.
  #
  # @return [String] the PKGBUILD
  def render
    ERB.new(template, 0, '-').result(binding)
  end

  # Get the PKGBUILD erb template.
  #
  # @return [String] the pkgbuild erb template
  def template
    File.read(File.join(File.dirname(__FILE__), 'pkgbuild.erb'))
  end

  # Write the PKGBUILD to disk.
  #
  # @param path [String] The directory to write the PKGBUILD.
  # @return [Fixnum] the number of bytes written
  def write(path = '')
    File.write(File.join(File.expand_path(path), 'PKGBUILD'), render)
  end

  # Obfuscate the maintainer/contributors' email addresses to (help to)
  # prevent spam.
  #
  # @param contact_information [String] The maintainer or contributor
  #   byline.
  # @return [String] the information with the @s and .s exchanged
  def format_contact_information(contact_information)
    contact_information.gsub('@', ' at ').gsub('.', ' dot ')
  end

  # Set the correct maintainer for the PKGBUILD.
  #
  # If the current maintainer is nil (no old pkgbuild was passed), then do
  # nothing. If there is a maintainer then compare it to the configured
  # maintainer and if they are different then make the old maintainer a
  # contributor before setting the correct maintainer. If the maintainer is
  # nil then just set the confgured maintainer.
  #
  # @return [String] the pkgbuild maintainer
  def fetch_maintainer
    configured_maintainer = Gembuild.configure
    m = "#{configured_maintainer[:name]} <#{configured_maintainer[:email]}>"
    new_maintainer = format_contact_information(m)

    unless maintainer.nil? || new_maintainer == maintainer
      @contributor.unshift(maintainer)
    end

    @maintainer = new_maintainer
  end

  # Add the data scraped from rubygems.org to the pkgbuild.
  #
  # @param details [Hash] The results from GemScraper scrape.
  # @return [void]
  def assign_gem_details(details)
    @pkgver = details.fetch(:version)
    @description = details.fetch(:description)
    @checksum = details.fetch(:checksum)
    @license = details.fetch(:license)
    @url = details.fetch(:homepage)

    details.fetch(:dependencies).each do |dependency|
      @depends << "ruby-#{dependency}"
    end
  end

  # Assign version information based on the information gathered from the
  # AUR.
  #
  # @param details [Hash, nil] The results from AurScraper scrape or nil if
  #   the package does not yet exist on the AUR.
  # @return [void]
  def assign_aur_details(details)
    if details.nil?
      @epoch = 0
      @pkgrel = 1
    else
      perform_version_reconciliation(details)
    end
  end

  private

  # Set the static variables of a new pkgbuild.
  #
  # @return [nil]
  def set_package_defaults
    @checksum_type = 'sha256'
    @arch = ['any']
    @makedepends = ['rubygems']
    @depends = ['ruby']
    @source = ['https://rubygems.org/downloads/$_gemname-$pkgver.gem']
    @noextract = ['$_gemname-$pkgver.gem']
    @options = ['!emptydirs']
    @contributor = []

    nil
  end

  # Scrape dependencies from an existing pkgbuild.
  #
  # @param pkgbuild [String] The PKGBUILD to search.
  # @return [Array] all existing dependencies that are not ruby or gems
  def parse_existing_dependencies(pkgbuild)
    match = pkgbuild.match(/^depends=\((.*?)\)$/m)[1]

    # First step is to remove the leading and trailing quotes. Then convert
    # all whitespace (newlines, tabs, multiple spaces, etc.) to single
    # spaces. Then, make sure that strings are quoted with ' not ".
    # Finally, split the packages into an array.
    deps = match[1..-2].gsub(/[[:space:]]+/, ' ').tr('"', "'").split("' '")

    deps.reject { |e| e.match(/^ruby/) }
  rescue
    []
  end

  # Assign the correct pkgrel and epoch depending on the current pkgver on
  # the AUR and the version of the gem from rubygems.org.
  #
  # @param details [Hash] The results from AurScraper scrape
  # @return [void]
  def perform_version_reconciliation(details)
    @epoch = details.fetch(:epoch)
    @pkgrel = 1

    if pkgver < details.fetch(:pkgver)
      @epoch += 1
    elsif @pkgver == details.fetch(:pkgver)
      @pkgrel = details.fetch(:pkgrel) + 1
    end
  end
end

#noextractArray

Returns a list of sources not to extract with bsdtar (namely, the gemfile).

Returns:

  • (Array)

    a list of sources not to extract with bsdtar (namely, the gemfile)

See Also:


78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/gembuild/pkgbuild.rb', line 78

class Pkgbuild
  attr_accessor :arch, :checksum, :checksum_type, :contributor, :depends,
                :description, :epoch, :gemname, :license, :maintainer,
                :makedepends, :noextract, :options, :pkgname, :pkgrel,
                :pkgver, :source, :url

  # Create a new Pkgbuild instance.
  #
  # @raise [Gembuild::InvalidPkgbuildError] if something other than a
  #   string or nil is passed as the existing pkgbuild
  #
  # @param gemname [String] The rubygem for which to create a PKGBUILD.
  # @param existing_pkgbuild [nil, String] An old PKGBUILD that can be
  #   parsed for maintainer and contributor information.
  # @return [Gembuild::Pkgbuild] a new Pkgbuild instance
  def initialize(gemname, existing_pkgbuild = nil)
    unless existing_pkgbuild.nil? || existing_pkgbuild.is_a?(String)
      fail Gembuild::InvalidPkgbuildError
    end

    @gemname = gemname
    @pkgname = "ruby-#{@gemname}"

    set_package_defaults

    no_parse_pkgbuild = existing_pkgbuild.nil? || existing_pkgbuild.empty?
    parse_existing_pkgbuild(existing_pkgbuild) unless no_parse_pkgbuild
  end

  # Parse the old pkgbuild (if it exists) to get information about old
  # maintainers or contributors or about other dependencies that have been
  # added but that can not be scraped from rubygems.org.
  #
  # @param pkgbuild [String] The old PKGBUILD to parse.
  # @return [Hash] a hash containing the values scraped from the PKGBUILD
  def parse_existing_pkgbuild(pkgbuild)
    pkgbuild.match(/^# Maintainer: (.*)$/) { |m| @maintainer = m[1] }

    @contributor = pkgbuild.scan(/^# Contributor: (.*)$/).flatten

    deps = parse_existing_dependencies(pkgbuild)
    deps.each do |dep|
      @depends << dep
    end

    { maintainer: maintainer, contributor: contributor, depends: deps }
  end

  # Create a new Pkgbuild instance with all information from the scraped
  # sources assigned.
  #
  # @param gemname [String] The rubygem for which to create a Pkgbuild.
  # @param existing_pkgbuild [String, nil] An old PKGBUILD that can be
  #   parsed for maintainer information.
  # @return [Gembuild::Pkgbuild] a new Pkgbuild instance
  def self.create(gemname, existing_pkgbuild = nil)
    pkgbuild = Pkgbuild.new(gemname, existing_pkgbuild)

    pkgbuild.fetch_maintainer

    gem_details = Gembuild::GemScraper.new(gemname).scrape!
    aur_details = Gembuild::AurScraper.new(pkgbuild.pkgname).scrape!

    pkgbuild.assign_gem_details(gem_details)
    pkgbuild.assign_aur_details(aur_details)

    pkgbuild
  end

  # Generate a PKGBUILD from the class using the pkgbuild erb template.
  #
  # @return [String] the PKGBUILD
  def render
    ERB.new(template, 0, '-').result(binding)
  end

  # Get the PKGBUILD erb template.
  #
  # @return [String] the pkgbuild erb template
  def template
    File.read(File.join(File.dirname(__FILE__), 'pkgbuild.erb'))
  end

  # Write the PKGBUILD to disk.
  #
  # @param path [String] The directory to write the PKGBUILD.
  # @return [Fixnum] the number of bytes written
  def write(path = '')
    File.write(File.join(File.expand_path(path), 'PKGBUILD'), render)
  end

  # Obfuscate the maintainer/contributors' email addresses to (help to)
  # prevent spam.
  #
  # @param contact_information [String] The maintainer or contributor
  #   byline.
  # @return [String] the information with the @s and .s exchanged
  def format_contact_information(contact_information)
    contact_information.gsub('@', ' at ').gsub('.', ' dot ')
  end

  # Set the correct maintainer for the PKGBUILD.
  #
  # If the current maintainer is nil (no old pkgbuild was passed), then do
  # nothing. If there is a maintainer then compare it to the configured
  # maintainer and if they are different then make the old maintainer a
  # contributor before setting the correct maintainer. If the maintainer is
  # nil then just set the confgured maintainer.
  #
  # @return [String] the pkgbuild maintainer
  def fetch_maintainer
    configured_maintainer = Gembuild.configure
    m = "#{configured_maintainer[:name]} <#{configured_maintainer[:email]}>"
    new_maintainer = format_contact_information(m)

    unless maintainer.nil? || new_maintainer == maintainer
      @contributor.unshift(maintainer)
    end

    @maintainer = new_maintainer
  end

  # Add the data scraped from rubygems.org to the pkgbuild.
  #
  # @param details [Hash] The results from GemScraper scrape.
  # @return [void]
  def assign_gem_details(details)
    @pkgver = details.fetch(:version)
    @description = details.fetch(:description)
    @checksum = details.fetch(:checksum)
    @license = details.fetch(:license)
    @url = details.fetch(:homepage)

    details.fetch(:dependencies).each do |dependency|
      @depends << "ruby-#{dependency}"
    end
  end

  # Assign version information based on the information gathered from the
  # AUR.
  #
  # @param details [Hash, nil] The results from AurScraper scrape or nil if
  #   the package does not yet exist on the AUR.
  # @return [void]
  def assign_aur_details(details)
    if details.nil?
      @epoch = 0
      @pkgrel = 1
    else
      perform_version_reconciliation(details)
    end
  end

  private

  # Set the static variables of a new pkgbuild.
  #
  # @return [nil]
  def set_package_defaults
    @checksum_type = 'sha256'
    @arch = ['any']
    @makedepends = ['rubygems']
    @depends = ['ruby']
    @source = ['https://rubygems.org/downloads/$_gemname-$pkgver.gem']
    @noextract = ['$_gemname-$pkgver.gem']
    @options = ['!emptydirs']
    @contributor = []

    nil
  end

  # Scrape dependencies from an existing pkgbuild.
  #
  # @param pkgbuild [String] The PKGBUILD to search.
  # @return [Array] all existing dependencies that are not ruby or gems
  def parse_existing_dependencies(pkgbuild)
    match = pkgbuild.match(/^depends=\((.*?)\)$/m)[1]

    # First step is to remove the leading and trailing quotes. Then convert
    # all whitespace (newlines, tabs, multiple spaces, etc.) to single
    # spaces. Then, make sure that strings are quoted with ' not ".
    # Finally, split the packages into an array.
    deps = match[1..-2].gsub(/[[:space:]]+/, ' ').tr('"', "'").split("' '")

    deps.reject { |e| e.match(/^ruby/) }
  rescue
    []
  end

  # Assign the correct pkgrel and epoch depending on the current pkgver on
  # the AUR and the version of the gem from rubygems.org.
  #
  # @param details [Hash] The results from AurScraper scrape
  # @return [void]
  def perform_version_reconciliation(details)
    @epoch = details.fetch(:epoch)
    @pkgrel = 1

    if pkgver < details.fetch(:pkgver)
      @epoch += 1
    elsif @pkgver == details.fetch(:pkgver)
      @pkgrel = details.fetch(:pkgrel) + 1
    end
  end
end

#optionsArray

Returns a list of options to pass to makepkg.

Returns:

  • (Array)

    a list of options to pass to makepkg

See Also:


78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/gembuild/pkgbuild.rb', line 78

class Pkgbuild
  attr_accessor :arch, :checksum, :checksum_type, :contributor, :depends,
                :description, :epoch, :gemname, :license, :maintainer,
                :makedepends, :noextract, :options, :pkgname, :pkgrel,
                :pkgver, :source, :url

  # Create a new Pkgbuild instance.
  #
  # @raise [Gembuild::InvalidPkgbuildError] if something other than a
  #   string or nil is passed as the existing pkgbuild
  #
  # @param gemname [String] The rubygem for which to create a PKGBUILD.
  # @param existing_pkgbuild [nil, String] An old PKGBUILD that can be
  #   parsed for maintainer and contributor information.
  # @return [Gembuild::Pkgbuild] a new Pkgbuild instance
  def initialize(gemname, existing_pkgbuild = nil)
    unless existing_pkgbuild.nil? || existing_pkgbuild.is_a?(String)
      fail Gembuild::InvalidPkgbuildError
    end

    @gemname = gemname
    @pkgname = "ruby-#{@gemname}"

    set_package_defaults

    no_parse_pkgbuild = existing_pkgbuild.nil? || existing_pkgbuild.empty?
    parse_existing_pkgbuild(existing_pkgbuild) unless no_parse_pkgbuild
  end

  # Parse the old pkgbuild (if it exists) to get information about old
  # maintainers or contributors or about other dependencies that have been
  # added but that can not be scraped from rubygems.org.
  #
  # @param pkgbuild [String] The old PKGBUILD to parse.
  # @return [Hash] a hash containing the values scraped from the PKGBUILD
  def parse_existing_pkgbuild(pkgbuild)
    pkgbuild.match(/^# Maintainer: (.*)$/) { |m| @maintainer = m[1] }

    @contributor = pkgbuild.scan(/^# Contributor: (.*)$/).flatten

    deps = parse_existing_dependencies(pkgbuild)
    deps.each do |dep|
      @depends << dep
    end

    { maintainer: maintainer, contributor: contributor, depends: deps }
  end

  # Create a new Pkgbuild instance with all information from the scraped
  # sources assigned.
  #
  # @param gemname [String] The rubygem for which to create a Pkgbuild.
  # @param existing_pkgbuild [String, nil] An old PKGBUILD that can be
  #   parsed for maintainer information.
  # @return [Gembuild::Pkgbuild] a new Pkgbuild instance
  def self.create(gemname, existing_pkgbuild = nil)
    pkgbuild = Pkgbuild.new(gemname, existing_pkgbuild)

    pkgbuild.fetch_maintainer

    gem_details = Gembuild::GemScraper.new(gemname).scrape!
    aur_details = Gembuild::AurScraper.new(pkgbuild.pkgname).scrape!

    pkgbuild.assign_gem_details(gem_details)
    pkgbuild.assign_aur_details(aur_details)

    pkgbuild
  end

  # Generate a PKGBUILD from the class using the pkgbuild erb template.
  #
  # @return [String] the PKGBUILD
  def render
    ERB.new(template, 0, '-').result(binding)
  end

  # Get the PKGBUILD erb template.
  #
  # @return [String] the pkgbuild erb template
  def template
    File.read(File.join(File.dirname(__FILE__), 'pkgbuild.erb'))
  end

  # Write the PKGBUILD to disk.
  #
  # @param path [String] The directory to write the PKGBUILD.
  # @return [Fixnum] the number of bytes written
  def write(path = '')
    File.write(File.join(File.expand_path(path), 'PKGBUILD'), render)
  end

  # Obfuscate the maintainer/contributors' email addresses to (help to)
  # prevent spam.
  #
  # @param contact_information [String] The maintainer or contributor
  #   byline.
  # @return [String] the information with the @s and .s exchanged
  def format_contact_information(contact_information)
    contact_information.gsub('@', ' at ').gsub('.', ' dot ')
  end

  # Set the correct maintainer for the PKGBUILD.
  #
  # If the current maintainer is nil (no old pkgbuild was passed), then do
  # nothing. If there is a maintainer then compare it to the configured
  # maintainer and if they are different then make the old maintainer a
  # contributor before setting the correct maintainer. If the maintainer is
  # nil then just set the confgured maintainer.
  #
  # @return [String] the pkgbuild maintainer
  def fetch_maintainer
    configured_maintainer = Gembuild.configure
    m = "#{configured_maintainer[:name]} <#{configured_maintainer[:email]}>"
    new_maintainer = format_contact_information(m)

    unless maintainer.nil? || new_maintainer == maintainer
      @contributor.unshift(maintainer)
    end

    @maintainer = new_maintainer
  end

  # Add the data scraped from rubygems.org to the pkgbuild.
  #
  # @param details [Hash] The results from GemScraper scrape.
  # @return [void]
  def assign_gem_details(details)
    @pkgver = details.fetch(:version)
    @description = details.fetch(:description)
    @checksum = details.fetch(:checksum)
    @license = details.fetch(:license)
    @url = details.fetch(:homepage)

    details.fetch(:dependencies).each do |dependency|
      @depends << "ruby-#{dependency}"
    end
  end

  # Assign version information based on the information gathered from the
  # AUR.
  #
  # @param details [Hash, nil] The results from AurScraper scrape or nil if
  #   the package does not yet exist on the AUR.
  # @return [void]
  def assign_aur_details(details)
    if details.nil?
      @epoch = 0
      @pkgrel = 1
    else
      perform_version_reconciliation(details)
    end
  end

  private

  # Set the static variables of a new pkgbuild.
  #
  # @return [nil]
  def set_package_defaults
    @checksum_type = 'sha256'
    @arch = ['any']
    @makedepends = ['rubygems']
    @depends = ['ruby']
    @source = ['https://rubygems.org/downloads/$_gemname-$pkgver.gem']
    @noextract = ['$_gemname-$pkgver.gem']
    @options = ['!emptydirs']
    @contributor = []

    nil
  end

  # Scrape dependencies from an existing pkgbuild.
  #
  # @param pkgbuild [String] The PKGBUILD to search.
  # @return [Array] all existing dependencies that are not ruby or gems
  def parse_existing_dependencies(pkgbuild)
    match = pkgbuild.match(/^depends=\((.*?)\)$/m)[1]

    # First step is to remove the leading and trailing quotes. Then convert
    # all whitespace (newlines, tabs, multiple spaces, etc.) to single
    # spaces. Then, make sure that strings are quoted with ' not ".
    # Finally, split the packages into an array.
    deps = match[1..-2].gsub(/[[:space:]]+/, ' ').tr('"', "'").split("' '")

    deps.reject { |e| e.match(/^ruby/) }
  rescue
    []
  end

  # Assign the correct pkgrel and epoch depending on the current pkgver on
  # the AUR and the version of the gem from rubygems.org.
  #
  # @param details [Hash] The results from AurScraper scrape
  # @return [void]
  def perform_version_reconciliation(details)
    @epoch = details.fetch(:epoch)
    @pkgrel = 1

    if pkgver < details.fetch(:pkgver)
      @epoch += 1
    elsif @pkgver == details.fetch(:pkgver)
      @pkgrel = details.fetch(:pkgrel) + 1
    end
  end
end

#pkgnameString

Returns the name of the package (usually ruby-gem).

Returns:

  • (String)

    the name of the package (usually ruby-gem)

See Also:


78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/gembuild/pkgbuild.rb', line 78

class Pkgbuild
  attr_accessor :arch, :checksum, :checksum_type, :contributor, :depends,
                :description, :epoch, :gemname, :license, :maintainer,
                :makedepends, :noextract, :options, :pkgname, :pkgrel,
                :pkgver, :source, :url

  # Create a new Pkgbuild instance.
  #
  # @raise [Gembuild::InvalidPkgbuildError] if something other than a
  #   string or nil is passed as the existing pkgbuild
  #
  # @param gemname [String] The rubygem for which to create a PKGBUILD.
  # @param existing_pkgbuild [nil, String] An old PKGBUILD that can be
  #   parsed for maintainer and contributor information.
  # @return [Gembuild::Pkgbuild] a new Pkgbuild instance
  def initialize(gemname, existing_pkgbuild = nil)
    unless existing_pkgbuild.nil? || existing_pkgbuild.is_a?(String)
      fail Gembuild::InvalidPkgbuildError
    end

    @gemname = gemname
    @pkgname = "ruby-#{@gemname}"

    set_package_defaults

    no_parse_pkgbuild = existing_pkgbuild.nil? || existing_pkgbuild.empty?
    parse_existing_pkgbuild(existing_pkgbuild) unless no_parse_pkgbuild
  end

  # Parse the old pkgbuild (if it exists) to get information about old
  # maintainers or contributors or about other dependencies that have been
  # added but that can not be scraped from rubygems.org.
  #
  # @param pkgbuild [String] The old PKGBUILD to parse.
  # @return [Hash] a hash containing the values scraped from the PKGBUILD
  def parse_existing_pkgbuild(pkgbuild)
    pkgbuild.match(/^# Maintainer: (.*)$/) { |m| @maintainer = m[1] }

    @contributor = pkgbuild.scan(/^# Contributor: (.*)$/).flatten

    deps = parse_existing_dependencies(pkgbuild)
    deps.each do |dep|
      @depends << dep
    end

    { maintainer: maintainer, contributor: contributor, depends: deps }
  end

  # Create a new Pkgbuild instance with all information from the scraped
  # sources assigned.
  #
  # @param gemname [String] The rubygem for which to create a Pkgbuild.
  # @param existing_pkgbuild [String, nil] An old PKGBUILD that can be
  #   parsed for maintainer information.
  # @return [Gembuild::Pkgbuild] a new Pkgbuild instance
  def self.create(gemname, existing_pkgbuild = nil)
    pkgbuild = Pkgbuild.new(gemname, existing_pkgbuild)

    pkgbuild.fetch_maintainer

    gem_details = Gembuild::GemScraper.new(gemname).scrape!
    aur_details = Gembuild::AurScraper.new(pkgbuild.pkgname).scrape!

    pkgbuild.assign_gem_details(gem_details)
    pkgbuild.assign_aur_details(aur_details)

    pkgbuild
  end

  # Generate a PKGBUILD from the class using the pkgbuild erb template.
  #
  # @return [String] the PKGBUILD
  def render
    ERB.new(template, 0, '-').result(binding)
  end

  # Get the PKGBUILD erb template.
  #
  # @return [String] the pkgbuild erb template
  def template
    File.read(File.join(File.dirname(__FILE__), 'pkgbuild.erb'))
  end

  # Write the PKGBUILD to disk.
  #
  # @param path [String] The directory to write the PKGBUILD.
  # @return [Fixnum] the number of bytes written
  def write(path = '')
    File.write(File.join(File.expand_path(path), 'PKGBUILD'), render)
  end

  # Obfuscate the maintainer/contributors' email addresses to (help to)
  # prevent spam.
  #
  # @param contact_information [String] The maintainer or contributor
  #   byline.
  # @return [String] the information with the @s and .s exchanged
  def format_contact_information(contact_information)
    contact_information.gsub('@', ' at ').gsub('.', ' dot ')
  end

  # Set the correct maintainer for the PKGBUILD.
  #
  # If the current maintainer is nil (no old pkgbuild was passed), then do
  # nothing. If there is a maintainer then compare it to the configured
  # maintainer and if they are different then make the old maintainer a
  # contributor before setting the correct maintainer. If the maintainer is
  # nil then just set the confgured maintainer.
  #
  # @return [String] the pkgbuild maintainer
  def fetch_maintainer
    configured_maintainer = Gembuild.configure
    m = "#{configured_maintainer[:name]} <#{configured_maintainer[:email]}>"
    new_maintainer = format_contact_information(m)

    unless maintainer.nil? || new_maintainer == maintainer
      @contributor.unshift(maintainer)
    end

    @maintainer = new_maintainer
  end

  # Add the data scraped from rubygems.org to the pkgbuild.
  #
  # @param details [Hash] The results from GemScraper scrape.
  # @return [void]
  def assign_gem_details(details)
    @pkgver = details.fetch(:version)
    @description = details.fetch(:description)
    @checksum = details.fetch(:checksum)
    @license = details.fetch(:license)
    @url = details.fetch(:homepage)

    details.fetch(:dependencies).each do |dependency|
      @depends << "ruby-#{dependency}"
    end
  end

  # Assign version information based on the information gathered from the
  # AUR.
  #
  # @param details [Hash, nil] The results from AurScraper scrape or nil if
  #   the package does not yet exist on the AUR.
  # @return [void]
  def assign_aur_details(details)
    if details.nil?
      @epoch = 0
      @pkgrel = 1
    else
      perform_version_reconciliation(details)
    end
  end

  private

  # Set the static variables of a new pkgbuild.
  #
  # @return [nil]
  def set_package_defaults
    @checksum_type = 'sha256'
    @arch = ['any']
    @makedepends = ['rubygems']
    @depends = ['ruby']
    @source = ['https://rubygems.org/downloads/$_gemname-$pkgver.gem']
    @noextract = ['$_gemname-$pkgver.gem']
    @options = ['!emptydirs']
    @contributor = []

    nil
  end

  # Scrape dependencies from an existing pkgbuild.
  #
  # @param pkgbuild [String] The PKGBUILD to search.
  # @return [Array] all existing dependencies that are not ruby or gems
  def parse_existing_dependencies(pkgbuild)
    match = pkgbuild.match(/^depends=\((.*?)\)$/m)[1]

    # First step is to remove the leading and trailing quotes. Then convert
    # all whitespace (newlines, tabs, multiple spaces, etc.) to single
    # spaces. Then, make sure that strings are quoted with ' not ".
    # Finally, split the packages into an array.
    deps = match[1..-2].gsub(/[[:space:]]+/, ' ').tr('"', "'").split("' '")

    deps.reject { |e| e.match(/^ruby/) }
  rescue
    []
  end

  # Assign the correct pkgrel and epoch depending on the current pkgver on
  # the AUR and the version of the gem from rubygems.org.
  #
  # @param details [Hash] The results from AurScraper scrape
  # @return [void]
  def perform_version_reconciliation(details)
    @epoch = details.fetch(:epoch)
    @pkgrel = 1

    if pkgver < details.fetch(:pkgver)
      @epoch += 1
    elsif @pkgver == details.fetch(:pkgver)
      @pkgrel = details.fetch(:pkgrel) + 1
    end
  end
end

#pkgrelFixnum

Returns the release number of the package.

Returns:

  • (Fixnum)

    the release number of the package

See Also:


78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/gembuild/pkgbuild.rb', line 78

class Pkgbuild
  attr_accessor :arch, :checksum, :checksum_type, :contributor, :depends,
                :description, :epoch, :gemname, :license, :maintainer,
                :makedepends, :noextract, :options, :pkgname, :pkgrel,
                :pkgver, :source, :url

  # Create a new Pkgbuild instance.
  #
  # @raise [Gembuild::InvalidPkgbuildError] if something other than a
  #   string or nil is passed as the existing pkgbuild
  #
  # @param gemname [String] The rubygem for which to create a PKGBUILD.
  # @param existing_pkgbuild [nil, String] An old PKGBUILD that can be
  #   parsed for maintainer and contributor information.
  # @return [Gembuild::Pkgbuild] a new Pkgbuild instance
  def initialize(gemname, existing_pkgbuild = nil)
    unless existing_pkgbuild.nil? || existing_pkgbuild.is_a?(String)
      fail Gembuild::InvalidPkgbuildError
    end

    @gemname = gemname
    @pkgname = "ruby-#{@gemname}"

    set_package_defaults

    no_parse_pkgbuild = existing_pkgbuild.nil? || existing_pkgbuild.empty?
    parse_existing_pkgbuild(existing_pkgbuild) unless no_parse_pkgbuild
  end

  # Parse the old pkgbuild (if it exists) to get information about old
  # maintainers or contributors or about other dependencies that have been
  # added but that can not be scraped from rubygems.org.
  #
  # @param pkgbuild [String] The old PKGBUILD to parse.
  # @return [Hash] a hash containing the values scraped from the PKGBUILD
  def parse_existing_pkgbuild(pkgbuild)
    pkgbuild.match(/^# Maintainer: (.*)$/) { |m| @maintainer = m[1] }

    @contributor = pkgbuild.scan(/^# Contributor: (.*)$/).flatten

    deps = parse_existing_dependencies(pkgbuild)
    deps.each do |dep|
      @depends << dep
    end

    { maintainer: maintainer, contributor: contributor, depends: deps }
  end

  # Create a new Pkgbuild instance with all information from the scraped
  # sources assigned.
  #
  # @param gemname [String] The rubygem for which to create a Pkgbuild.
  # @param existing_pkgbuild [String, nil] An old PKGBUILD that can be
  #   parsed for maintainer information.
  # @return [Gembuild::Pkgbuild] a new Pkgbuild instance
  def self.create(gemname, existing_pkgbuild = nil)
    pkgbuild = Pkgbuild.new(gemname, existing_pkgbuild)

    pkgbuild.fetch_maintainer

    gem_details = Gembuild::GemScraper.new(gemname).scrape!
    aur_details = Gembuild::AurScraper.new(pkgbuild.pkgname).scrape!

    pkgbuild.assign_gem_details(gem_details)
    pkgbuild.assign_aur_details(aur_details)

    pkgbuild
  end

  # Generate a PKGBUILD from the class using the pkgbuild erb template.
  #
  # @return [String] the PKGBUILD
  def render
    ERB.new(template, 0, '-').result(binding)
  end

  # Get the PKGBUILD erb template.
  #
  # @return [String] the pkgbuild erb template
  def template
    File.read(File.join(File.dirname(__FILE__), 'pkgbuild.erb'))
  end

  # Write the PKGBUILD to disk.
  #
  # @param path [String] The directory to write the PKGBUILD.
  # @return [Fixnum] the number of bytes written
  def write(path = '')
    File.write(File.join(File.expand_path(path), 'PKGBUILD'), render)
  end

  # Obfuscate the maintainer/contributors' email addresses to (help to)
  # prevent spam.
  #
  # @param contact_information [String] The maintainer or contributor
  #   byline.
  # @return [String] the information with the @s and .s exchanged
  def format_contact_information(contact_information)
    contact_information.gsub('@', ' at ').gsub('.', ' dot ')
  end

  # Set the correct maintainer for the PKGBUILD.
  #
  # If the current maintainer is nil (no old pkgbuild was passed), then do
  # nothing. If there is a maintainer then compare it to the configured
  # maintainer and if they are different then make the old maintainer a
  # contributor before setting the correct maintainer. If the maintainer is
  # nil then just set the confgured maintainer.
  #
  # @return [String] the pkgbuild maintainer
  def fetch_maintainer
    configured_maintainer = Gembuild.configure
    m = "#{configured_maintainer[:name]} <#{configured_maintainer[:email]}>"
    new_maintainer = format_contact_information(m)

    unless maintainer.nil? || new_maintainer == maintainer
      @contributor.unshift(maintainer)
    end

    @maintainer = new_maintainer
  end

  # Add the data scraped from rubygems.org to the pkgbuild.
  #
  # @param details [Hash] The results from GemScraper scrape.
  # @return [void]
  def assign_gem_details(details)
    @pkgver = details.fetch(:version)
    @description = details.fetch(:description)
    @checksum = details.fetch(:checksum)
    @license = details.fetch(:license)
    @url = details.fetch(:homepage)

    details.fetch(:dependencies).each do |dependency|
      @depends << "ruby-#{dependency}"
    end
  end

  # Assign version information based on the information gathered from the
  # AUR.
  #
  # @param details [Hash, nil] The results from AurScraper scrape or nil if
  #   the package does not yet exist on the AUR.
  # @return [void]
  def assign_aur_details(details)
    if details.nil?
      @epoch = 0
      @pkgrel = 1
    else
      perform_version_reconciliation(details)
    end
  end

  private

  # Set the static variables of a new pkgbuild.
  #
  # @return [nil]
  def set_package_defaults
    @checksum_type = 'sha256'
    @arch = ['any']
    @makedepends = ['rubygems']
    @depends = ['ruby']
    @source = ['https://rubygems.org/downloads/$_gemname-$pkgver.gem']
    @noextract = ['$_gemname-$pkgver.gem']
    @options = ['!emptydirs']
    @contributor = []

    nil
  end

  # Scrape dependencies from an existing pkgbuild.
  #
  # @param pkgbuild [String] The PKGBUILD to search.
  # @return [Array] all existing dependencies that are not ruby or gems
  def parse_existing_dependencies(pkgbuild)
    match = pkgbuild.match(/^depends=\((.*?)\)$/m)[1]

    # First step is to remove the leading and trailing quotes. Then convert
    # all whitespace (newlines, tabs, multiple spaces, etc.) to single
    # spaces. Then, make sure that strings are quoted with ' not ".
    # Finally, split the packages into an array.
    deps = match[1..-2].gsub(/[[:space:]]+/, ' ').tr('"', "'").split("' '")

    deps.reject { |e| e.match(/^ruby/) }
  rescue
    []
  end

  # Assign the correct pkgrel and epoch depending on the current pkgver on
  # the AUR and the version of the gem from rubygems.org.
  #
  # @param details [Hash] The results from AurScraper scrape
  # @return [void]
  def perform_version_reconciliation(details)
    @epoch = details.fetch(:epoch)
    @pkgrel = 1

    if pkgver < details.fetch(:pkgver)
      @epoch += 1
    elsif @pkgver == details.fetch(:pkgver)
      @pkgrel = details.fetch(:pkgrel) + 1
    end
  end
end

#pkgverGem::Version

Returns the version of the gem.

Returns:

  • (Gem::Version)

    the version of the gem

See Also:


78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/gembuild/pkgbuild.rb', line 78

class Pkgbuild
  attr_accessor :arch, :checksum, :checksum_type, :contributor, :depends,
                :description, :epoch, :gemname, :license, :maintainer,
                :makedepends, :noextract, :options, :pkgname, :pkgrel,
                :pkgver, :source, :url

  # Create a new Pkgbuild instance.
  #
  # @raise [Gembuild::InvalidPkgbuildError] if something other than a
  #   string or nil is passed as the existing pkgbuild
  #
  # @param gemname [String] The rubygem for which to create a PKGBUILD.
  # @param existing_pkgbuild [nil, String] An old PKGBUILD that can be
  #   parsed for maintainer and contributor information.
  # @return [Gembuild::Pkgbuild] a new Pkgbuild instance
  def initialize(gemname, existing_pkgbuild = nil)
    unless existing_pkgbuild.nil? || existing_pkgbuild.is_a?(String)
      fail Gembuild::InvalidPkgbuildError
    end

    @gemname = gemname
    @pkgname = "ruby-#{@gemname}"

    set_package_defaults

    no_parse_pkgbuild = existing_pkgbuild.nil? || existing_pkgbuild.empty?
    parse_existing_pkgbuild(existing_pkgbuild) unless no_parse_pkgbuild
  end

  # Parse the old pkgbuild (if it exists) to get information about old
  # maintainers or contributors or about other dependencies that have been
  # added but that can not be scraped from rubygems.org.
  #
  # @param pkgbuild [String] The old PKGBUILD to parse.
  # @return [Hash] a hash containing the values scraped from the PKGBUILD
  def parse_existing_pkgbuild(pkgbuild)
    pkgbuild.match(/^# Maintainer: (.*)$/) { |m| @maintainer = m[1] }

    @contributor = pkgbuild.scan(/^# Contributor: (.*)$/).flatten

    deps = parse_existing_dependencies(pkgbuild)
    deps.each do |dep|
      @depends << dep
    end

    { maintainer: maintainer, contributor: contributor, depends: deps }
  end

  # Create a new Pkgbuild instance with all information from the scraped
  # sources assigned.
  #
  # @param gemname [String] The rubygem for which to create a Pkgbuild.
  # @param existing_pkgbuild [String, nil] An old PKGBUILD that can be
  #   parsed for maintainer information.
  # @return [Gembuild::Pkgbuild] a new Pkgbuild instance
  def self.create(gemname, existing_pkgbuild = nil)
    pkgbuild = Pkgbuild.new(gemname, existing_pkgbuild)

    pkgbuild.fetch_maintainer

    gem_details = Gembuild::GemScraper.new(gemname).scrape!
    aur_details = Gembuild::AurScraper.new(pkgbuild.pkgname).scrape!

    pkgbuild.assign_gem_details(gem_details)
    pkgbuild.assign_aur_details(aur_details)

    pkgbuild
  end

  # Generate a PKGBUILD from the class using the pkgbuild erb template.
  #
  # @return [String] the PKGBUILD
  def render
    ERB.new(template, 0, '-').result(binding)
  end

  # Get the PKGBUILD erb template.
  #
  # @return [String] the pkgbuild erb template
  def template
    File.read(File.join(File.dirname(__FILE__), 'pkgbuild.erb'))
  end

  # Write the PKGBUILD to disk.
  #
  # @param path [String] The directory to write the PKGBUILD.
  # @return [Fixnum] the number of bytes written
  def write(path = '')
    File.write(File.join(File.expand_path(path), 'PKGBUILD'), render)
  end

  # Obfuscate the maintainer/contributors' email addresses to (help to)
  # prevent spam.
  #
  # @param contact_information [String] The maintainer or contributor
  #   byline.
  # @return [String] the information with the @s and .s exchanged
  def format_contact_information(contact_information)
    contact_information.gsub('@', ' at ').gsub('.', ' dot ')
  end

  # Set the correct maintainer for the PKGBUILD.
  #
  # If the current maintainer is nil (no old pkgbuild was passed), then do
  # nothing. If there is a maintainer then compare it to the configured
  # maintainer and if they are different then make the old maintainer a
  # contributor before setting the correct maintainer. If the maintainer is
  # nil then just set the confgured maintainer.
  #
  # @return [String] the pkgbuild maintainer
  def fetch_maintainer
    configured_maintainer = Gembuild.configure
    m = "#{configured_maintainer[:name]} <#{configured_maintainer[:email]}>"
    new_maintainer = format_contact_information(m)

    unless maintainer.nil? || new_maintainer == maintainer
      @contributor.unshift(maintainer)
    end

    @maintainer = new_maintainer
  end

  # Add the data scraped from rubygems.org to the pkgbuild.
  #
  # @param details [Hash] The results from GemScraper scrape.
  # @return [void]
  def assign_gem_details(details)
    @pkgver = details.fetch(:version)
    @description = details.fetch(:description)
    @checksum = details.fetch(:checksum)
    @license = details.fetch(:license)
    @url = details.fetch(:homepage)

    details.fetch(:dependencies).each do |dependency|
      @depends << "ruby-#{dependency}"
    end
  end

  # Assign version information based on the information gathered from the
  # AUR.
  #
  # @param details [Hash, nil] The results from AurScraper scrape or nil if
  #   the package does not yet exist on the AUR.
  # @return [void]
  def assign_aur_details(details)
    if details.nil?
      @epoch = 0
      @pkgrel = 1
    else
      perform_version_reconciliation(details)
    end
  end

  private

  # Set the static variables of a new pkgbuild.
  #
  # @return [nil]
  def set_package_defaults
    @checksum_type = 'sha256'
    @arch = ['any']
    @makedepends = ['rubygems']
    @depends = ['ruby']
    @source = ['https://rubygems.org/downloads/$_gemname-$pkgver.gem']
    @noextract = ['$_gemname-$pkgver.gem']
    @options = ['!emptydirs']
    @contributor = []

    nil
  end

  # Scrape dependencies from an existing pkgbuild.
  #
  # @param pkgbuild [String] The PKGBUILD to search.
  # @return [Array] all existing dependencies that are not ruby or gems
  def parse_existing_dependencies(pkgbuild)
    match = pkgbuild.match(/^depends=\((.*?)\)$/m)[1]

    # First step is to remove the leading and trailing quotes. Then convert
    # all whitespace (newlines, tabs, multiple spaces, etc.) to single
    # spaces. Then, make sure that strings are quoted with ' not ".
    # Finally, split the packages into an array.
    deps = match[1..-2].gsub(/[[:space:]]+/, ' ').tr('"', "'").split("' '")

    deps.reject { |e| e.match(/^ruby/) }
  rescue
    []
  end

  # Assign the correct pkgrel and epoch depending on the current pkgver on
  # the AUR and the version of the gem from rubygems.org.
  #
  # @param details [Hash] The results from AurScraper scrape
  # @return [void]
  def perform_version_reconciliation(details)
    @epoch = details.fetch(:epoch)
    @pkgrel = 1

    if pkgver < details.fetch(:pkgver)
      @epoch += 1
    elsif @pkgver == details.fetch(:pkgver)
      @pkgrel = details.fetch(:pkgrel) + 1
    end
  end
end

#sourceArray

Returns a list of sources.

Returns:

  • (Array)

    a list of sources

See Also:


78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/gembuild/pkgbuild.rb', line 78

class Pkgbuild
  attr_accessor :arch, :checksum, :checksum_type, :contributor, :depends,
                :description, :epoch, :gemname, :license, :maintainer,
                :makedepends, :noextract, :options, :pkgname, :pkgrel,
                :pkgver, :source, :url

  # Create a new Pkgbuild instance.
  #
  # @raise [Gembuild::InvalidPkgbuildError] if something other than a
  #   string or nil is passed as the existing pkgbuild
  #
  # @param gemname [String] The rubygem for which to create a PKGBUILD.
  # @param existing_pkgbuild [nil, String] An old PKGBUILD that can be
  #   parsed for maintainer and contributor information.
  # @return [Gembuild::Pkgbuild] a new Pkgbuild instance
  def initialize(gemname, existing_pkgbuild = nil)
    unless existing_pkgbuild.nil? || existing_pkgbuild.is_a?(String)
      fail Gembuild::InvalidPkgbuildError
    end

    @gemname = gemname
    @pkgname = "ruby-#{@gemname}"

    set_package_defaults

    no_parse_pkgbuild = existing_pkgbuild.nil? || existing_pkgbuild.empty?
    parse_existing_pkgbuild(existing_pkgbuild) unless no_parse_pkgbuild
  end

  # Parse the old pkgbuild (if it exists) to get information about old
  # maintainers or contributors or about other dependencies that have been
  # added but that can not be scraped from rubygems.org.
  #
  # @param pkgbuild [String] The old PKGBUILD to parse.
  # @return [Hash] a hash containing the values scraped from the PKGBUILD
  def parse_existing_pkgbuild(pkgbuild)
    pkgbuild.match(/^# Maintainer: (.*)$/) { |m| @maintainer = m[1] }

    @contributor = pkgbuild.scan(/^# Contributor: (.*)$/).flatten

    deps = parse_existing_dependencies(pkgbuild)
    deps.each do |dep|
      @depends << dep
    end

    { maintainer: maintainer, contributor: contributor, depends: deps }
  end

  # Create a new Pkgbuild instance with all information from the scraped
  # sources assigned.
  #
  # @param gemname [String] The rubygem for which to create a Pkgbuild.
  # @param existing_pkgbuild [String, nil] An old PKGBUILD that can be
  #   parsed for maintainer information.
  # @return [Gembuild::Pkgbuild] a new Pkgbuild instance
  def self.create(gemname, existing_pkgbuild = nil)
    pkgbuild = Pkgbuild.new(gemname, existing_pkgbuild)

    pkgbuild.fetch_maintainer

    gem_details = Gembuild::GemScraper.new(gemname).scrape!
    aur_details = Gembuild::AurScraper.new(pkgbuild.pkgname).scrape!

    pkgbuild.assign_gem_details(gem_details)
    pkgbuild.assign_aur_details(aur_details)

    pkgbuild
  end

  # Generate a PKGBUILD from the class using the pkgbuild erb template.
  #
  # @return [String] the PKGBUILD
  def render
    ERB.new(template, 0, '-').result(binding)
  end

  # Get the PKGBUILD erb template.
  #
  # @return [String] the pkgbuild erb template
  def template
    File.read(File.join(File.dirname(__FILE__), 'pkgbuild.erb'))
  end

  # Write the PKGBUILD to disk.
  #
  # @param path [String] The directory to write the PKGBUILD.
  # @return [Fixnum] the number of bytes written
  def write(path = '')
    File.write(File.join(File.expand_path(path), 'PKGBUILD'), render)
  end

  # Obfuscate the maintainer/contributors' email addresses to (help to)
  # prevent spam.
  #
  # @param contact_information [String] The maintainer or contributor
  #   byline.
  # @return [String] the information with the @s and .s exchanged
  def format_contact_information(contact_information)
    contact_information.gsub('@', ' at ').gsub('.', ' dot ')
  end

  # Set the correct maintainer for the PKGBUILD.
  #
  # If the current maintainer is nil (no old pkgbuild was passed), then do
  # nothing. If there is a maintainer then compare it to the configured
  # maintainer and if they are different then make the old maintainer a
  # contributor before setting the correct maintainer. If the maintainer is
  # nil then just set the confgured maintainer.
  #
  # @return [String] the pkgbuild maintainer
  def fetch_maintainer
    configured_maintainer = Gembuild.configure
    m = "#{configured_maintainer[:name]} <#{configured_maintainer[:email]}>"
    new_maintainer = format_contact_information(m)

    unless maintainer.nil? || new_maintainer == maintainer
      @contributor.unshift(maintainer)
    end

    @maintainer = new_maintainer
  end

  # Add the data scraped from rubygems.org to the pkgbuild.
  #
  # @param details [Hash] The results from GemScraper scrape.
  # @return [void]
  def assign_gem_details(details)
    @pkgver = details.fetch(:version)
    @description = details.fetch(:description)
    @checksum = details.fetch(:checksum)
    @license = details.fetch(:license)
    @url = details.fetch(:homepage)

    details.fetch(:dependencies).each do |dependency|
      @depends << "ruby-#{dependency}"
    end
  end

  # Assign version information based on the information gathered from the
  # AUR.
  #
  # @param details [Hash, nil] The results from AurScraper scrape or nil if
  #   the package does not yet exist on the AUR.
  # @return [void]
  def assign_aur_details(details)
    if details.nil?
      @epoch = 0
      @pkgrel = 1
    else
      perform_version_reconciliation(details)
    end
  end

  private

  # Set the static variables of a new pkgbuild.
  #
  # @return [nil]
  def set_package_defaults
    @checksum_type = 'sha256'
    @arch = ['any']
    @makedepends = ['rubygems']
    @depends = ['ruby']
    @source = ['https://rubygems.org/downloads/$_gemname-$pkgver.gem']
    @noextract = ['$_gemname-$pkgver.gem']
    @options = ['!emptydirs']
    @contributor = []

    nil
  end

  # Scrape dependencies from an existing pkgbuild.
  #
  # @param pkgbuild [String] The PKGBUILD to search.
  # @return [Array] all existing dependencies that are not ruby or gems
  def parse_existing_dependencies(pkgbuild)
    match = pkgbuild.match(/^depends=\((.*?)\)$/m)[1]

    # First step is to remove the leading and trailing quotes. Then convert
    # all whitespace (newlines, tabs, multiple spaces, etc.) to single
    # spaces. Then, make sure that strings are quoted with ' not ".
    # Finally, split the packages into an array.
    deps = match[1..-2].gsub(/[[:space:]]+/, ' ').tr('"', "'").split("' '")

    deps.reject { |e| e.match(/^ruby/) }
  rescue
    []
  end

  # Assign the correct pkgrel and epoch depending on the current pkgver on
  # the AUR and the version of the gem from rubygems.org.
  #
  # @param details [Hash] The results from AurScraper scrape
  # @return [void]
  def perform_version_reconciliation(details)
    @epoch = details.fetch(:epoch)
    @pkgrel = 1

    if pkgver < details.fetch(:pkgver)
      @epoch += 1
    elsif @pkgver == details.fetch(:pkgver)
      @pkgrel = details.fetch(:pkgrel) + 1
    end
  end
end

#urlString

Returns the URL of the homepage of the gem.

Returns:

  • (String)

    the URL of the homepage of the gem

See Also:


78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/gembuild/pkgbuild.rb', line 78

class Pkgbuild
  attr_accessor :arch, :checksum, :checksum_type, :contributor, :depends,
                :description, :epoch, :gemname, :license, :maintainer,
                :makedepends, :noextract, :options, :pkgname, :pkgrel,
                :pkgver, :source, :url

  # Create a new Pkgbuild instance.
  #
  # @raise [Gembuild::InvalidPkgbuildError] if something other than a
  #   string or nil is passed as the existing pkgbuild
  #
  # @param gemname [String] The rubygem for which to create a PKGBUILD.
  # @param existing_pkgbuild [nil, String] An old PKGBUILD that can be
  #   parsed for maintainer and contributor information.
  # @return [Gembuild::Pkgbuild] a new Pkgbuild instance
  def initialize(gemname, existing_pkgbuild = nil)
    unless existing_pkgbuild.nil? || existing_pkgbuild.is_a?(String)
      fail Gembuild::InvalidPkgbuildError
    end

    @gemname = gemname
    @pkgname = "ruby-#{@gemname}"

    set_package_defaults

    no_parse_pkgbuild = existing_pkgbuild.nil? || existing_pkgbuild.empty?
    parse_existing_pkgbuild(existing_pkgbuild) unless no_parse_pkgbuild
  end

  # Parse the old pkgbuild (if it exists) to get information about old
  # maintainers or contributors or about other dependencies that have been
  # added but that can not be scraped from rubygems.org.
  #
  # @param pkgbuild [String] The old PKGBUILD to parse.
  # @return [Hash] a hash containing the values scraped from the PKGBUILD
  def parse_existing_pkgbuild(pkgbuild)
    pkgbuild.match(/^# Maintainer: (.*)$/) { |m| @maintainer = m[1] }

    @contributor = pkgbuild.scan(/^# Contributor: (.*)$/).flatten

    deps = parse_existing_dependencies(pkgbuild)
    deps.each do |dep|
      @depends << dep
    end

    { maintainer: maintainer, contributor: contributor, depends: deps }
  end

  # Create a new Pkgbuild instance with all information from the scraped
  # sources assigned.
  #
  # @param gemname [String] The rubygem for which to create a Pkgbuild.
  # @param existing_pkgbuild [String, nil] An old PKGBUILD that can be
  #   parsed for maintainer information.
  # @return [Gembuild::Pkgbuild] a new Pkgbuild instance
  def self.create(gemname, existing_pkgbuild = nil)
    pkgbuild = Pkgbuild.new(gemname, existing_pkgbuild)

    pkgbuild.fetch_maintainer

    gem_details = Gembuild::GemScraper.new(gemname).scrape!
    aur_details = Gembuild::AurScraper.new(pkgbuild.pkgname).scrape!

    pkgbuild.assign_gem_details(gem_details)
    pkgbuild.assign_aur_details(aur_details)

    pkgbuild
  end

  # Generate a PKGBUILD from the class using the pkgbuild erb template.
  #
  # @return [String] the PKGBUILD
  def render
    ERB.new(template, 0, '-').result(binding)
  end

  # Get the PKGBUILD erb template.
  #
  # @return [String] the pkgbuild erb template
  def template
    File.read(File.join(File.dirname(__FILE__), 'pkgbuild.erb'))
  end

  # Write the PKGBUILD to disk.
  #
  # @param path [String] The directory to write the PKGBUILD.
  # @return [Fixnum] the number of bytes written
  def write(path = '')
    File.write(File.join(File.expand_path(path), 'PKGBUILD'), render)
  end

  # Obfuscate the maintainer/contributors' email addresses to (help to)
  # prevent spam.
  #
  # @param contact_information [String] The maintainer or contributor
  #   byline.
  # @return [String] the information with the @s and .s exchanged
  def format_contact_information(contact_information)
    contact_information.gsub('@', ' at ').gsub('.', ' dot ')
  end

  # Set the correct maintainer for the PKGBUILD.
  #
  # If the current maintainer is nil (no old pkgbuild was passed), then do
  # nothing. If there is a maintainer then compare it to the configured
  # maintainer and if they are different then make the old maintainer a
  # contributor before setting the correct maintainer. If the maintainer is
  # nil then just set the confgured maintainer.
  #
  # @return [String] the pkgbuild maintainer
  def fetch_maintainer
    configured_maintainer = Gembuild.configure
    m = "#{configured_maintainer[:name]} <#{configured_maintainer[:email]}>"
    new_maintainer = format_contact_information(m)

    unless maintainer.nil? || new_maintainer == maintainer
      @contributor.unshift(maintainer)
    end

    @maintainer = new_maintainer
  end

  # Add the data scraped from rubygems.org to the pkgbuild.
  #
  # @param details [Hash] The results from GemScraper scrape.
  # @return [void]
  def assign_gem_details(details)
    @pkgver = details.fetch(:version)
    @description = details.fetch(:description)
    @checksum = details.fetch(:checksum)
    @license = details.fetch(:license)
    @url = details.fetch(:homepage)

    details.fetch(:dependencies).each do |dependency|
      @depends << "ruby-#{dependency}"
    end
  end

  # Assign version information based on the information gathered from the
  # AUR.
  #
  # @param details [Hash, nil] The results from AurScraper scrape or nil if
  #   the package does not yet exist on the AUR.
  # @return [void]
  def assign_aur_details(details)
    if details.nil?
      @epoch = 0
      @pkgrel = 1
    else
      perform_version_reconciliation(details)
    end
  end

  private

  # Set the static variables of a new pkgbuild.
  #
  # @return [nil]
  def set_package_defaults
    @checksum_type = 'sha256'
    @arch = ['any']
    @makedepends = ['rubygems']
    @depends = ['ruby']
    @source = ['https://rubygems.org/downloads/$_gemname-$pkgver.gem']
    @noextract = ['$_gemname-$pkgver.gem']
    @options = ['!emptydirs']
    @contributor = []

    nil
  end

  # Scrape dependencies from an existing pkgbuild.
  #
  # @param pkgbuild [String] The PKGBUILD to search.
  # @return [Array] all existing dependencies that are not ruby or gems
  def parse_existing_dependencies(pkgbuild)
    match = pkgbuild.match(/^depends=\((.*?)\)$/m)[1]

    # First step is to remove the leading and trailing quotes. Then convert
    # all whitespace (newlines, tabs, multiple spaces, etc.) to single
    # spaces. Then, make sure that strings are quoted with ' not ".
    # Finally, split the packages into an array.
    deps = match[1..-2].gsub(/[[:space:]]+/, ' ').tr('"', "'").split("' '")

    deps.reject { |e| e.match(/^ruby/) }
  rescue
    []
  end

  # Assign the correct pkgrel and epoch depending on the current pkgver on
  # the AUR and the version of the gem from rubygems.org.
  #
  # @param details [Hash] The results from AurScraper scrape
  # @return [void]
  def perform_version_reconciliation(details)
    @epoch = details.fetch(:epoch)
    @pkgrel = 1

    if pkgver < details.fetch(:pkgver)
      @epoch += 1
    elsif @pkgver == details.fetch(:pkgver)
      @pkgrel = details.fetch(:pkgrel) + 1
    end
  end
end

Class Method Details

.create(gemname, existing_pkgbuild = nil) ⇒ Gembuild::Pkgbuild

Create a new Pkgbuild instance with all information from the scraped sources assigned.

Parameters:

  • gemname (String)

    The rubygem for which to create a Pkgbuild.

  • existing_pkgbuild (String, nil) (defaults to: nil)

    An old PKGBUILD that can be parsed for maintainer information.

Returns:


133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/gembuild/pkgbuild.rb', line 133

def self.create(gemname, existing_pkgbuild = nil)
  pkgbuild = Pkgbuild.new(gemname, existing_pkgbuild)

  pkgbuild.fetch_maintainer

  gem_details = Gembuild::GemScraper.new(gemname).scrape!
  aur_details = Gembuild::AurScraper.new(pkgbuild.pkgname).scrape!

  pkgbuild.assign_gem_details(gem_details)
  pkgbuild.assign_aur_details(aur_details)

  pkgbuild
end

Instance Method Details

#assign_aur_details(details) ⇒ void

This method returns an undefined value.

Assign version information based on the information gathered from the AUR.

Parameters:

  • details (Hash, nil)

    The results from AurScraper scrape or nil if the package does not yet exist on the AUR.


222
223
224
225
226
227
228
229
# File 'lib/gembuild/pkgbuild.rb', line 222

def assign_aur_details(details)
  if details.nil?
    @epoch = 0
    @pkgrel = 1
  else
    perform_version_reconciliation(details)
  end
end

#assign_gem_details(details) ⇒ void

This method returns an undefined value.

Add the data scraped from rubygems.org to the pkgbuild.

Parameters:

  • details (Hash)

    The results from GemScraper scrape.


204
205
206
207
208
209
210
211
212
213
214
# File 'lib/gembuild/pkgbuild.rb', line 204

def assign_gem_details(details)
  @pkgver = details.fetch(:version)
  @description = details.fetch(:description)
  @checksum = details.fetch(:checksum)
  @license = details.fetch(:license)
  @url = details.fetch(:homepage)

  details.fetch(:dependencies).each do |dependency|
    @depends << "ruby-#{dependency}"
  end
end

#fetch_maintainerString

Set the correct maintainer for the PKGBUILD.

If the current maintainer is nil (no old pkgbuild was passed), then do nothing. If there is a maintainer then compare it to the configured maintainer and if they are different then make the old maintainer a contributor before setting the correct maintainer. If the maintainer is nil then just set the confgured maintainer.

Returns:

  • (String)

    the pkgbuild maintainer


188
189
190
191
192
193
194
195
196
197
198
# File 'lib/gembuild/pkgbuild.rb', line 188

def fetch_maintainer
  configured_maintainer = Gembuild.configure
  m = "#{configured_maintainer[:name]} <#{configured_maintainer[:email]}>"
  new_maintainer = format_contact_information(m)

  unless maintainer.nil? || new_maintainer == maintainer
    @contributor.unshift(maintainer)
  end

  @maintainer = new_maintainer
end

#format_contact_information(contact_information) ⇒ String

Obfuscate the maintainer/contributors' email addresses to (help to) prevent spam.

Parameters:

  • contact_information (String)

    The maintainer or contributor byline.

Returns:

  • (String)

    the information with the @s and .s exchanged


175
176
177
# File 'lib/gembuild/pkgbuild.rb', line 175

def format_contact_information(contact_information)
  contact_information.gsub('@', ' at ').gsub('.', ' dot ')
end

#parse_existing_pkgbuild(pkgbuild) ⇒ Hash

Parse the old pkgbuild (if it exists) to get information about old maintainers or contributors or about other dependencies that have been added but that can not be scraped from rubygems.org.

Parameters:

  • pkgbuild (String)

    The old PKGBUILD to parse.

Returns:

  • (Hash)

    a hash containing the values scraped from the PKGBUILD


113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/gembuild/pkgbuild.rb', line 113

def parse_existing_pkgbuild(pkgbuild)
  pkgbuild.match(/^# Maintainer: (.*)$/) { |m| @maintainer = m[1] }

  @contributor = pkgbuild.scan(/^# Contributor: (.*)$/).flatten

  deps = parse_existing_dependencies(pkgbuild)
  deps.each do |dep|
    @depends << dep
  end

  { maintainer: maintainer, contributor: contributor, depends: deps }
end

#renderString

Generate a PKGBUILD from the class using the pkgbuild erb template.

Returns:

  • (String)

    the PKGBUILD


150
151
152
# File 'lib/gembuild/pkgbuild.rb', line 150

def render
  ERB.new(template, 0, '-').result(binding)
end

#templateString

Get the PKGBUILD erb template.

Returns:

  • (String)

    the pkgbuild erb template


157
158
159
# File 'lib/gembuild/pkgbuild.rb', line 157

def template
  File.read(File.join(File.dirname(__FILE__), 'pkgbuild.erb'))
end

#write(path = '') ⇒ Fixnum

Write the PKGBUILD to disk.

Parameters:

  • path (String) (defaults to: '')

    The directory to write the PKGBUILD.

Returns:

  • (Fixnum)

    the number of bytes written


165
166
167
# File 'lib/gembuild/pkgbuild.rb', line 165

def write(path = '')
  File.write(File.join(File.expand_path(path), 'PKGBUILD'), render)
end