Class: Grouik::Loadable

Inherits:
Object
  • Object
show all
Defined in:
src/lib/grouik/loadable.rb

Overview

Describe a loable item (Ruby file)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base, path, basedir = '.') ⇒ Loadable

Returns a new instance of Loadable.

Parameters:

  • base (String)
  • path (String)
  • basedir (String) (defaults to: '.')


12
13
14
15
16
# File 'src/lib/grouik/loadable.rb', line 12

def initialize(base, path, basedir = '.')
  @base = Pathname.new(base)
  @path = path
  @basedir = Pathname.new(basedir).realpath
end

Instance Attribute Details

#baseObject (readonly)

Returns the value of attribute base.



5
6
7
# File 'src/lib/grouik/loadable.rb', line 5

def base
  @base
end

#basedirObject (readonly)

Returns the value of attribute basedir.



7
8
9
# File 'src/lib/grouik/loadable.rb', line 7

def basedir
  @basedir
end

#path(format = false) ⇒ String (readonly)

Parameters:

  • format (Boolean) (defaults to: false)

    format as loadable from $LOAD_PATH

Returns:

  • (String)


20
21
22
# File 'src/lib/grouik/loadable.rb', line 20

def path
  @path
end

Class Method Details

.pathsArray<String>

Returns:

  • (Array<String>)


47
48
49
# File 'src/lib/grouik/loadable.rb', line 47

def paths
  $LOAD_PATH.map(&:to_s)
end

Instance Method Details

#load(from = nil) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
38
39
# File 'src/lib/grouik/loadable.rb', line 35

def load(from = nil)
  path = from ? Pathname.new(from).join(self.path) : self.path

  return require path
end

#loadable?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'src/lib/grouik/loadable.rb', line 41

def loadable?
  self.class.paths.include?(basedir.join(base).to_s)
end

#to_sString

Returns:

  • (String)


30
31
32
# File 'src/lib/grouik/loadable.rb', line 30

def to_s
  path(true)
end