Module: Eazypi::ApiController::ClassMethods
- Defined in:
- lib/eazypi/api_controller.rb
Overview
Class methods to be used in your own API controller
Instance Method Summary collapse
-
#determine_method_name(http_method, _path_string) ⇒ Object
rubocop:todo Metrics/MethodLength.
- #operation(method, path_string, &block) ⇒ Object
- #operations ⇒ Object
Instance Method Details
#determine_method_name(http_method, _path_string) ⇒ Object
rubocop:todo Metrics/MethodLength
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/eazypi/api_controller.rb', line 33 def determine_method_name(http_method, _path_string) # rubocop:todo Metrics/MethodLength controller_base_name = case http_method when :get :show when :post :create when :patch, :put :update when :delete :destroy else raise "Could not generate method name" end controller_method_name = controller_base_name counter = 1 while method_defined?(controller_method_name) controller_method_name = "#{controller_base_name}#{counter}" counter += 1 end controller_method_name end |
#operation(method, path_string, &block) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/eazypi/api_controller.rb', line 14 def operation(method, path_string, &block) method_name = determine_method_name(method, path_string) op = Operation.new(self, method_name, path_string, method) op.load(&block) define_method(method_name) do op.call(self) end @operations << op op end |
#operations ⇒ Object
29 30 31 |
# File 'lib/eazypi/api_controller.rb', line 29 def operations @operations end |