Class: Monty::Delivery

Inherits:
Object
  • Object
show all
Defined in:
lib/monty/delivery.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ Delivery

Returns a new instance of Delivery.



14
15
16
17
18
19
20
# File 'lib/monty/delivery.rb', line 14

def initialize(env)
  @path = env['REQUEST_PATH'] || env['PATH_INFO']
  @method = (env['REQUEST_METHOD'] || 'GET').to_s.downcase.to_sym 
  @post_body = env['rack.input']
  session = env['rack.session'] || {}
  @access_rights = session[:access_rights] || Monty::Configuration.public_access
end

Instance Attribute Details

#access_rightsObject



12
13
14
# File 'lib/monty/delivery.rb', line 12

def access_rights
  @access_rights
end

#methodObject

env



10
11
12
# File 'lib/monty/delivery.rb', line 10

def method
  @method
end

#pathObject

env || env



8
9
10
# File 'lib/monty/delivery.rb', line 8

def path
  @path
end

Instance Method Details

#allowed?true|false

Returns if the given path and method are allowed.

Returns:

  • (true|false)

    if the given path and method are allowed



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/monty/delivery.rb', line 23

def allowed?
  return true if @path == '/'

  begin
    ::Authorization.configure
  rescue NameError
  end

  @access_rights_regex = Monty.regex(@access_rights)

  @access_rights_regex.match(@path) || method_match?
end