Module: ApiFrame::Utils
- Defined in:
- lib/api_frame/utils.rb
Class Method Summary collapse
- .call_proc_without_unknown_keywords(proc, *args, **kwargs, &block) ⇒ Object
- .request_type_from_method_argument(method) ⇒ Object
- .url_escape(string) ⇒ Object
Class Method Details
.call_proc_without_unknown_keywords(proc, *args, **kwargs, &block) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/api_frame/utils.rb', line 11 def self.call_proc_without_unknown_keywords(proc, *args, **kwargs, &block) params = proc.parameters.group_by(&:first).transform_values! do |m| m.map do |s| s[1] end end proc_keys = if params.key?(:keyrest) kwargs else kwargs.slice(*params.values_at(:key, :keyreq).compact.flatten) end proc.call(*args, **proc_keys, &block) end |
.request_type_from_method_argument(method) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/api_frame/utils.rb', line 28 def self.request_type_from_method_argument(method) if method.instance_of?(Class) && method.ancestors.include?(Net::HTTPRequest) method else { get: Net::HTTP::Get, post: Net::HTTP::Post, put: Net::HTTP::Put, patch: Net::HTTP::Patch, delete: Net::HTTP::Delete, head: Net::HTTP::Head, options: Net::HTTP::Options, }.fetch(method) end end |
.url_escape(string) ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/api_frame/utils.rb', line 3 def self.url_escape(string) if !string.nil? CGI.escape(string.to_s) else raise TypeError, 'cannot escape nil' end end |