Class: FabulatorExhibitExtension::Type

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

Instance Method Summary collapse

Constructor Details

#initialize(t) ⇒ Type

Returns a new instance of Type.



216
217
218
219
# File 'lib/fabulator_exhibit_extension/database.rb', line 216

def initialize(t)
  @type = t
  @raw_data = ( JSON.parse(t.data) rescue {} )
end

Instance Method Details

#[](k) ⇒ Object



221
222
223
# File 'lib/fabulator_exhibit_extension/database.rb', line 221

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

#[]=(k, v) ⇒ Object



225
226
227
228
# File 'lib/fabulator_exhibit_extension/database.rb', line 225

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

#delete(k) ⇒ Object



230
231
232
233
# File 'lib/fabulator_exhibit_extension/database.rb', line 230

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

#each_pair(&block) ⇒ Object



235
236
237
238
239
# File 'lib/fabulator_exhibit_extension/database.rb', line 235

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

#merge!(hash) ⇒ Object



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

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

#saveObject



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

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

#save!Object



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

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