Class: OpenRosa::Middleware::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/open_rosa/middleware.rb

Overview

Configuration object for the middleware

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



312
313
314
315
316
317
318
319
320
321
# File 'lib/open_rosa/middleware.rb', line 312

def initialize
  @forms = []
  @mount_path = "/openrosa"
  @base_url = nil
  @submission_handler = nil
  @max_submission_size = 10_485_760 # 10MB default
  @authentication_handler = nil
  @skip_authentication_for = []
  @authentication_realm = "OpenRosa"
end

Instance Attribute Details

#authentication_handlerObject

Returns the value of attribute authentication_handler.



309
310
311
# File 'lib/open_rosa/middleware.rb', line 309

def authentication_handler
  @authentication_handler
end

#authentication_realmObject

Returns the value of attribute authentication_realm.



309
310
311
# File 'lib/open_rosa/middleware.rb', line 309

def authentication_realm
  @authentication_realm
end

#base_urlObject

Returns the value of attribute base_url.



309
310
311
# File 'lib/open_rosa/middleware.rb', line 309

def base_url
  @base_url
end

#formsObject

Returns the value of attribute forms.



309
310
311
# File 'lib/open_rosa/middleware.rb', line 309

def forms
  @forms
end

#max_submission_sizeObject

Returns the value of attribute max_submission_size.



309
310
311
# File 'lib/open_rosa/middleware.rb', line 309

def max_submission_size
  @max_submission_size
end

#mount_pathObject

Returns the value of attribute mount_path.



309
310
311
# File 'lib/open_rosa/middleware.rb', line 309

def mount_path
  @mount_path
end

#skip_authentication_forObject

Returns the value of attribute skip_authentication_for.



309
310
311
# File 'lib/open_rosa/middleware.rb', line 309

def skip_authentication_for
  @skip_authentication_for
end

#submission_handlerObject

Returns the value of attribute submission_handler.



309
310
311
# File 'lib/open_rosa/middleware.rb', line 309

def submission_handler
  @submission_handler
end

Instance Method Details

#authenticate {|env| ... } ⇒ Object

Set the authentication handler callback

Example:

config.authenticate do |env|
request = Rack::Request.new(env)
auth = Rack::Auth::Basic::Request.new(env)
if auth.provided? && auth.basic?
  username, password = auth.credentials
  User.authenticate(username, password) # Returns user object or nil
end
end

Yields:

  • (env)

    The Rack environment hash

Yield Parameters:

  • env (Hash)

    The Rack environment

Yield Returns:

  • (Object, true, false, nil)

    Return truthy to authenticate, falsy to deny



347
348
349
# File 'lib/open_rosa/middleware.rb', line 347

def authenticate(&block)
  @authentication_handler = block
end

#on_submission {|submission| ... } ⇒ Object

Set the submission handler callback

Yields:

  • (submission)

    The parsed submission

Yield Parameters:

  • submission (Submission)

    The submission object

Yield Returns:

  • (String, nil)

    Optional success message



328
329
330
# File 'lib/open_rosa/middleware.rb', line 328

def on_submission(&block)
  @submission_handler = block
end