Module: TeronRecords
- Included in:
- Teron
- Defined in:
- lib/record.rb
Overview
Saving/Records Keeper
Instance Method Summary collapse
Instance Method Details
#attributes ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/record.rb', line 33 def attributes instance_variables.each_with_object({}) do |name, obj| key = name.to_s.delete('@').to_sym obj[key] = instance_variable_get(name) obj end end |
#destroy! ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/record.rb', line 23 def destroy! self.class._mutex.synchronize do self.class._data.delete id end self.class._obj_clear id true end |
#reload ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/record.rb', line 42 def reload klass_obj = self.class.find id instance_variables.each do |name| key = name.to_s.delete('@').to_sym instance_variable_set(name, klass_obj.send(key)) end true end |
#save! ⇒ Object Also known as: save
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/record.rb', line 3 def save! self.class._mutex.synchronize do # Handle Dump vs No Dump Variables payload = self.class.class_variable_get(:@@params).each_with_object({}) do |data, obj| value = attributes[data[:name]] obj[data[:name]] = data.dig(:options, :dump) ? Marshal.load(Marshal.dump(value)) : value obj end self.class._data[id] = payload end self.class._obj_clear id true end |