Class: Divergence::RequestParser

Inherits:
Object
  • Object
show all
Defined in:
lib/divergence/request_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ RequestParser

Returns a new instance of RequestParser.



3
4
5
# File 'lib/divergence/request_parser.rb', line 3

def initialize(env)
  @req = Rack::Request.new(env)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object



47
48
49
# File 'lib/divergence/request_parser.rb', line 47

def method_missing(meth, *args, &block)
  raw.send(meth, *args)
end

Instance Method Details

#branchObject



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/divergence/request_parser.rb', line 33

def branch
  if has_subdomain?
    branch = subdomain

    if branch['-']
      @git.discover(branch)
    else
      branch
    end
  else
    nil
  end
end

#has_subdomain?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/divergence/request_parser.rb', line 21

def has_subdomain?
  host_parts.length > 2
end

#host_partsObject



17
18
19
# File 'lib/divergence/request_parser.rb', line 17

def host_parts
  @req.host.split(".")
end

#is_webhook?Boolean

Returns:

  • (Boolean)


11
12
13
14
15
# File 'lib/divergence/request_parser.rb', line 11

def is_webhook?
  subdomain == "divergence" and 
  @req.env['PATH_INFO'] == "/update" and
  @req.post?
end

#rawObject



7
8
9
# File 'lib/divergence/request_parser.rb', line 7

def raw
  @req
end

#subdomainObject



25
26
27
28
29
30
31
# File 'lib/divergence/request_parser.rb', line 25

def subdomain
  if has_subdomain?
    host_parts.shift
  else
    nil
  end
end