Sha256: 66fb6e6879fe3e5e076dee360a88e8ee20b15bf078c70a8f877f97a240484208

Contents?: true

Size: 517 Bytes

Versions: 5

Compression:

Stored size: 517 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.3.1 lib/drafting/class_methods.rb
drafting-0.3.0 lib/drafting/class_methods.rb
drafting-0.2.0 lib/drafting/class_methods.rb
drafting-0.1.1 lib/drafting/class_methods.rb
drafting-0.1.0 lib/drafting/class_methods.rb