Class: NanoSystem
Overview
The NanoSystem module provides meta-information on all nano-methods.
Constant Summary collapse
- REQUIRE_DIR =
'nano'
- DATA_DIR =
File.join( Config::CONFIG['datadir'], 'site_ruby/nano' )
Instance Attribute Summary collapse
-
#base ⇒ Object
readonly
instance_level.
-
#full ⇒ Object
readonly
instance_level.
-
#noauto ⇒ Object
readonly
instance_level.
-
#unsafe ⇒ Object
readonly
instance_level.
Class Method Summary collapse
Instance Method Summary collapse
-
#[](classname) ⇒ Object
Returns a nano method lookup hash for given classname.
-
#classes ⇒ Object
(also: #modules)
Returns list of class/module names with available nano methods.
-
#each(&blk) ⇒ Object
iterate through classes { |classname, methodhash| … }.
-
#files(classname = nil) ⇒ Object
# Returns a list of all nano method names for a given class/module name.
-
#index ⇒ Object
top level storage.
-
#initialize ⇒ NanoSystem
constructor
A new instance of NanoSystem.
-
#load ⇒ Object
Load nano data.
-
#require(klass, *meths) ⇒ Object
Require method nano(s) for given class/module.
Constructor Details
#initialize ⇒ NanoSystem
Returns a new instance of NanoSystem.
55 56 57 58 59 |
# File 'lib/nanosys.rb', line 55 def initialize Object.send( :require, 'yaml' ) Object.send( :require, 'rbconfig' ) load end |
Instance Attribute Details
#base ⇒ Object (readonly)
instance_level
53 54 55 |
# File 'lib/nanosys.rb', line 53 def base @base end |
#full ⇒ Object (readonly)
instance_level
53 54 55 |
# File 'lib/nanosys.rb', line 53 def full @full end |
#noauto ⇒ Object (readonly)
instance_level
53 54 55 |
# File 'lib/nanosys.rb', line 53 def noauto @noauto end |
#unsafe ⇒ Object (readonly)
instance_level
53 54 55 |
# File 'lib/nanosys.rb', line 53 def unsafe @unsafe end |
Class Method Details
.__new__ ⇒ Object
39 |
# File 'lib/nanosys.rb', line 39 alias __new__ new |
.method_missing(meth, *args, &blk) ⇒ Object
45 46 47 48 |
# File 'lib/nanosys.rb', line 45 def method_missing( meth, *args, &blk ) @instance ||= __new__ @instance.send( meth, *args, &blk ) end |
.new ⇒ Object
40 41 42 |
# File 'lib/nanosys.rb', line 40 def new raise NoMethodError, 'cannot instantiate auto-singleton class' end |
Instance Method Details
#[](classname) ⇒ Object
Returns a nano method lookup hash for given classname.
129 130 131 |
# File 'lib/nanosys.rb', line 129 def []( classname ) index[classname.to_s.downcase] end |
#classes ⇒ Object Also known as: modules
Returns list of class/module names with available nano methods.
135 136 137 |
# File 'lib/nanosys.rb', line 135 def classes index.keys.sort end |
#each(&blk) ⇒ Object
iterate through classes { |classname, methodhash| … }
124 125 126 |
# File 'lib/nanosys.rb', line 124 def each( &blk ) self.index.each &blk end |
#files(classname = nil) ⇒ Object
# Returns a list of all nano method names for a given class/module name.
# If no class/module name is give returns a list of all nano methods
# in the format of '<classname>#<methname>' for instance methods, and
# '<classname>.<methname>' for class/module methods.
def method_list( classname=nil )
lst = nil
if classname
lst = store[classname.to_s].keys if store.include? classname.to_s
else
lst = []
store.each { |classname, methmap|
methmap.each { |methname, path|
md = /^(self|#{classname})[.]/.match methname
lst << ( md ? "#{classname}.#{md.post_match}" : "#{classname}##{methname}" )
}
}
end
lst.sort
end
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/nanosys.rb', line 160 def files( classname=nil ) lst = [] if classname index[classname.to_s.downcase].each { |methname| lst << "#{classname}/#{methname}" } else index.each { |classname, methlist| methlist.each { |methname| lst << "#{classname}/#{methname}" } } end lst.uniq.sort end |
#index ⇒ Object
top level storage
119 120 121 |
# File 'lib/nanosys.rb', line 119 def index @index end |
#load ⇒ Object
Load nano data
62 63 64 65 |
# File 'lib/nanosys.rb', line 62 def load load_index load_info end |
#require(klass, *meths) ⇒ Object
Require method nano(s) for given class/module.
178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/nanosys.rb', line 178 def require( klass, *meths ) classname = klass.name.downcase raise "unknown class #{klass}" unless self.index.has_key?( classname ) success = true meths.each do |m| raise "unknown nano-method #{m}" unless self[ classname ].include?( m.to_s ) f = "#{NanoSystem::REQUIRE_DIR}/#{classname}/#{m}" r = Object.send( :require, f ) success = success && r end success end |