Module: YeshouaCrm::ActsAsDraftable::InstanceMethods
- Defined in:
- lib/yeshoua_crm/acts_as_draftable/rcrm_acts_as_draftable.rb
Overview
ClassMethods
Instance Method Summary collapse
- #dump_to_draft ⇒ Object
- #load_from_draft(string) ⇒ Object
- #save_draft(user = nil) ⇒ Object
- #update_draft(user, attributes) ⇒ Object
Instance Method Details
#dump_to_draft ⇒ Object
110 111 112 |
# File 'lib/yeshoua_crm/acts_as_draftable/rcrm_acts_as_draftable.rb', line 110 def dump_to_draft Marshal.dump(instance_values) end |
#load_from_draft(string) ⇒ Object
114 115 116 117 118 119 120 |
# File 'lib/yeshoua_crm/acts_as_draftable/rcrm_acts_as_draftable.rb', line 114 def load_from_draft(string) values = Marshal.load(string) values.each do |name, value| instance_variable_set("@#{name}", value) end end |
#save_draft(user = nil) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/yeshoua_crm/acts_as_draftable/rcrm_acts_as_draftable.rb', line 88 def save_draft(user = nil) return false unless self.new_record? draft = Draft.find_by_id(self.draft_id) || Draft.new draft.data = dump_to_draft draft.target_type = self.class.name draft.user = user draft.parent = self.send(self.class.draft_parent) if self.class.draft_parent result = draft.save self.draft_id = draft.id if result result end |
#update_draft(user, attributes) ⇒ Object
103 104 105 106 107 108 |
# File 'lib/yeshoua_crm/acts_as_draftable/rcrm_acts_as_draftable.rb', line 103 def update_draft(user, attributes) with_transaction_returning_status do assign_attributes(attributes) save_draft(user) end end |