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.


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.


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.


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.


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.


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.


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.

Options Hash (properties):

  • :os_type (String)

    One of: windows, linux, or osx.

  • :arch (String)

    CPU architecture - 32 or 64.


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