Class: Fried::Test::PrependToLoadPath

Inherits:
Object
  • Object
show all
Defined in:
lib/fried/test/prepend_to_load_path.rb

Overview

Unshifts the path to $LOAD_PATH unless already existing

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePrependToLoadPath

Returns a new instance of PrependToLoadPath.



8
9
10
# File 'lib/fried/test/prepend_to_load_path.rb', line 8

def initialize
  @load_path = []
end

Instance Attribute Details

#load_pathObject

Returns the value of attribute load_path.



6
7
8
# File 'lib/fried/test/prepend_to_load_path.rb', line 6

def load_path
  @load_path
end

Class Method Details

.buildObject



12
13
14
15
16
# File 'lib/fried/test/prepend_to_load_path.rb', line 12

def self.build
  new.tap do |instance|
    instance.load_path = $LOAD_PATH
  end
end

.callObject



29
30
31
32
# File 'lib/fried/test/prepend_to_load_path.rb', line 29

def self.call
  instance = build
  instance.()
end

Instance Method Details

#call(path) ⇒ Boolean

Returns true if path was added, false if already present.

Parameters:

  • path (String, Pathname)

Returns:

  • (Boolean)

    true if path was added, false if already present



20
21
22
23
24
25
26
27
# File 'lib/fried/test/prepend_to_load_path.rb', line 20

def call(path)
  text_path = path.to_s

  has_path = load_path.include?(text_path)
  load_path.unshift(text_path) unless has_path

  !has_path
end