Sha256: 856fff7976ea549d1b5a3d26fea52ce1188363ada09a91642959a8a7f375cfb5
Contents?: true
Size: 1.03 KB
Versions: 1
Compression:
Stored size: 1.03 KB
Contents
require 'rest_in_peace/template_sanitizer' require 'rest_in_peace/api_call' module RESTinPeace class DefinitionProxy class CollectionMethodDefinitions def initialize(target) @target = target end def get(method_name, url_template, default_params = {}) @target.rip_registry[:collection] << { method: :get, name: method_name, url: url_template } @target.send(:define_singleton_method, method_name) do |*args| if args.last.is_a?(Hash) params = default_params.merge(args.pop) else params = default_params.dup end if args.any? tokens = RESTinPeace::TemplateSanitizer.new(url_template, {}).tokens tokens.each do |token| params.merge!(token.to_sym => args.shift) end end call = RESTinPeace::ApiCall.new(api, url_template, self, params) call.extend(params.delete(:paginate_with)) if params[:paginate_with] call.get end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rest-in-peace-1.1.1 | lib/rest_in_peace/definition_proxy/collection_method_definitions.rb |