Class: Getv::Package

Inherits:
Object
  • Object
show all
Defined in:
lib/getv/package.rb,
lib/getv/package/gem.rb,
lib/getv/package/npm.rb,
lib/getv/package/xml.rb,
lib/getv/package/helm.rb,
lib/getv/package/pypi.rb,
lib/getv/package/text.rb,
lib/getv/package/docker.rb,
lib/getv/package/github.rb,
lib/getv/package/github/tag.rb,
lib/getv/package/github/commit.rb,
lib/getv/package/github/release.rb

Overview

Getv::Package class

Direct Known Subclasses

Docker, Gem, GitHub, Helm, Npm, Pypi, Text, Xml

Defined Under Namespace

Classes: Docker, Gem, GitHub, Helm, Npm, Pypi, Text, Xml

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, opts = {}) ⇒ Package

Returns a new instance of Package.



40
41
42
43
# File 'lib/getv/package.rb', line 40

def initialize(name, opts = {})
  @name = name
  @opts = opts
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/getv/package.rb', line 6

def name
  @name
end

#optsObject

Returns the value of attribute opts.



6
7
8
# File 'lib/getv/package.rb', line 6

def opts
  @opts
end

Class Method Details

.create(name, opts = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/getv/package.rb', line 8

def self.create(name, opts = {})
  if opts.fetch(:type, nil).nil?
    opts.delete(:type)
    create_using_name(name, opts)
  else
    type = opts[:type]
    opts.delete(:type)
    type_to_class(type).new name, opts
  end
end

Instance Method Details

#defaultsObject

rubocop:disable Metrics/MethodLength



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/getv/package.rb', line 45

def defaults # rubocop:disable Metrics/MethodLength
  {
    select_search: '^\s*v?(.*)\s*$',
    select_replace: '\1',
    reject: nil,
    semantic_only: true,
    semantic_prefix: nil,
    semantic_select: ['*'],
    proxy: nil,
    versions: nil,
    latest_version: nil
  }
end

#latest_versionObject



59
60
61
62
# File 'lib/getv/package.rb', line 59

def latest_version
  update_versions if opts[:latest_version].nil?
  opts[:latest_version]
end

#update_versionsObject

rubocop:disable Metrics/PerceivedComplexity,Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/AbcSize



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/getv/package.rb', line 69

def update_versions # rubocop:disable Metrics/PerceivedComplexity,Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/AbcSize
  versions = retrieve_versions || []
  versions.sort! if instance_of?(Getv::Package::GitHub::Commit)
  select_pattern = Regexp.new(opts[:select_search])
  versions.select! { |v| v =~ select_pattern }
  versions.map! { |v| v.sub(select_pattern, opts[:select_replace]) }
  versions.reject! { |v| v =~ Regexp.new(opts[:reject]) } unless opts[:reject].nil?

  if opts[:semantic_only]
    require 'semantic'
    require 'semantic/core_ext'

    # remove non semantic version tags
    versions.select! do |v|
      v.sub(/^#{opts[:semantic_prefix]}/, '').is_version? && v.start_with?(opts[:semantic_prefix].to_s)
    end

    opts[:semantic_select].each do |comparator|
      versions.select! do |v|
        Semantic::Version.new(v.sub(/^#{opts[:semantic_prefix]}/, '')).satisfies?(comparator)
      end
    end
    versions.sort_by! { |v| Semantic::Version.new(v.sub(/^#{opts[:semantic_prefix]}/, '')) }
  else
    versions.sort! unless instance_of?(Getv::Package::GitHub::Commit)
  end
  opts[:versions] = versions.uniq
  opts[:latest_version] = opts[:versions][-1] unless opts[:versions].empty?
end

#versionsObject



64
65
66
67
# File 'lib/getv/package.rb', line 64

def versions
  update_versions if opts[:versions].nil?
  opts[:versions]
end