Sha256: 7e99b14909964896b38619db9052459791109e6bcec2a3a014696783a7cd7c9b

Contents?: true

Size: 1.07 KB

Versions: 2

Compression:

Stored size: 1.07 KB

Contents

module Buoys
  class Buoy
    attr_reader :previous, :context
    # buoy :account do
    #   link 'Account', account_path
    # end
    #
    # buoy :account_edit do |account|
    #   link 'Account Show', show_account_path(account)
    #   link 'Account Edit', edit_account_path(account)
    #   pre_buoy :account
    # end
    def initialize(context, key, *args)
      block = Buoys::Loader.buoys[key]
      raise ArgumentError, "Buoys :#{key} is not found" unless block

      @key, @context = key, context
      instance_exec *args, &block
    end

    def link(key, *args)
      options = args.extract_options!
      path = args.shift
      url = path ? context.url_for(path) : path

      text = I18n.t(key, scope: 'buoys.breadcrumbs', default: key)

      links << Buoys::Link.new(text, url, options)
    end

    def links
      @links ||= []
    end

    def pre_buoy(key, *args)
      @previous = Buoys::Buoy.new(context, key, args)
    end
    alias_method :parent, :pre_buoy

    def method_missing(method, *args, &block)
      context.send(method, *args, &block)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
buoys-0.2.0 lib/buoys/buoy.rb
buoys-0.1.0 lib/buoys/buoy.rb