Class: Social::Determinant::RequestParam::Provider

Inherits:
Object
  • Object
show all
Defined in:
lib/social/determinant/request_param.rb

Class Method Summary collapse

Class Method Details

.build(social_type) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/social/determinant/request_param.rb', line 8

def self.build(social_type)
  klass = Class.new do

    class << self
      attr_accessor :social_type
    end

    def initialize(app)
      @app = app
    end

    def call(env)
      request      = Rack::Request.new(env)
      social_type  = self.class.social_type
      prefix       = Social.prefix_by_type(social_type)
      id           = Social.id_by_type(social_type)
      
      request.GET['social_env'] = {
        'prefix' => prefix, 'type' => social_type, 'id' => id
      }

      @app.call(request.env)
    end

  end

  klass.social_type = social_type
  klass
end