Class: Gnarly::UUID
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, opts = {}) ⇒ UUID
constructor
A new instance of UUID.
Methods included from Provides
Methods included from Status
#created, #default_content_type, #internal_server_error, #method_not_allowed, #not_acceptable, #not_found, #ok, #pop_default_content_type, #push_default_content_type, #unsupported_media_type
Methods included from Base
#body_charset, #logger, #request, #state
Constructor Details
#initialize(app, opts = {}) ⇒ UUID
Returns a new instance of UUID.
10 11 12 13 14 15 |
# File 'lib/gnarly/uuid.rb', line 10 def initialize(app, opts={}) @app = app @path = opts[:path] ||= "/uuid" @default_number = opts[:default_number] ||= 1 @generator = ::UUID.new end |
Instance Method Details
#call(env) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/gnarly/uuid.rb', line 17 def call(env) environment env if request.path == "/uuid" provides "text/plain", "application/json" do |mime| n = request.params["n"] num = n ? n.to_i : @default_number uuids = num.times.collect do @generator.generate end case mime when "text/plain" ok uuids.join("\n") when "application/json" ok uuids.to_json end end else @app.call env end end |