Sha256: 42bfbb4f14a02a90350f4e72c429b0dab5abcb3a1812e543a6ffdb0edcc56e46

Contents?: true

Size: 1 KB

Versions: 7

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

require 'active_support/concern'

module Lcms
  module Engine
    module Navigable
      extend ActiveSupport::Concern

      included do
        def parents
          ancestors.reverse
        end

        def previous
          @previous ||= begin
            return unless level_position

            if level_position.positive?
              siblings.where(level_position: level_position - 1).first
            else
              # last element of previous node from parent level
              parent.try(:previous).try(:children).try(:last)
            end
          end
        end

        def next
          @next ||= begin
            return unless level_position

            if level_position < siblings.size
              siblings.where(level_position: level_position + 1).first
            else
              # first element of next node from parent level
              parent.try(:next).try(:children).try(:first)
            end
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
lcms-engine-0.3.1 app/models/concerns/lcms/engine/navigable.rb
lcms-engine-0.1.4 app/models/concerns/lcms/engine/navigable.rb
lcms-engine-0.3.0 app/models/concerns/lcms/engine/navigable.rb
lcms-engine-0.1.3 app/models/concerns/lcms/engine/navigable.rb
lcms-engine-0.2.0 app/models/concerns/lcms/engine/navigable.rb
lcms-engine-0.1.2 app/models/concerns/lcms/engine/navigable.rb
lcms-engine-0.1.0 app/models/concerns/lcms/engine/navigable.rb