aboutsummaryrefslogtreecommitdiffstats
path: root/lib/apidoc/controller_dsl.rb
blob: 38b17270f6b82c77990149fca8d14a5a3d73b05e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
module Apidoc
  module ControllerDsl
    include Resources
    include Endpoints
    include Parameters

    private
    def method_added(method_name)
      super(method_name)

      if _apidoc_endpoint_started?
        _apidoc_resource.endpoints[method_name] = _apidoc_current_endpoint
        self._apidoc_current_endpoint = nil
      end
    end

    def _apidoc_resource
      name = self.name.sub(/Controller$/, "").underscore
      Apidoc.resources[name.to_sym] ||= Resource.new(name.titleize)
    end

    def _apidoc_current_endpoint
      @_apidoc_current_endpoint || raise(DslError, "Endpoint definition is not started.")
    end

    def _apidoc_current_endpoint=(value)
      @_apidoc_current_endpoint = value
    end

    def _apidoc_endpoint_started?
      @_apidoc_current_endpoint.present?
    end

    def _apidoc_param_groups
      @_apidoc_param_groups ||= {}
    end
  end
end