Class: ElmInstall::DirectorySource

Inherits:
Source show all
Defined in:
lib/elm_install/directory_source.rb

Overview

This clas handles sources that point to a local directory.

Instance Attribute Summary collapse

Attributes inherited from Source

#identifier, #options

Instance Method Summary collapse

Constructor Details

#initialize(dir) ⇒ DirectorySource

Initializes a directory source with the given directory.

Parameters:

  • dir (Dir)

    The directory



13
14
15
16
# File 'lib/elm_install/directory_source.rb', line 13

def initialize(dir)
  @dir = dir
  self
end

Instance Attribute Details

#dirDir (readonly)

Returns The directory.

Returns:

  • (Dir)

    The directory



5
6
7
# File 'lib/elm_install/directory_source.rb', line 5

def dir
  @dir
end

Instance Method Details

#copy_to(_, directory) ⇒ Object

Copies the directory to the given other directory

Parameters:

Returns:

  • nil



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/elm_install/directory_source.rb', line 35

def copy_to(_, directory)
  # Delete the directory to make sure no pervious version remains
  FileUtils.rm_rf(directory) if directory.exist?

  # Create parent directory
  FileUtils.mkdir_p(directory.parent)

  # Create symlink
  FileUtils.ln_s(@dir.expand_path, directory)

  nil
end

#fetch(_) ⇒ Dir

Returns the directory

Parameters:

  • _ (String)

    The version

Returns:

  • (Dir)

    The directory



24
25
26
# File 'lib/elm_install/directory_source.rb', line 24

def fetch(_)
  Dir.new(@dir.expand_path)
end

#to_logString

Returns the log format

Returns:

  • (String)


62
63
64
# File 'lib/elm_install/directory_source.rb', line 62

def to_log
  @dir.expand_path.to_s
end

#versions(_) ⇒ Array

Returns the available versions for a repository

Parameters:

  • _ (Array)

    The constraints

Returns:

  • (Array)

    The versions



54
55
56
# File 'lib/elm_install/directory_source.rb', line 54

def versions(_)
  [identifier.version(fetch(''))]
end