Class: Library::Feature
- Inherits:
-
Object
- Object
- Library::Feature
- Defined in:
- lib/library/feature.rb
Overview
The Feature class represents a single file within a library.
This class had been called ‘Script` until it occured to me that Ruby choose the name “feature” by it’s use of tem in the global variable ‘$LOADED_FEATURES`.
Instance Attribute Summary collapse
-
#extension ⇒ Object
readonly
Extension of feature file, e.g.
-
#filename ⇒ Object
readonly
The file path of the feature relative to the loadpath.
-
#library ⇒ Object
readonly
The Library object to which the file belongs.
-
#loadpath ⇒ Array
readonly
The loadpath within the library in which the feature resides.
Instance Method Summary collapse
-
#==(other) ⇒ true, false
Compare this features full path name to another using ‘#==`.
-
#acquire(options = {}) ⇒ true, false
Acquire the feature –Roll’s advanced require/load method.
-
#eql?(other) ⇒ true, false
Same as ‘#==`.
-
#fullname ⇒ String
Full path name of of feature.
-
#hash ⇒ Integer
Use ‘#fullname` to calculate a hash value for the feature file.
-
#initialize(library, loadpath, filename, extension = nil) ⇒ Feature
constructor
Create a new Feature instance.
- #library_activate ⇒ Object
-
#library_name ⇒ String
Name of the library to which the feature belongs.
-
#load(options = {}) ⇒ true, false
Load feature.
-
#localname ⇒ String
The path of the feature relative to the loadpath.
-
#location ⇒ String
Library location.
-
#require(options = {}) ⇒ true, false
Require feature.
-
#to_s ⇒ String
Same a fullname.
-
#to_str ⇒ String
Same a fullname.
Constructor Details
#initialize(library, loadpath, filename, extension = nil) ⇒ Feature
Create a new Feature instance.
26 27 28 29 30 31 |
# File 'lib/library/feature.rb', line 26 def initialize(library, loadpath, filename, extension=nil) @library = library @loadpath = loadpath @filename = filename @extension = extension end |
Instance Attribute Details
#extension ⇒ Object (readonly)
Extension of feature file, e.g. ‘.rb`.
53 54 55 |
# File 'lib/library/feature.rb', line 53 def extension @extension end |
#filename ⇒ Object (readonly)
The file path of the feature relative to the loadpath.
48 49 50 |
# File 'lib/library/feature.rb', line 48 def filename @filename end |
#library ⇒ Object (readonly)
The Library object to which the file belongs.
36 37 38 |
# File 'lib/library/feature.rb', line 36 def library @library end |
#loadpath ⇒ Array (readonly)
The loadpath within the library in which the feature resides.
43 44 45 |
# File 'lib/library/feature.rb', line 43 def loadpath @loadpath end |
Instance Method Details
#==(other) ⇒ true, false
Compare this features full path name to another using ‘#==`.
163 164 165 |
# File 'lib/library/feature.rb', line 163 def ==(other) fullname == other.to_s end |
#acquire(options = {}) ⇒ true, false
Acquire the feature –Roll’s advanced require/load method.
103 104 105 106 107 108 109 |
# File 'lib/library/feature.rb', line 103 def acquire(={}) if [:load] # TODO: .delete(:load) ? load() else require() end end |
#eql?(other) ⇒ true, false
Same as ‘#==`.
174 175 176 |
# File 'lib/library/feature.rb', line 174 def eql?(other) fullname == other.to_s end |
#fullname ⇒ String
Full path name of of feature.
85 86 87 |
# File 'lib/library/feature.rb', line 85 def fullname @fullname ||= ::File.join(location, loadpath, filename + (extension || '')) end |
#hash ⇒ Integer
Use ‘#fullname` to calculate a hash value for the feature file.
201 202 203 |
# File 'lib/library/feature.rb', line 201 def hash fullname.hash end |
#library_activate ⇒ Object
67 68 69 |
# File 'lib/library/feature.rb', line 67 def library_activate library.activate if Library === library end |
#library_name ⇒ String
Name of the library to which the feature belongs.
60 61 62 |
# File 'lib/library/feature.rb', line 60 def library_name Library === library ? library.name : nil end |
#load(options = {}) ⇒ true, false
Load feature.
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/library/feature.rb', line 139 def load(={}) if library_name == 'ruby' or library_name == 'site_ruby' $" << localname # ruby 1.8 does not use absolutes end Library.load_stack << self #library begin library_activate unless [:force] success = __load__(fullname, [:wrap]) #rescue ::LoadError => load_error # raise LoadError.new(localname, library_name) ensure Library.load_stack.pop end success end |
#localname ⇒ String
The path of the feature relative to the loadpath.
94 95 96 |
# File 'lib/library/feature.rb', line 94 def localname @localname ||= ::File.join(filename + (extension || '')) end |
#location ⇒ String
Library location.
76 77 78 |
# File 'lib/library/feature.rb', line 76 def location Library===library ? library.location : library end |
#require(options = {}) ⇒ true, false
Require feature.
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/library/feature.rb', line 116 def require(={}) if library_name == 'ruby' or library_name == 'site_ruby' return false if $".include?(localname) # ruby 1.8 does not use absolutes $" << localname # ruby 1.8 does not use absolutes end Library.load_stack << self #library begin library_activate unless [:force] success = __require__(fullname) #rescue ::LoadError => load_error # TODO: deativeate this if $DEBUG ? # raise LoadError.new(localname, library_name) ensure Library.load_stack.pop end success end |
#to_s ⇒ String
Same a fullname.
183 184 185 |
# File 'lib/library/feature.rb', line 183 def to_s fullname end |
#to_str ⇒ String
Same a fullname.
192 193 194 |
# File 'lib/library/feature.rb', line 192 def to_str fullname end |