Class: Spectro::Database
- Inherits:
-
Object
- Object
- Spectro::Database
- Extended by:
- Forwardable
- Includes:
- Singleton
- Defined in:
- lib/spectro/database.rb
Overview
Gives access to the current collection of algorithms (lambdas) providing several ways to fetch specific elements by different criteria.
Instance Attribute Summary collapse
-
#cache ⇒ Object
Returns the value of attribute cache.
Instance Method Summary collapse
-
#fetch(file_path, method_name, *required_params) ⇒ Proc
Fetches and returns the target lambda based on the given class, method name and required aprameters.
-
#index ⇒ Hash
Lazy loads the index.yml and returns it.
-
#initialize ⇒ Database
constructor
A new instance of Database.
-
#reset_index ⇒ Object
Sets the index cache to nil Just in case you want the database to parse the file once again.
Constructor Details
#initialize ⇒ Database
Returns a new instance of Database.
17 18 19 |
# File 'lib/spectro/database.rb', line 17 def initialize self.cache = {} end |
Instance Attribute Details
#cache ⇒ Object
Returns the value of attribute cache.
15 16 17 |
# File 'lib/spectro/database.rb', line 15 def cache @cache end |
Instance Method Details
#fetch(file_path, method_name, *required_params) ⇒ Proc
Fetches and returns the target lambda based on the given class, method name and required aprameters.
41 42 43 44 45 46 47 |
# File 'lib/spectro/database.rb', line 41 def fetch file_path, method_name, *required_params if self.index["#{file_path}"].nil? || self.index["#{file_path}"]["#{method_name}"].nil? return nil end λ_id = self.index["#{file_path}"]["#{method_name}"]['lambda_id'] return self.cache[λ_id] ||= eval(File.read(".spectro/cache/#{λ_id}.rb")) end |
#index ⇒ Hash
Lazy loads the index.yml and returns it
24 25 26 |
# File 'lib/spectro/database.rb', line 24 def index return @index ||= load_index() end |
#reset_index ⇒ Object
Sets the index cache to nil Just in case you want the database to parse the file once again
30 31 32 |
# File 'lib/spectro/database.rb', line 30 def reset_index @index = nil end |