Sha256: c926d8d8f6fc7f113c8d69e5ab95059a0b2f99154cc355818a7eb3c472630324

Contents?: true

Size: 1.02 KB

Versions: 19

Compression:

Stored size: 1.02 KB

Contents

module Trestle
  class Breadcrumb
    attr_reader :label, :path

    def initialize(label, path=nil)
      @label, @path = label, path
    end

    def ==(other)
      label == other.label && path == other.path
    end

    def self.cast(obj)
      case obj
      when Breadcrumb
        obj
      when String
        new(obj)
      when Array
        new(*obj)
      when NilClass, false
        nil
      else
        raise ArgumentError, "Unable to cast #{obj.inspect} to Breadcrumb"
      end
    end

    class Trail
      include Enumerable

      def initialize(breadcrumbs=[])
        @breadcrumbs = Array(breadcrumbs).compact
      end

      def ==(other)
        to_a == other.to_a
      end

      def dup
        self.class.new(@breadcrumbs.dup)
      end

      def append(label, path=nil)
        @breadcrumbs << Breadcrumb.new(label, path)
      end

      def prepend(label, path=nil)
        @breadcrumbs.unshift(Breadcrumb.new(label, path))
      end

      delegate :each, :first, :last, to: :@breadcrumbs
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
trestle-0.10.1 lib/trestle/breadcrumb.rb
trestle-0.10.0 lib/trestle/breadcrumb.rb
trestle-0.10.0.pre2 lib/trestle/breadcrumb.rb
trestle-0.10.0.pre lib/trestle/breadcrumb.rb
trestle-0.9.8 lib/trestle/breadcrumb.rb
trestle-0.9.7 lib/trestle/breadcrumb.rb
trestle-0.9.6 lib/trestle/breadcrumb.rb
trestle-0.9.5 lib/trestle/breadcrumb.rb
trestle-0.9.4 lib/trestle/breadcrumb.rb
trestle-0.9.3 lib/trestle/breadcrumb.rb
trestle-0.9.2 lib/trestle/breadcrumb.rb
trestle-0.9.1 lib/trestle/breadcrumb.rb
trestle-0.9.0 lib/trestle/breadcrumb.rb
trestle-0.8.13 lib/trestle/breadcrumb.rb
trestle-0.8.12 lib/trestle/breadcrumb.rb
trestle-0.8.11 lib/trestle/breadcrumb.rb
trestle-0.8.10 lib/trestle/breadcrumb.rb
trestle-0.8.9 lib/trestle/breadcrumb.rb
trestle-0.8.8 lib/trestle/breadcrumb.rb