Sha256: c2cb608255f4f7e7be94c5a9fc413c871443d976310c3569358694062548f308

Contents?: true

Size: 1.14 KB

Versions: 2

Compression:

Stored size: 1.14 KB

Contents

module Vedeu

  # Repository for storing and retrieving content offsets; i.e. scroll
  # position for a named interface.
  #
  # @api private
  module Offsets

    include Repository
    extend self

    # Add or update the offset coordinates.
    #
    # @param attributes [Hash]
    # @return [Offset]
    def add(attributes)
      validate_attributes!(attributes)

      Vedeu.log("#{action(__callee__)} positional (#{model}): " \
                "'#{attributes[:name]}'")

      model.new(attributes).store
    end
    alias_method :update, :add

    # @return [Array]
    def down
      move(1, 0)
    end

    # @return [Array]
    def up
      move(-1, 0)
    end

    # @return [Array]
    def right
      move(0, 1)
    end

    # @return [Array]
    def left
      move(0, -1)
    end

    private

    # @param y [Fixnum]
    # @param x [Fixnum]
    # @return [Array]
    def move(y, x)
      find_or_create(Focus.current).move(y, x)

      Focus.refresh
    end

    # @return [Class] The model class for this repository.
    def model
      Vedeu::Offset
    end

    # @return [Hash]
    def in_memory
      {}
    end

  end # Offsets

end # Vedeu

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
vedeu-0.2.12 lib/vedeu/repositories/offsets.rb
vedeu-0.2.11 lib/vedeu/repositories/offsets.rb