module Flon::DSL

This module holds Flon's DSL. You should extend it in your class.

@example

class BreadAPI
  extend Flon::DSL

  get '/bread'
  def bread
    'bread.'
  end
end

Public Instance Methods

method_added(name) click to toggle source

@api private

# File lib/flon/dsl.rb, line 81
def method_added(name)
  return unless @current_route

  http_method, path = @current_route
  router.add_route(http_method, path, instance_method(name))

  @current_route = nil
end
namespace(path) { || ... } click to toggle source

Creates a namespace of the given path. If a block is given, the namespace is local to the block. If not, it is applied to the rest of the API. You may not call this method without a block twice.

@param [String] path the path to use @return [void]

# File lib/flon/dsl.rb, line 52
def namespace(path)
  if block_given?
    namespaces.push(path)
    yield
    namespaces.pop
  else
    unless namespaces.empty?
      raise Flon::Error, 'cannot declare a nested global namespace or declare a global namespace twice'
    end

    namespaces.push(path)
  end
end
Also aliased as: version
namespaces() click to toggle source

@api private

# File lib/flon/dsl.rb, line 76
def namespaces
  @namespaces ||= []
end
router() click to toggle source

@api private

# File lib/flon/dsl.rb, line 71
def router
  @router ||= Flon::Router.new
end
version(path)
Alias for: namespace