Class: FabulatorExhibitExtension::PropertyCollection
- Inherits:
-
Object
- Object
- FabulatorExhibitExtension::PropertyCollection
- Defined in:
- lib/fabulator_exhibit_extension/database.rb
Instance Method Summary collapse
- #[](nom) ⇒ Object
- #[]=(nom, hash) ⇒ Object
-
#initialize(db) ⇒ PropertyCollection
constructor
A new instance of PropertyCollection.
- #to_json ⇒ Object
Constructor Details
#initialize(db) ⇒ PropertyCollection
Returns a new instance of PropertyCollection.
90 91 92 93 |
# File 'lib/fabulator_exhibit_extension/database.rb', line 90 def initialize(db) @db = db @properties = { } end |
Instance Method Details
#[](nom) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/fabulator_exhibit_extension/database.rb', line 95 def [](nom) return @properties[nom] if @properties.include?(nom) ob = nil begin ob = @db.fabulator_exhibit_properties.find(:first, :conditions => [ 'name = ?', nom ]) rescue ob = nil end if ob.nil? ob = FabulatorExhibitProperty.new({ :name => nom, :fabulator_exhibit_id => @db.id }) end @properties[nom] ||= Property.new(ob) end |
#[]=(nom, hash) ⇒ Object
112 113 114 115 116 117 118 |
# File 'lib/fabulator_exhibit_extension/database.rb', line 112 def []=(nom, hash) ob = self[nom] hash.each_pair do |k,v| ob[k] = v end ob.save end |
#to_json ⇒ Object
120 121 122 123 124 125 126 |
# File 'lib/fabulator_exhibit_extension/database.rb', line 120 def to_json '{' + @db.fabulator_exhibit_properties.find(:all).collect{ |p| p.name.to_json + ":" + p.data }.join(", ") + '}' end |