Class: FabulatorExhibitExtension::Item

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

Instance Method Summary collapse

Constructor Details

#initialize(i) ⇒ Item

Returns a new instance of Item.



170
171
172
173
# File 'lib/fabulator_exhibit_extension/database.rb', line 170

def initialize(i)
  @item = i
  @raw_data = ( JSON.parse(i.data) rescue {} )
end

Instance Method Details

#[](k) ⇒ Object



179
180
181
# File 'lib/fabulator_exhibit_extension/database.rb', line 179

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

#[]=(k, v) ⇒ Object



183
184
185
186
# File 'lib/fabulator_exhibit_extension/database.rb', line 183

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

#delete(k) ⇒ Object



175
176
177
# File 'lib/fabulator_exhibit_extension/database.rb', line 175

def delete
  @item.delete
end

#each_pair(&block) ⇒ Object



193
194
195
196
197
# File 'lib/fabulator_exhibit_extension/database.rb', line 193

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

#merge!(hash) ⇒ Object



199
200
201
202
# File 'lib/fabulator_exhibit_extension/database.rb', line 199

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

#saveObject



204
205
206
207
# File 'lib/fabulator_exhibit_extension/database.rb', line 204

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

#save!Object



209
210
211
212
# File 'lib/fabulator_exhibit_extension/database.rb', line 209

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