Whack the draft data onto the real object.

 @return [Draftable] the draftable object populated with the draft attrs.
976627
def restore_attrs
      draftable_columns.each do |key|
        self.send "#{key}=", self.draft.data[key] if self.respond_to?(key)
      end
      self
    end
773350
def make_patch( expected, actual )
      diffs = Diff::LCS.sdiff( expected.split("\n"), actual.split("\n"),
        Diff::LCS::ContextDiffCallbacks )

      maxcol = diffs.flatten.
        collect {|d| [d.old_element.to_s.length, d.new_element.to_s.length ] }.
        flatten.max || 0
      maxcol += 4

      patch = "              %#{maxcol}s | %s\n" % [ "Expected", "Actual" ]
      patch << diffs.collect do |changeset|
        changeset.collect do |change|
          "%s [%03d, %03d]: %#{maxcol}s | %-#{maxcol}s" % [
            change.action,
            change.old_position,
            change.new_position,
            change.old_element.inspect,
            change.new_element.inspect,
          ]
        end.join("\n")
      end.join("\n---\n")
    end
682509
def get_draft_url(url):
    
    if verify_draft_url(url):
        # Nothing to do. Already a valid draft URL.
        return url
    # Parse querystring and add draft mode HMAC.
    url = urlparse.urlparse(url)
    salt = get_random_string(5)
    # QueryDict requires a bytestring as its first argument
    query = QueryDict(force_bytes(url.query), mutable=True)
    query['preview'] = '%s:%s' % (salt, get_draft_hmac(salt, url.path))
    # Reconstruct URL.
    parts = list(url)
    parts[4] = query.urlencode(safe=':')
    return urlparse.urlunparse(parts)
357701
def write
      new = get
      new[@note] = @token
      File.open(@file, 'w', 0o0600) { |fh| fh.write new.to_yaml }
    end
551658
def attributes
      (@original_attributes||{}).merge(@attributes).keys.inject({}) do |hash, key|
        hash[key] = read_attribute(key)
        hash
      end
    end
1009516
def serialize_attributes
    attr_hash = {}
    @attributes.each_pair do |name,value|
      attr_hash[name] = serialize_attribute(name,value)
    end
    attr_hash[:id] = serialize_id unless new?
    attr_hash
  end
537137
def maybe_automatically_publish_drafts_on_save(sender, instance, **kwargs):
    
    # Skip processing if auto-publishing is not enabled
    if not is_automatic_publishing_enabled(sender):
        return
    # Skip missing or unpublishable instances
    if not instance or not hasattr(instance, 'publishing_linked'):
        return
    # Ignore saves of published copies
    if instance.is_published:
        return
    # Ignore saves of already-published draft copies
    if not instance.is_dirty:
        return
    # Immediately publish saved draft copy
    instance.publish()
231542
def save(self, *args, **kwargs):
        
        with xact():
            if not self.vid:
                self.state = self.DRAFT

                if not self.object_id:
                    base = self._meta._base_model(is_published=False)
                    base.save(*args, **kwargs)
                    self.object = base

            super(VersionModel, self).save(*args, **kwargs)
183373
def writeable_attributes(*attrs)
      @writeable_attributes ||= []
      if attrs.any?
        @writeable_attributes.map!(&:to_sym).concat(attrs).uniq! if attrs.any?
        setup_attributes(@writeable_attributes, false)
      end
      @writeable_attributes
    end
1234741
def save
      run_callbacks(:before_save)
      run_callbacks(:before_create) unless self.is_created

      existing_items = self.class.all
      if self.new_record?
        existing_items << self
      else # update existing record
        updated_item = existing_items.find { |item| item.id == self.id }
        return false unless updated_item
        updated_item.attributes = self.attributes
      end

      raw_data = existing_items ? existing_items.map { |item| item.persisted_attributes } : []
      self.class.write_contents(raw_data) if self.valid?

      run_callbacks(:after_create) unless self.is_created
      run_callbacks(:after_save)
      true
    rescue IOError
      false
    end
474309
def can_publish(self):
        
        with self.published_context():
            published = self.one(
                Q._uid == self._uid,
                projection={'revision': True}
                )

        if not published:
            return True

        with self.draft_context():
            draft = self.one(Q._uid == self._uid, projection={'revision': True})

        return draft.revision > published.revision
1275478
def physicalize(options = {})

            @revisions.each do |revision|
                # Do not use each_object here as build_object may modify the iterator.
                revision.objects.each do |obj|
                    build_object(obj, revision, options)
                end
            end

            self
        end
134285
def create(&block)
      register
      self.instance_eval(&block) if block_given?
      content = self.to_ruby
      fullpath = File.join(self.class.bindir, filename)
      #puts "creating double: #{fullpath} with content:\n#{content}" # debug
      f = File.open(fullpath, 'w')
      f.puts content
      f.close
      FileUtils.chmod(0755, File.join(self.class.bindir, filename))
      self
    end
362630
def create(attributes_hash)
      #the tap method allows preconfigured methods and values to
      #be associated with the instance during instantiation while also automatically returning
      #the object after its creation is concluded.
      self.new.tap do |card|
        attributes_hash.each do |key, value|
          #sending the new instance the key name as a setter with the value
          card.send("#{key}=", value)
          #string interpolation is used as the method doesn't know the key name yet
          #but an = sign is implemented into the string in order to asssociate it as a setter
        end
        #saves the new instance into the database
        card.save
      end
    end
1000852
def article2draft(article):
    ''''''
    draft = Draft(article._content, article.metadata, article.settings,
                  article.source_path, article._context)
    draft.status = 'draft'
    return draft
51885
def save_draft(parent_draft=nil, parent_association_name=nil)
      if valid?
        do_create_draft(parent_draft, parent_association_name)
        create_subdrafts
      end
      return self.draft.reload if self.draft
    end
415115
def pre_build #:nodoc:
            load!

            prolog = ""
            data = ""
            objoff = 0
            @objects.to_a.sort.each do |num,obj|

                obj.set_indirect(false)
                obj.objstm_offset = objoff

                prolog << "#{num} #{objoff} "
                objdata = "#{obj} "

                objoff += objdata.size
                data << objdata
                obj.set_indirect(true)
                obj.no = num
            end

            self.data = prolog + data

            @dictionary[:N] = @objects.size
            @dictionary[:First] = prolog.size

            super
        end