Class: FabulatorExhibitExtension::Property

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

Instance Method Summary collapse

Constructor Details

#initialize(p) ⇒ Property

Returns a new instance of Property.



258
259
260
261
# File 'lib/fabulator_exhibit_extension/database.rb', line 258

def initialize(p)
  @property = p
  @raw_data = ( JSON.parse(p.data) rescue {} )
end

Instance Method Details

#[](k) ⇒ Object



263
264
265
# File 'lib/fabulator_exhibit_extension/database.rb', line 263

def [](k)
  @raw_data[k]
end

#[]=(k, v) ⇒ Object



267
268
269
270
# File 'lib/fabulator_exhibit_extension/database.rb', line 267

def []=(k,v)
  @raw_data[k] = v
  self.save
end

#delete(k) ⇒ Object



272
273
274
275
# File 'lib/fabulator_exhibit_extension/database.rb', line 272

def delete(k)
  @raw_data.delete(k)
  self.save
end

#each_pair(&block) ⇒ Object



277
278
279
280
281
# File 'lib/fabulator_exhibit_extension/database.rb', line 277

def each_pair(&block)
  @raw_data.each_pair do |k,v|
    yield k,v
  end
end

#merge!(hash) ⇒ Object



283
284
285
286
# File 'lib/fabulator_exhibit_extension/database.rb', line 283

def merge!(hash)
  @raw_data.merge!(hash)
  self.save
end

#saveObject



288
289
290
291
# File 'lib/fabulator_exhibit_extension/database.rb', line 288

def save
  @property.data = @raw_data.to_json
  @property.save
end

#save!Object



293
294
295
296
# File 'lib/fabulator_exhibit_extension/database.rb', line 293

def save!
  @property.data = @raw_data.to_json
  @property.save!
end