Class: Lapis::Minecraft::Versioning::OSRule

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

Overview

Description of how resources can be chosen for operating systems.

Instance Attribute Summary collapse

Attributes inherited from Rule

#allowed?

Instance Method Summary collapse

Constructor Details

#initialize(is_allowed, os_type, os_version = nil) ⇒ OSRule

Creates an OS rule.

Parameters:

  • is_allowed (Boolean)

    Indicates whether the resource should be included.

  • os_type (Symbol)

    Type of OS this rule applies to. Can be one of: :windows, :linux, or :osx.

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

    OS version regex. Can be nil to apply to all versions of the OS.


25
26
27
28
29
# File 'lib/lapis/minecraft/versioning/os_rule.rb', line 25

def initialize(is_allowed, os_type, os_version = nil)
  super(is_allowed)
  @os_type = os_type
  @os_version = os_version ? Regexp.new(os_version) : // # Use empty regex if no version specified.
end

Instance Attribute Details

#os_typeSymbol (readonly)

Type of operating system this rule applies to.

Returns:

  • (Symbol)

    Can be one of: :windows, :linux, or :osx.


12
13
14
# File 'lib/lapis/minecraft/versioning/os_rule.rb', line 12

def os_type
  @os_type
end

#os_versionRegexp (readonly)

Operating system version regex. This rule should apply if the OS version matches this regex.

Returns:

  • (Regexp)

17
18
19
# File 'lib/lapis/minecraft/versioning/os_rule.rb', line 17

def os_version
  @os_version
end

Instance Method Details

#==(other) ⇒ true, false

Compares one rule to another.

Parameters:

  • other (OSRule)

    Rule to compare against.

Returns:

  • (true)

    The rules are the same.

  • (false)

    The rules are different.


47
48
49
50
51
# File 'lib/lapis/minecraft/versioning/os_rule.rb', line 47

def ==(other)
  super(other) &&
      other.os_type == @os_type &&
      other.os_version == @os_version
end

#applies_to?(properties) ⇒ true, false

Checks whether the rule applies to a set of properties.

Parameters:

  • properties (Hash<Symbol => String>)

    Properties to check the rule against.

Options Hash (properties):

  • :os_type (String)

    One of: windows, linux, or osx.

  • :os_version (String)

    Version of the OS.

Returns:

  • (true)

    The rule should be considered when using the resource.

  • (false)

    The rule should not be considered.


37
38
39
40
41
# File 'lib/lapis/minecraft/versioning/os_rule.rb', line 37

def applies_to?(properties)
  super(properties) &&
      properties[:os_type].downcase == @os_type.to_s &&
      @os_version.match(properties[:os_version])
end