Class: FabulatorExhibitExtension::Type
- Inherits:
-
Object
- Object
- FabulatorExhibitExtension::Type
- Defined in:
- lib/fabulator_exhibit_extension/database.rb
Instance Method Summary collapse
- #[](k) ⇒ Object
- #[]=(k, v) ⇒ Object
- #delete(k) ⇒ Object
- #each_pair(&block) ⇒ Object
-
#initialize(t) ⇒ Type
constructor
A new instance of Type.
- #merge!(hash) ⇒ Object
- #save ⇒ Object
- #save! ⇒ Object
Constructor Details
#initialize(t) ⇒ Type
Returns a new instance of Type.
191 192 193 194 |
# File 'lib/fabulator_exhibit_extension/database.rb', line 191 def initialize(t) @type = t @raw_data = ( JSON.parse(t.data) rescue {} ) end |
Instance Method Details
#[](k) ⇒ Object
196 197 198 |
# File 'lib/fabulator_exhibit_extension/database.rb', line 196 def [](k) @raw_data[k] end |
#[]=(k, v) ⇒ Object
200 201 202 203 |
# File 'lib/fabulator_exhibit_extension/database.rb', line 200 def []=(k,v) @raw_data[k] = v self.save end |
#delete(k) ⇒ Object
205 206 207 208 |
# File 'lib/fabulator_exhibit_extension/database.rb', line 205 def delete(k) @raw_data.delete(k) self.save end |
#each_pair(&block) ⇒ Object
210 211 212 213 214 |
# File 'lib/fabulator_exhibit_extension/database.rb', line 210 def each_pair(&block) @raw_data.each_pair do |k,v| yield k,v end end |
#merge!(hash) ⇒ Object
216 217 218 219 |
# File 'lib/fabulator_exhibit_extension/database.rb', line 216 def merge!(hash) @raw_data.merge!(hash) self.save end |
#save ⇒ Object
221 222 223 224 |
# File 'lib/fabulator_exhibit_extension/database.rb', line 221 def save @type.data = @raw_data.to_json @type.save end |
#save! ⇒ Object
226 227 228 229 |
# File 'lib/fabulator_exhibit_extension/database.rb', line 226 def save! @type.data = @raw_data.to_json @type.save! end |