Sha256: 1294986ff7cd87fd2a6d8c6df36bd6e008e1b5799b24814f648bfa668e53bd45

Contents?: true

Size: 769 Bytes

Versions: 3

Compression:

Stored size: 769 Bytes

Contents

require 'allowance'

module Happy
  module Extras
    module Permissions
      module ContextExtensions
        extend ActiveSupport::Concern

        def permissions(&blk)
          (@permissions ||= Allowance::Permissions.new).tap do |p|
            if blk
              blk.arity == 0 ? p.instance_exec(&blk) : blk.call(p)
            end
          end
        end

        alias_method :can, :permissions
      end

      module ControllerExtensions
        extend ActiveSupport::Concern

        included do
          delegate :permissions, :can, :to => :context
        end
      end
    end
  end
end

Happy::Context.send(:include, Happy::Extras::Permissions::ContextExtensions)
Happy::Controller.send(:include, Happy::Extras::Permissions::ControllerExtensions)

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
happy-0.1.0.pre19 lib/happy/extras/permissions.rb
happy-0.1.0.pre16 lib/happy/extras/permissions.rb
happy-0.1.0.pre15 lib/happy/extras/permissions.rb