Sha256: 2dd333a4cf22e6fc8d4e158ba59fbf88b75849a09ab4f3b2554a58fd20d5ab33

Contents?: true

Size: 727 Bytes

Versions: 1

Compression:

Stored size: 727 Bytes

Contents

module Timber
  module Contexts
    module Users
      class ActionController < User
        DEFAULT_METHOD_NAME = :current_user.freeze

        class << self
          attr_writer :method_name

          def method_name
            @method_name ||= DEFAULT_METHOD_NAME
          end
        end

        attr_reader :controller

        def initialize(controller)
          @controller = controller
          super()
        end

        private
          def method_name
            self.class.method_name
          end

          def user
            return @user if defined?(@user)
            @user = controller.respond_to?(method_name, true) ? controller.send(method_name) : nil
          end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
timberio-1.0.0.beta1 lib/timber/contexts/users/action_controller.rb