Class: FabulatorExhibitExtension::PropertyCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/fabulator_exhibit_extension/database.rb

Instance Method Summary collapse

Constructor Details

#initialize(db) ⇒ PropertyCollection

Returns a new instance of PropertyCollection.



73
74
75
# File 'lib/fabulator_exhibit_extension/database.rb', line 73

def initialize(db)
  @db = db
end

Instance Method Details

#[](nom) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/fabulator_exhibit_extension/database.rb', line 77

def [](nom)
  ob = nil
  begin
    ob = @db.fabulator_exhibit_properties.find(:first, [ 'name = ?', nom ])
  rescue
    ob = nil
  end
  if ob.nil?
    ob = FabulatorExhibitProperty.new({
      :name => nom,
      :fabulator_exhibit_id => @db.id
    })
  end
  Property.new(ob)
end

#[]=(nom, hash) ⇒ Object



93
94
95
96
97
98
99
# File 'lib/fabulator_exhibit_extension/database.rb', line 93

def []=(nom, hash)
  ob = self[nom]
  hash.each_pair do |k,v|
    ob[k] = v
  end
  ob.save
end

#to_jsonObject



101
102
103
104
105
106
107
# File 'lib/fabulator_exhibit_extension/database.rb', line 101

def to_json
  '{' +
  @db.fabulator_exhibit_properties.find(:all).collect{ |p|
    p.name.to_json + ":" + p.data
  }.join(", ") +
  '}'
end