Sha256: bdbff86dd8834b250499713028a5c78648d88cf7da00635d19efcaea80681d35

Contents?: true

Size: 1.08 KB

Versions: 18

Compression:

Stored size: 1.08 KB

Contents

# encoding: UTF-8

module Spontaneous::Collections
  class ChangeSet
    attr_reader :changes

    def initialize(changes)
      @changes = changes.map do |change_or_id|
        change_or_id.is_a?(Spontaneous::Change) ? change_or_id : Spontaneous::Change[change_or_id]
      end
    end

    def pages
      @pages ||= page_ids.map { |id| Spontaneous::Content[id] }
    end

    def page_ids
      @page_ids ||= changes.inject([]) { |a, c| a += c.modified_list; a }.uniq.sort
    end

    def export
      h = {
        :changes => changes.map { |c| c.export },
      }
      # use compact because it's possible that some pages have been deleted since
      # the change was created and the best way to deal with them is to silently
      # ignore them and let the publishing mech delete them as usual
      h[:pages] = pages.compact.map  do |page|
        {
          :id => page.id,
          :title => page.title.to_s,
          :path => page.path,
          :depth => page.depth
        }
      end
      h
    end
    # def serialise_http
    #   Spontaneous.serialise_http(export)
    # end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
spontaneous-0.2.0.beta10 lib/spontaneous/collections/change_set.rb
spontaneous-0.2.0.beta9 lib/spontaneous/collections/change_set.rb
spontaneous-0.2.0.beta8 lib/spontaneous/collections/change_set.rb
spontaneous-0.2.0.beta7 lib/spontaneous/collections/change_set.rb
spontaneous-0.2.0.beta6 lib/spontaneous/collections/change_set.rb
spontaneous-0.2.0.beta5 lib/spontaneous/collections/change_set.rb
spontaneous-0.2.0.beta4 lib/spontaneous/collections/change_set.rb
spontaneous-0.2.0.beta3 lib/spontaneous/collections/change_set.rb
spontaneous-0.2.0.beta2 lib/spontaneous/collections/change_set.rb
spontaneous-0.2.0.beta1 lib/spontaneous/collections/change_set.rb
spontaneous-0.2.0.alpha7 lib/spontaneous/collections/change_set.rb
spontaneous-0.2.0.alpha6 lib/spontaneous/collections/change_set.rb
spontaneous-0.2.0.alpha5 lib/spontaneous/collections/change_set.rb
spontaneous-0.2.0.alpha4 lib/spontaneous/collections/change_set.rb
spontaneous-0.2.0.alpha3 lib/spontaneous/collections/change_set.rb
spontaneous-0.2.0.alpha2 lib/spontaneous/collections/change_set.rb
spontaneous-0.2.0.alpha1 lib/spontaneous/collections/change_set.rb
spontaneous-0.1.0.alpha1 lib/spontaneous/collections/change_set.rb