Sha256: b68a91288687addb26915f1f23c103606c476c2c6053ac63a46c56a1a031866d

Contents?: true

Size: 511 Bytes

Versions: 5

Compression:

Stored size: 511 Bytes

Contents

module Drafting
  module ClassMethods
    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

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
drafting-0.5.1 lib/drafting/class_methods.rb
drafting-0.5.0 lib/drafting/class_methods.rb
drafting-0.4.2 lib/drafting/class_methods.rb
drafting-0.4.1 lib/drafting/class_methods.rb
drafting-0.4.0 lib/drafting/class_methods.rb