Class: Lapis::Minecraft::Versioning::ResourceSet

Inherits:
Object
  • Object
show all
Defined in:
lib/lapis/minecraft/versioning/resource_set.rb

Overview

Information about the archives and natives needed for a library.

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resources, windows_classifier = nil, linux_classifier = nil, osx_classifier = nil) ⇒ ResourceSet

Creates a new resource set.

Parameters:

  • resources (Array<Resource>)

    List of all resources (including natives).

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

    Classifier for the Windows native. Specify nil if there is no native for Windows.

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

    Classifier for the Linux native. Specify nil if there is no native for Linux.

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

    Classifier for the OSX native. Specify nil if there is no native for OSX.


39
40
41
42
43
44
# File 'lib/lapis/minecraft/versioning/resource_set.rb', line 39

def initialize(resources, windows_classifier = nil, linux_classifier = nil, osx_classifier = nil)
  @windows_classifier = windows_classifier ? windows_classifier.dup.freeze : nil
  @linux_classifier   = linux_classifier   ? linux_classifier.dup.freeze   : nil
  @osx_classifier     = osx_classifier     ? osx_classifier.dup.freeze     : nil
  @resources          = resources.dup.freeze
end

Instance Attribute Details

#linux_classifierString? (readonly)

Note:

This value can contain variables.

Classifier for the Linux native.

Returns:

  • (String)

    Classifier for Linux.

  • (nil)

    No Linux native for this library.


19
20
21
# File 'lib/lapis/minecraft/versioning/resource_set.rb', line 19

def linux_classifier
  @linux_classifier
end

#osx_classifierString? (readonly)

Note:

This value can contain variables.

Classifier for the OSX native.

Returns:

  • (String)

    Classifier for OSX.

  • (nil)

    No OSX native for this library.


25
26
27
# File 'lib/lapis/minecraft/versioning/resource_set.rb', line 25

def osx_classifier
  @osx_classifier
end

#resourcesArray<Resource> (readonly)

List of all resources (including natives) the library uses.

Returns:


29
30
31
# File 'lib/lapis/minecraft/versioning/resource_set.rb', line 29

def resources
  @resources
end

#windows_classifierString? (readonly)

Note:

This value can contain variables.

Classifier for the Windows native.

Returns:

  • (String)

    Classifier for Windows.

  • (nil)

    No Windows native for this library.


13
14
15
# File 'lib/lapis/minecraft/versioning/resource_set.rb', line 13

def windows_classifier
  @windows_classifier
end

Instance Method Details

#==(other) ⇒ true, false

Compares one resource set to another.

Parameters:

  • other (ResourceSet)

    Resource set to compare against.

Returns:

  • (true)

    The resource sets are the same.

  • (false)

    The resource sets are different.


82
83
84
85
86
87
# File 'lib/lapis/minecraft/versioning/resource_set.rb', line 82

def ==(other)
  other.windows_classifier == @windows_classifier &&
      other.linux_classifier == @linux_classifier &&
      other.osx_classifier == @osx_classifier &&
      other.resources == @resources
end

#filter_resources(properties) ⇒ Array<Resource>

Filters the resources in the set based on properties.

Parameters:

  • properties (Hash<Symbol => String>)

    Properties to check the resources against.

Options Hash (properties):

  • :os_type (String)

    One of: windows, linux, or osx.

  • :arch (String)

    CPU architecture - 32 or 64.

Returns:

  • (Array<Resource>)

    List of resources applicable to the properties given.


51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/lapis/minecraft/versioning/resource_set.rb', line 51

def filter_resources(properties)
  result = []
  generic = @resources.find do |resource|
    resource.classifier == 'artifact'
  end
  result << generic if generic
  classifier = case(properties[:os_type])
                        when 'windows'
                          @windows_classifier
                        when 'linux'
                          @linux_classifier
                        when 'osx'
                          @osx_classifier
                      end
  if classifier
    native_classifier = classifier.gsub(/\$\{([^}]*)\}/) do |match|
      property = match[2...-1].downcase.to_sym
      properties[property]
    end
    native = @resources.find do |resource|
      resource.classifier == native_classifier
    end
    result << native if native
  end
  result
end