Module: YeshouaCrm::ActsAsDraftable::ClassMethods

Defined in:
lib/yeshoua_crm/acts_as_draftable/rcrm_acts_as_draftable.rb

Overview

Base

Instance Method Summary collapse

Instance Method Details

#draftable?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/yeshoua_crm/acts_as_draftable/rcrm_acts_as_draftable.rb', line 66

def draftable?
  true
end

#drafts(user) ⇒ Object



82
83
84
# File 'lib/yeshoua_crm/acts_as_draftable/rcrm_acts_as_draftable.rb', line 82

def drafts(user)
  Draft.where(user: user, target_type: name)
end

#from_draft(draft_or_id) ⇒ Object

Raises:

  • (ArgumentError)


70
71
72
73
74
75
76
77
78
79
80
# File 'lib/yeshoua_crm/acts_as_draftable/rcrm_acts_as_draftable.rb', line 70

def from_draft(draft_or_id)
  draft = draft_or_id.is_a?(Draft) ? draft_or_id : Draft.find(draft_or_id)
  raise ArgumentError unless draft.target_type == name

  target = draft.target_type.constantize.new
  target.load_from_draft(draft.data)

  target.send("#{draft_parent}=", draft.parent) if draft_parent
  target.draft_id = draft.id
  target
end