Sha256: 8dd572785dc7cd57eed049426b450e907785e47d4806356f17e0d1a16b019a0b

Contents?: true

Size: 1 KB

Versions: 27

Compression:

Stored size: 1 KB

Contents

module Apipie
  class RoutesFormatter
    API_METHODS = %w{GET POST PUT PATCH OPTIONS DELETE}

    # The entry method called by Apipie to extract the array
    # representing the api dsl from the routes definition.
    def format_routes(rails_routes, args)
      rails_routes.map { |rails_route| format_route(rails_route, args) }
    end

    def format_route(rails_route, args)
      { :path => format_path(rails_route),
        :verb => format_verb(rails_route),
        :desc => args[:desc],
        :options => args[:options] }
    end

    def format_path(rails_route)
      rails_route.path.spec.to_s.gsub('(.:format)', '')
    end

    def format_verb(rails_route)
      verb = API_METHODS.select{|defined_verb| defined_verb =~ /\A#{rails_route.verb}\z/}
      if verb.count != 1
        verb = API_METHODS.select{|defined_verb| defined_verb == rails_route.constraints[:method]}
        if verb.blank?
          raise "Unknow verb #{rails_route.path.spec.to_s}"
        end
      end
      verb.first
    end
  end
end

Version data entries

27 entries across 27 versions & 2 rubygems

Version Path
apipie-rails-0.5.16 lib/apipie/routes_formatter.rb
apipierails3-0.0.1 lib/apipie/routes_formatter.rb
apipie-rails-0.5.15 lib/apipie/routes_formatter.rb
apipie-rails-0.5.14 lib/apipie/routes_formatter.rb
apipie-rails-0.5.13 lib/apipie/routes_formatter.rb
apipie-rails-0.5.12 lib/apipie/routes_formatter.rb
apipie-rails-0.5.11 lib/apipie/routes_formatter.rb
apipie-rails-0.5.10 lib/apipie/routes_formatter.rb
apipie-rails-0.5.9 lib/apipie/routes_formatter.rb
apipie-rails-0.5.8 lib/apipie/routes_formatter.rb
apipie-rails-0.5.7 lib/apipie/routes_formatter.rb
apipie-rails-0.5.6 lib/apipie/routes_formatter.rb
apipie-rails-0.5.5 lib/apipie/routes_formatter.rb
apipie-rails-0.5.4 lib/apipie/routes_formatter.rb
apipie-rails-0.5.3 lib/apipie/routes_formatter.rb
apipie-rails-0.5.2 lib/apipie/routes_formatter.rb
apipie-rails-0.5.1 lib/apipie/routes_formatter.rb
apipie-rails-0.5.0 lib/apipie/routes_formatter.rb
apipie-rails-0.4.0 lib/apipie/routes_formatter.rb
apipie-rails-0.3.7 lib/apipie/routes_formatter.rb