Class: Fabulator::Exhibit::Lib
- Inherits:
-
TagLib
- Object
- TagLib
- Fabulator::Exhibit::Lib
- Defined in:
- lib/fabulator/exhibit/lib.rb
Constant Summary collapse
- @@databases =
{ }
Class Method Summary collapse
- .add_info(nom, t, item) ⇒ Object
-
.fetch_database(nom) ⇒ Object
should set up an empty database with :items, :types, and :properties.
- .get_database(nom) ⇒ Object
- .remove_info(nom, t, id) ⇒ Object
- .set_database(nom, data) ⇒ Object
- .store_database(nom, data) ⇒ Object
- .store_databases ⇒ Object
Instance Method Summary collapse
-
#items ⇒ Object
need to make this an iterator.
Class Method Details
.add_info(nom, t, item) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/fabulator/exhibit/lib.rb', line 52 def self.add_info(nom, t, item) @@databases ||= {} @@databases[nom] ||= self.fetch_database(nom) @@databases[nom][t][item['id']] ||= { } @@databases[nom][t][item['id']].merge!(item) @@databases[nom][t][item['id']].each_pair do |k,v| if v.nil? || (v.is_a?(Array) && v.empty?) || v.is_a?(String) && v == "" @@databases[nom][t][item['id']].delete(k) end end case t when :types, :properties @@databases[nom][t][item['id']].delete(:id) end end |
.fetch_database(nom) ⇒ Object
should set up an empty database with :items, :types, and :properties
30 31 32 |
# File 'lib/fabulator/exhibit/lib.rb', line 30 def self.fetch_database(nom) raise "fetch_database is not implemented by the framework." end |
.get_database(nom) ⇒ Object
38 39 40 |
# File 'lib/fabulator/exhibit/lib.rb', line 38 def self.get_database(nom) @@databases[nom] ||= self.fetch_database(nom) end |
.remove_info(nom, t, id) ⇒ Object
69 70 71 72 73 |
# File 'lib/fabulator/exhibit/lib.rb', line 69 def self.remove_info(nom, t, id) @@databases[nom] ||= self.fetch_database(nom) return if @@databases[nom][t].empty? @@databases[nom][t].delete(id) end |
.set_database(nom, data) ⇒ Object
42 43 44 |
# File 'lib/fabulator/exhibit/lib.rb', line 42 def self.set_database(nom, data) @@databases[nom] = data end |
.store_database(nom, data) ⇒ Object
34 35 36 |
# File 'lib/fabulator/exhibit/lib.rb', line 34 def self.store_database(nom, data) raise "store_database is not imeplemented by the framework." end |
.store_databases ⇒ Object
46 47 48 49 50 |
# File 'lib/fabulator/exhibit/lib.rb', line 46 def self.store_databases @@databases.keys.each do |k| self.store_database(k, @@databases[k]) end end |
Instance Method Details
#items ⇒ Object
need to make this an iterator
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/fabulator/exhibit/lib.rb', line 96 function 'items' do |ctx, args| nom = ctx.attribute(EXHIBIT_NS, 'database', { :inherited => true, :static => true }) db = Fabulator::Exhibit::Lib.get_database(nom) ret = ctx.root.anon_node(nil) db[:items].each_pair{ |id, item| i = ret.create_child(id, nil) item.each_pair do |k,v| next if k == "id" v = [ v ] unless v.is_a?(Array) v.each do |vv| i.create_child(k,vv) end end } [ ret ] end |