Class: Webspicy::Mocker
- Inherits:
-
Object
- Object
- Webspicy::Mocker
- Defined in:
- lib/webspicy/mocker.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#generator ⇒ Object
readonly
Returns the value of attribute generator.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(config) ⇒ Mocker
constructor
A new instance of Mocker.
Constructor Details
#initialize(config) ⇒ Mocker
Returns a new instance of Mocker.
6 7 8 9 |
# File 'lib/webspicy/mocker.rb', line 6 def initialize(config) @config = Configuration.dress(config) @generator = config.generator || Finitio::Generation.new end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
10 11 12 |
# File 'lib/webspicy/mocker.rb', line 10 def config @config end |
#generator ⇒ Object (readonly)
Returns the value of attribute generator.
10 11 12 |
# File 'lib/webspicy/mocker.rb', line 10 def generator @generator end |
Instance Method Details
#call(env) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/webspicy/mocker.rb', line 12 def call(env) req = Rack::Request.new(env) path = req.path meth = req.request_method if meth == "OPTIONS" && has_service?(path) [204, {}, []] elsif service = find_service(meth, path) status = best_status_code(service) body = status == 204 ? "" : random_body(service, req) headers = generate_headers(service) [ status, headers, [ body ].compact ] else [404, {}, []] end end |