Class: Grouik::Loadable
- Inherits:
-
Object
- Object
- Grouik::Loadable
- Defined in:
- src/lib/grouik/loadable.rb
Overview
Describe a loable item (Ruby file)
Instance Attribute Summary collapse
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#basedir ⇒ Object
readonly
Returns the value of attribute basedir.
- #path(format = false) ⇒ String readonly
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(base, path, basedir = '.') ⇒ Loadable
constructor
A new instance of Loadable.
- #load(from = nil) ⇒ Boolean
- #loadable? ⇒ Boolean
- #to_s ⇒ String
Constructor Details
#initialize(base, path, basedir = '.') ⇒ Loadable
Returns a new instance of Loadable.
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
#base ⇒ Object (readonly)
Returns the value of attribute base.
5 6 7 |
# File 'src/lib/grouik/loadable.rb', line 5 def base @base end |
#basedir ⇒ Object (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)
20 21 22 |
# File 'src/lib/grouik/loadable.rb', line 20 def path @path end |
Class Method Details
.paths ⇒ 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
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
41 42 43 |
# File 'src/lib/grouik/loadable.rb', line 41 def loadable? self.class.paths.include?(basedir.join(base).to_s) end |
#to_s ⇒ String
30 31 32 |
# File 'src/lib/grouik/loadable.rb', line 30 def to_s path(true) end |