Sha256: 7ad0dc7993fc72e386d440c4ccf557463c801f2552abe2729266158449f0aaed

Contents?: true

Size: 1.14 KB

Versions: 19

Compression:

Stored size: 1.14 KB

Contents

module Gretel
  class Link
    attr_accessor :key, :text, :url, :options

    def initialize(key, text, url, options = {})
      # Use accessors so plugins can override their behavior
      self.key, self.text, self.url, self.options = key, text, url, options
    end

    # Sets current so +current?+ will return +true+.
    def current!
      @current = true
    end

    # Returns +true+ if this is the last link in the breadcrumb trail.
    def current?
      !!@current
    end

    # Enables accessors and predicate methods for values in the +options+ hash.
    # This can be used to pass information to links when rendering breadcrumbs
    # manually.
    #
    #   link = Link.new(:my_crumb, "My Crumb", my_path, title: "Test Title", other_value: "Other")
    #   link.title?       # => true
    #   link.title        # => "Test Title"
    #   link.other_value? # => true
    #   link.other_value  # => "Other"
    #   link.some_other?  # => false
    #   link.some_other   # => nil
    def method_missing(method, *args, &block)
      if method =~ /(.+)\?$/
        options[$1.to_sym].present?
      else
        options[method]
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 2 rubygems

Version Path
gretel-5.0.1 lib/gretel/link.rb
gretel-5.0.0 lib/gretel/link.rb
gretel-4.6.0 lib/gretel/link.rb
gretel-4.5.0 lib/gretel/link.rb
gretel-4.4.0 lib/gretel/link.rb
gretel-4.3.0 lib/gretel/link.rb
gretel-4.2.0 lib/gretel/link.rb
gretel-4.1.0 lib/gretel/link.rb
gretel-4.0.2 lib/gretel/link.rb
gretel-4.0.1 lib/gretel/link.rb
gretel-4.0.0 lib/gretel/link.rb
gretel-lite-3.0.10 lib/gretel/link.rb
gretel-3.0.9 lib/gretel/link.rb
gretel-3.0.8 lib/gretel/link.rb
gretel-3.0.7 lib/gretel/link.rb
gretel-3.0.6 lib/gretel/link.rb
gretel-3.0.5 lib/gretel/link.rb
gretel-3.0.4 lib/gretel/link.rb
gretel-3.0.3 lib/gretel/link.rb