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.



233
234
235
236
# File 'lib/fabulator_exhibit_extension/database.rb', line 233

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

Instance Method Details

#[](k) ⇒ Object



238
239
240
# File 'lib/fabulator_exhibit_extension/database.rb', line 238

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

#[]=(k, v) ⇒ Object



242
243
244
245
# File 'lib/fabulator_exhibit_extension/database.rb', line 242

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

#delete(k) ⇒ Object



247
248
249
250
# File 'lib/fabulator_exhibit_extension/database.rb', line 247

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

#each_pair(&block) ⇒ Object



252
253
254
255
256
# File 'lib/fabulator_exhibit_extension/database.rb', line 252

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

#merge!(hash) ⇒ Object



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

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

#saveObject



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

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

#save!Object



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

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