Sha256: ea204714adca3e992912232ee65111b696d10dcf4d372ce858098a096592bd94

Contents?: true

Size: 879 Bytes

Versions: 13

Compression:

Stored size: 879 Bytes

Contents

module Arrthorizer
  module Rails
    class ControllerContextBuilder < Arrthorizer::ContextBuilder
      attr_accessor :controller, :configuration

      def initialize(controller, configuration)
        self.controller = controller
        self.configuration = configuration
      end

      def build_default
        config = config_for_action(nil)

        build_from_block(&config)
      end

      def build_for_action
        config = config_for_action(controller.action_name)

        build_from_block(&config)
      end

    protected
      def build_from_block(&config)
        if block_given?
          context_hash = controller.instance_eval(&config)

          build_from_hash(context_hash)
        else
          build_from_hash({})
        end
      end

      def config_for_action(action)
        configuration.try(:block_for, action)
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
arrthorizer-0.4.2 lib/arrthorizer/rails/controller_context_builder.rb
arrthorizer-0.4.1 lib/arrthorizer/rails/controller_context_builder.rb
arrthorizer-0.3.2 lib/arrthorizer/rails/controller_context_builder.rb
arrthorizer-0.3.1 lib/arrthorizer/rails/controller_context_builder.rb
arrthorizer-0.3.0 lib/arrthorizer/rails/controller_context_builder.rb
arrthorizer-0.2.1 lib/arrthorizer/rails/controller_context_builder.rb
arrthorizer-0.2.0 lib/arrthorizer/rails/controller_context_builder.rb
arrthorizer-0.1.3 lib/arrthorizer/rails/controller_context_builder.rb
arrthorizer-0.1.2 lib/arrthorizer/rails/controller_context_builder.rb
arrthorizer-0.1.1 lib/arrthorizer/rails/controller_context_builder.rb
arrthorizer-0.1.0 lib/arrthorizer/rails/controller_context_builder.rb
arrthorizer-0.1.0.pre2 lib/arrthorizer/rails/controller_context_builder.rb
arrthorizer-0.1.0.pre lib/arrthorizer/rails/controller_context_builder.rb