Sha256: 61c043d3129ebba53a30941bb522139401ac18900157835abb5fdd99f7921f58

Contents?: true

Size: 1.72 KB

Versions: 11

Compression:

Stored size: 1.72 KB

Contents

module RESTinPeace
  class DefinitionProxy
    class ResourceMethodDefinitions
      def initialize(target)
        @target = target
      end

      def get(method_name, url_template, default_params = {})
        @target.rip_registry[:resource] << { method: :get, name: method_name, url: url_template }
        @target.send(:define_method, method_name) do
          call = RESTinPeace::ApiCall.new(api, url_template, self, payload)
          call.get
        end
      end

      def patch(method_name, url_template)
        @target.rip_registry[:resource] << { method: :patch, name: method_name, url: url_template }
        @target.send(:define_method, method_name) do
          call = RESTinPeace::ApiCall.new(api, url_template, self, payload)
          call.patch
        end
      end

      def post(method_name, url_template)
        @target.rip_registry[:resource] << { method: :post, name: method_name, url: url_template }
        @target.send(:define_method, method_name) do
          call = RESTinPeace::ApiCall.new(api, url_template, self, payload(false))
          call.post
        end
      end

      def put(method_name, url_template)
        @target.rip_registry[:resource] << { method: :put, name: method_name, url: url_template }
        @target.send(:define_method, method_name) do
          call = RESTinPeace::ApiCall.new(api, url_template, self, payload(false))
          call.put
        end
      end

      def delete(method_name, url_template)
        @target.rip_registry[:resource] << { method: :delete, name: method_name, url: url_template }
        @target.send(:define_method, method_name) do
          call = RESTinPeace::ApiCall.new(api, url_template, self, id: id)
          call.delete
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
rest-in-peace-6.2.0 lib/rest_in_peace/definition_proxy/resource_method_definitions.rb
rest-in-peace-6.1.1 lib/rest_in_peace/definition_proxy/resource_method_definitions.rb
rest-in-peace-6.1.0 lib/rest_in_peace/definition_proxy/resource_method_definitions.rb
rest-in-peace-6.0.4 lib/rest_in_peace/definition_proxy/resource_method_definitions.rb
rest-in-peace-6.0.3 lib/rest_in_peace/definition_proxy/resource_method_definitions.rb
rest-in-peace-6.0.2 lib/rest_in_peace/definition_proxy/resource_method_definitions.rb
rest-in-peace-6.0.0 lib/rest_in_peace/definition_proxy/resource_method_definitions.rb
rest-in-peace-5.1.0 lib/rest_in_peace/definition_proxy/resource_method_definitions.rb
rest-in-peace-5.0.2 lib/rest_in_peace/definition_proxy/resource_method_definitions.rb
rest-in-peace-5.0.1 lib/rest_in_peace/definition_proxy/resource_method_definitions.rb
rest-in-peace-5.0.0 lib/rest_in_peace/definition_proxy/resource_method_definitions.rb