Sha256: 9535f1b0ed998968fc32aeae29107fa21a3f2215cbae6b2aa4efb44bbed9cea9

Contents?: true

Size: 1.22 KB

Versions: 8

Compression:

Stored size: 1.22 KB

Contents

# encoding: UTF-8

module Spontaneous::Model::Core
  module Entry
    extend Spontaneous::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 ||= mapper.schema_uid(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
      return 0 if owner.nil? # special case for root
      owner.pieces.index(self)
    end

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

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
spontaneous-0.2.0.beta9 lib/spontaneous/model/core/entry.rb
spontaneous-0.2.0.beta8 lib/spontaneous/model/core/entry.rb
spontaneous-0.2.0.beta7 lib/spontaneous/model/core/entry.rb
spontaneous-0.2.0.beta6 lib/spontaneous/model/core/entry.rb
spontaneous-0.2.0.beta5 lib/spontaneous/model/core/entry.rb
spontaneous-0.2.0.beta4 lib/spontaneous/model/core/entry.rb
spontaneous-0.2.0.beta3 lib/spontaneous/model/core/entry.rb
spontaneous-0.2.0.beta2 lib/spontaneous/model/core/entry.rb