Sha256: 9352fb412c3105230fed1dabffcb99af479462406d37502e3641caf6aa5d5515

Contents?: true

Size: 1.37 KB

Versions: 7

Compression:

Stored size: 1.37 KB

Contents

module ApiTaster
  class Mapper
    cattr_accessor :last_desc

    class << self
      def get(path, params = {}, metadata = {})
        map_method(:get, path, params, metadata)
      end

      def post(path, params = {}, metadata = {})
        map_method(:post, path, params, metadata)
      end

      def put(path, params = {}, metadata = {})
        map_method(:put, path, params, metadata)
      end

      def patch(path, params = {}, metadata = {})
        map_method(:patch, path, params, metadata)
      end

      def delete(path, params = {}, metadata = {})
        map_method(:delete, path, params, metadata)
      end

      def desc(text)
        self.last_desc = text
      end

      private

      def map_method(method, path, params, metadata)
        route = Route.find_by_verb_and_path(method, path)

        if route.nil?
          Route.obsolete_definitions << {
            :verb   => method,
            :path   => path,
            :params => params
          }
        else
          Route.supplied_params[route[:id]] ||= []
          Route.supplied_params[route[:id]] << ApiTaster.global_params.merge(params)

          unless last_desc.nil?
            Route.comments[route[:id]] = last_desc
            self.last_desc = nil
          end

          if metadata.any?
            Route.metadata[route[:id]] = metadata
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
api_taster-0.8.4 lib/api_taster/mapper.rb
api_taster-0.8.3 lib/api_taster/mapper.rb
api_taster-0.8.2 lib/api_taster/mapper.rb
api_taster-0.8.1 lib/api_taster/mapper.rb
api_taster-0.7.0 lib/api_taster/mapper.rb
api_taster-0.6.0 lib/api_taster/mapper.rb
api_taster-0.5.1 lib/api_taster/mapper.rb