Sha256: 24aadab9c96da51c135cb858a0398d020aab3f56d3285578f1b3fc3a9e1693e0

Contents?: true

Size: 701 Bytes

Versions: 3

Compression:

Stored size: 701 Bytes

Contents

module Crumpet
  module ControllerAdditions
    def self.included(base)
      base.extend ClassMethods
    end

    def add_crumb(*args)
      Crumpet.crumbs.add_crumb(*args)
    end

    def clear_crumbs
      Crumpet.crumbs.clear
    end

    def crumbs(&block)
      yield if block_given?
      Crumpet.crumbs
    end

    module ClassMethods
      def crumbs(&block)
        crumbs_for(&block)
      end

      def crumbs_for(*args, &block)
        if block_given?
          options = args.present? ? { only: args } : {}
          before_action(options) do |instance|
            instance.instance_exec(:crumbs, &block)
          end
        end
        Crumpet.crumbs
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
crumpet-0.2.1 lib/crumpet/controller_additions.rb
crumpet-0.2.0 lib/crumpet/controller_additions.rb
crumpet-0.1.2 lib/crumpet/controller_additions.rb