Class: Lapis::Minecraft::Versioning::Library

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

Overview

Dependency needed to run Minecraft.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, resources, rules = [], exclude_paths = []) ⇒ Library

Creates information about a dependency.

Parameters:

  • name (String)

    Name of the dependency.

  • resources (ResourceSet)

    Set of resources included in the library.

  • rules (Array<Rule>) (defaults to: [])

    Filter for which files should be installed.

  • exclude_paths (Array<String>) (defaults to: [])

    Paths to ignore when extracting resources.



29
30
31
32
33
34
# File 'lib/lapis/minecraft/versioning/library.rb', line 29

def initialize(name, resources, rules = [], exclude_paths = [])
  @name          = name.dup.freeze
  @resources     = resources
  @rules         = rules.dup.freeze
  @exclude_paths = exclude_paths.map(&:freeze).freeze
end

Instance Attribute Details

#exclude_pathsArray<String> (readonly)

Paths to ignore when extracting resources.

Returns:

  • (Array<String>)


22
23
24
# File 'lib/lapis/minecraft/versioning/library.rb', line 22

def exclude_paths
  @exclude_paths
end

#nameString (readonly)

Name of the dependency.

Returns:

  • (String)


10
11
12
# File 'lib/lapis/minecraft/versioning/library.rb', line 10

def name
  @name
end

#resourcesResourceSet (readonly)

Set of resources included in the library.

Returns:



14
15
16
# File 'lib/lapis/minecraft/versioning/library.rb', line 14

def resources
  @resources
end

#rulesArray<Rule> (readonly)

Filter for which files should be installed.

Returns:



18
19
20
# File 'lib/lapis/minecraft/versioning/library.rb', line 18

def rules
  @rules
end

Instance Method Details

#==(other) ⇒ true, false

Compares one library to another.

Parameters:

  • other (Library)

    Library to compare against.

Returns:

  • (true)

    The libraries are the same.

  • (false)

    The libraries are different.



63
64
65
66
67
68
# File 'lib/lapis/minecraft/versioning/library.rb', line 63

def ==(other)
  other.name == @name &&
      other.resources == @resources &&
      other.rules == @rules &&
      other.exclude_paths == @exclude_paths
end

#applies_to?(properties) ⇒ true, false

Checks whether the library applies to a set of properties.

Parameters:

  • properties (Hash<Symbol => String>)

    Properties to check the library rules against.

Options Hash (properties):

  • :os_type (String)

    One of: windows, linux, or osx.

  • :os_version (String)

    Version of the OS.

Returns:

  • (true)

    The library should be included with a client installation.

  • (false)

    The library should not be included.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/lapis/minecraft/versioning/library.rb', line 42

def applies_to?(properties)
  if @rules.empty?
    true
  else
    applicable = @rules.select do |rule|
      rule.applies_to?(properties)
    end
    if applicable.empty?
      false
    else
      applicable.all? do |rule|
        rule.allowed?
      end
    end
  end
end