Module: ElmInstall::Utils

Defined in:
lib/elm_install/utils.rb

Overview

This module contains utility functions.

Constant Summary collapse

CONVERTERS =

Regexes for converting constraints.

{
  /v<(?!=)(.*)/ => '<',
  /(.*)<=v/ => '>=',
  /v<=(.*)/ => '<=',
  /(.*)<v/ => '>'
}.freeze

Class Method Summary collapse

Class Method Details

.package_version_path(package, version) ⇒ Strin

Returns the path for a package with the given version.

Parameters:

  • package (String)

    The package

  • version (String)

    The version

Returns:

  • (Strin)

    The path



34
35
36
37
# File 'lib/elm_install/utils.rb', line 34

def package_version_path(package, version)
  package_name = GitCloneUrl.parse(package).path.sub(%r{^/}, '')
  [package_name, File.join('elm-stuff', 'packages', package_name, version)]
end

.transform_constraint(constraint) ⇒ Array

Transform constraints form Elm’s package format to semver’s.

Parameters:

  • constraint (String)

    The input constraint

Returns:

  • (Array)

    The output constraints



19
20
21
22
23
24
25
26
# File 'lib/elm_install/utils.rb', line 19

def transform_constraint(constraint)
  constraint.gsub!(/\s/, '')

  CONVERTERS.map do |regexp, prefix|
    match = constraint.match(regexp)
    "#{prefix} #{match[1]}" if match
  end.compact
end