Class: Boxing::Package

Inherits:
Object
  • Object
show all
Defined in:
lib/boxing/package.rb

Overview

The rubygems mapping for Linux package

Since:

  • 0.1.0

Constant Summary collapse

RUNTIME =

Since:

  • 0.1.0

0b01
BUILD =

Since:

  • 0.1.0

0b10

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, version = nil, mode: RUNTIME) ⇒ Package

Returns a new instance of Package.

Parameters:

  • name (String)

    the package name

  • version (String) (defaults to: nil)

    the package version

  • mode (Number) (defaults to: RUNTIME)

    is runtime or build

Since:

  • 0.1.0



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

def initialize(name, version = nil, mode: RUNTIME)
  @name = name
  @version = version
  @mode = mode
end

Instance Attribute Details

#nameObject (readonly)

Since:

  • 0.1.0



32
33
34
# File 'lib/boxing/package.rb', line 32

def name
  @name
end

#versionObject (readonly)

Since:

  • 0.1.0



32
33
34
# File 'lib/boxing/package.rb', line 32

def version
  @version
end

Class Method Details

.load(path) ⇒ Boxing::Package

Load Required Packages

Returns:

Since:

  • 0.1.0



16
17
18
19
20
21
22
# File 'lib/boxing/package.rb', line 16

def load(path)
  data = YAML.safe_load(File.read(path))
  mode = 0b00
  mode |= Package::RUNTIME if data['runtime']
  mode |= Package::BUILD if data['build']
  new(data['name'], data['version'], mode: mode)
end

Instance Method Details

#build?TrueClass|FalseClass

Returns is for build.

Returns:

  • (TrueClass|FalseClass)

    is for build

Since:

  • 0.1.0



48
49
50
# File 'lib/boxing/package.rb', line 48

def build?
  @mode & BUILD == BUILD
end

#eql?(other) ⇒ TrueClass|FalseClass Also known as: ==

Compare is same package

Returns:

  • (TrueClass|FalseClass)

Since:

  • 0.1.0



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

def eql?(other)
  @name == other.name
end

#hashNumber

Return Object#hash

Returns:

  • (Number)

Since:

  • 0.1.0



74
75
76
# File 'lib/boxing/package.rb', line 74

def hash
  @name.hash
end

#runtime?TrueClass|FalseClass

Returns is for runtime.

Returns:

  • (TrueClass|FalseClass)

    is for runtime

Since:

  • 0.1.0



55
56
57
# File 'lib/boxing/package.rb', line 55

def runtime?
  @mode & RUNTIME == RUNTIME
end

#to_sString

Convert to string

Returns:

  • (String)

    the package string

Since:

  • 0.1.0



83
84
85
86
87
88
# File 'lib/boxing/package.rb', line 83

def to_s
  return @name if @version.nil?

  # NOTE: Alpine format only
  "#{@name}=#{@version}"
end