Class: Gemspec

Inherits:
Object
  • Object
show all
Defined in:
lib/base/gemspec.rb

Class Method Summary collapse

Class Method Details

.gemfile(gemspec_file) ⇒ Object


13
14
15
16
17
18
# File 'lib/base/gemspec.rb', line 13

def self.gemfile(gemspec_file)
  spec = Gem::Specification.load(gemspec_file)
  return "#{spec.name}-#{spec.version}.gem" unless spec.nil?

  ""
end

.latest_published_version(gemname) ⇒ Object


25
26
27
28
29
30
# File 'lib/base/gemspec.rb', line 25

def self.latest_published_version(gemname)
  scan = `gem list -r #{gemname}`.scan(/^dev\s*\(([\d.]+)\)/)
  return scan[0][0] if !scan.nil? && (scan.length.positive? && !scan[0].nil? && scan[0].length.positive?)

  ""
end

.normalize(gemspec_file) ⇒ Object


47
48
49
50
# File 'lib/base/gemspec.rb', line 47

def self.normalize(gemspec_file)
  spec = Gem::Specification.load(gemspec_file)
  File.open(gemspec_file, "w") { |f| f.write(spec.to_ruby) }
end

.published?(gemspec_file) ⇒ Boolean

Returns:

  • (Boolean)

43
44
45
# File 'lib/base/gemspec.rb', line 43

def self.published?(gemspec_file)
  published_version(gemspec_file) == version(gemspec_file)
end

.published_version(gemspec_file) ⇒ Object


32
33
34
35
36
37
38
39
40
41
# File 'lib/base/gemspec.rb', line 32

def self.published_version(gemspec_file)
  published_version = ""
  spec = Gem::Specification.load(gemspec_file)
  begin
    published_version = latest_published_version spec.name # `gem list -r #{spec.name}`.scan(/\((\d+.\d+.\d+)\)/)[0][0]
  rescue StandardError
    published_version = ""
  end
  published_version
end

.update(gemspec_file) ⇒ Object


7
8
9
10
11
# File 'lib/base/gemspec.rb', line 7

def self.update(gemspec_file)
  Text.replace_in_file gemspec_file,
                       /('\d{4}-\d{2}-\d{2}')/,
                       "'#{Time.now.strftime("%Y-%m-%d")}'"
end

.upgrade(gemspec_file) ⇒ Object


52
# File 'lib/base/gemspec.rb', line 52

def self.upgrade(gemspec_file); end

.version(gemspec_file) ⇒ Object


20
21
22
23
# File 'lib/base/gemspec.rb', line 20

def self.version(gemspec_file)
  spec = Gem::Specification.load(gemspec_file)
  spec.version.to_s
end