Sha256: f8edae61886384a4e911b5e6429a5dc0b775c7c478f78bbd587e4999cddd04d5

Contents?: true

Size: 1.17 KB

Versions: 7

Compression:

Stored size: 1.17 KB

Contents

# encoding: UTF-8

module Spontaneous::Plugins
  module Entry
    extend ActiveSupport::Concern

    # InstanceMethods

    # kept to allow access to pages & pieces as they would be seen when
    # accessed as an entry in a box
    def entry
      self
    end

    def box_sid
      @box_sid ||= Spontaneous.schema.uids[self[:box_sid]]
    end

    def box_sid=(sid)
      self[:box_sid] = sid.to_s
    end

    def box
      owner.boxes.sid(box_sid) if owner
    end

    alias_method :container,  :box

    def first?
      container.contents.first == self
    end

    def last?
      container.contents.last == self
    end

    def next
      return nil if last?
      container.contents[position + 1]
    end

    def previous
      return nil if first?
      container.contents[position - 1]
    end

    alias_method :prev, :previous

    def set_position(new_position)
      if box
        box.set_position(self, new_position)
      else
        owner.pieces.set_position(self, new_position)
      end
    end

    def position
      return box.index(self) if box
      owner.pieces.index(self)
    end

    def serialize_db
      [self.id]
    end
  end # Entry
end # Spontaneous::Plugins

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
spontaneous-0.2.0.alpha7 lib/spontaneous/plugins/entry.rb
spontaneous-0.2.0.alpha6 lib/spontaneous/plugins/entry.rb
spontaneous-0.2.0.alpha5 lib/spontaneous/plugins/entry.rb
spontaneous-0.2.0.alpha4 lib/spontaneous/plugins/entry.rb
spontaneous-0.2.0.alpha3 lib/spontaneous/plugins/entry.rb
spontaneous-0.2.0.alpha2 lib/spontaneous/plugins/entry.rb
spontaneous-0.2.0.alpha1 lib/spontaneous/plugins/entry.rb