Module: TinyGID::MethodMissing
Overview
:nodoc:
Instance Method Summary collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *arguments, &block) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/tiny_gid.rb', line 11 def method_missing(name, *arguments, &block) # TODO: need to ensure we're not calling ourselves id = arguments.shift raise ArgumentError, "gid::#{name} requires an ID" unless id params = (arguments[0] || {}).dup raise TypeError, "gid::#{name} params must be a Hash. Received: #{params.class}" unless params.is_a?(Hash) app = params.delete(:__app__) || TinyGID.app raise "gid::#{name} cannot be generated: missing app name" unless app gid = sprintf(FORMAT, app, name, URI.encode_www_form_component(id)) return gid unless params.any? gid << "?" << URI.encode_www_form(params) end |