Module: RorHack::ControllerRequestUglyInject

Included in:
ActiveRecord::Base
Defined in:
lib/ror_hack/active_record_hack.rb

Class Method Summary collapse

Class Method Details

.included(mod) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/ror_hack/active_record_hack.rb', line 100

def self.included(mod)
  ActionController::Base.class_eval do
    before_filter do
      params                                 = {
        user:       (current_user rescue nil),
        request_ip: request.env['HTTP_X_REAL_IP'] || request.remote_ip,
        session:    session
      }
      RequestStore.store[:controller_params] = OpenStruct.new(params).freeze
    end
  end
  mod.class_eval do
    delegate :dingo_info, to: :class

    def self.dingo_info
      if RequestStore.store.key?(:controller_params)
        RequestStore.store.fetch(:controller_params)
      else
        OpenStruct.new.freeze
      end
    end
  end
end