Class: Devpack::GemRef

Inherits:
Object
  • Object
show all
Defined in:
lib/devpack/gem_ref.rb

Overview

Provides extended syntax for gem definitions, allowing ‘require: false` semantics via an asterisrk prefix in `.devpack` file, e.g. `*my_gem`

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, version: nil, no_require: false) ⇒ GemRef

Returns a new instance of GemRef.



14
15
16
17
18
# File 'lib/devpack/gem_ref.rb', line 14

def initialize(name:, version: nil, no_require: false)
  @name = name
  @version = version
  @no_require = no_require
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



20
21
22
# File 'lib/devpack/gem_ref.rb', line 20

def name
  @name
end

#versionObject (readonly)

Returns the value of attribute version.



20
21
22
# File 'lib/devpack/gem_ref.rb', line 20

def version
  @version
end

Class Method Details

.parse(line) ⇒ Object



7
8
9
10
11
12
# File 'lib/devpack/gem_ref.rb', line 7

def self.parse(line)
  name, _, version = line.partition(':')
  no_require = name.start_with?('*')
  name = name.sub('*', '') if no_require
  new(name: name, version: version.empty? ? nil : Gem::Requirement.new(version), no_require: no_require)
end

Instance Method Details

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/devpack/gem_ref.rb', line 26

def eql?(other)
  name == other.name && version == other.version && require? == other.require?
end

#require?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/devpack/gem_ref.rb', line 22

def require?
  !@no_require
end

#to_sObject



30
31
32
# File 'lib/devpack/gem_ref.rb', line 30

def to_s
  "#{require? ? '*' : ''}#{@name}:#{@version}"
end