Class: Trith::Cache
- Inherits:
-
RDF::Repository
- Object
- RDF::Repository
- Trith::Cache
- Defined in:
- lib/trith/cache.rb
Overview
The Trith code cache.
Class Method Summary (collapse)
- + (Trith::Cache) load(*filenames)
-
+ (Trith::Cache) load_core
Returns a cache containing all core functions.
Instance Method Summary (collapse)
-
- (Enumerator<Trith::Function>) each_function(&block)
Enumerates each function in the cache.
-
- (Enumerator<Trith::Function>) find_functions(options = {}, &block)
Finds functions fulfilling the given criteria.
-
- (Boolean) has_function?(function)
Returns
trueif the givenfunctionis cached. -
- (Boolean) has_label?(label, options = {})
Returns
trueif a function with the givenlabelis cached. -
- (Cache) initialize(options = {}, &block)
constructor
A new instance of Cache.
Constructor Details
- (Cache) initialize(options = {}, &block)
A new instance of Cache
28 29 30 31 |
# File 'lib/trith/cache.rb', line 28 def initialize( = {}, &block) @data = [] super(, &block) end |
Class Method Details
+ (Trith::Cache) load(*filenames)
18 19 20 21 22 23 24 |
# File 'lib/trith/cache.rb', line 18 def self.load(*filenames) self.new do |repository| filenames.each do |filename| repository.load(filename) end end end |
+ (Trith::Cache) load_core
Returns a cache containing all core functions.
11 12 13 |
# File 'lib/trith/cache.rb', line 11 def self.load_core load(*Dir.glob(File.(File.join(File.dirname(__FILE__), '..', '..', 'etc', '*.nt')))) end |
Instance Method Details
- (Enumerator<Trith::Function>) each_function(&block)
Enumerates each function in the cache.
61 62 63 64 65 66 67 68 69 |
# File 'lib/trith/cache.rb', line 61 def each_function(&block) unless block_given? Enumerator.new(self, :each_function) else query(:predicate => RDF.type, :object => Trith::Function::URI) do |statement| block.call(Trith::Function.new(statement.subject, :data => self)) end end end |
- (Enumerator<Trith::Function>) find_functions(options = {}, &block)
Finds functions fulfilling the given criteria.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/trith/cache.rb', line 77 def find_functions( = {}, &block) unless block_given? Enumerator.new(self, :find_functions, ) else # FIXME: would really need BGP query support in RDF.rb... each_function do |function| if .empty? block.call(function) else pattern = case when [:label] {:predicate => RDF::RDFS.label, :object => [:label].to_s} else {} end block.call(function) unless query({:subject => function.id}.merge(pattern)).empty? end end end end |
- (Boolean) has_function?(function)
Returns true if the given function is cached.
38 39 40 41 42 43 44 |
# File 'lib/trith/cache.rb', line 38 def has_function?(function) id = case function when Trith::Function then function.id else Trith::Function.new(function).id end !query(:subject => id, :predicate => RDF.type, :object => Trith::Function::URI).empty? end |
- (Boolean) has_label?(label, options = {})
Returns true if a function with the given label is cached.
53 54 55 |
# File 'lib/trith/cache.rb', line 53 def has_label?(label, = {}) !query(:predicate => RDF::RDFS.label, :object => RDF::Literal.new(label.to_s, )).empty? end |