model_driven_api 3.1.13 → 3.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b823fbfec58e3d2ed3fcfab93a4d1efbf71216d7f812f219a11f2f71842df4f5
4
- data.tar.gz: f991ce102699d8b91e85ea996520bed2b1693a13b533a0971fed3f899b53fa44
3
+ metadata.gz: 484b0a3f30e3d9f1bf3b5345a46698ae66a35aeff259a50d6260adfadbd355c3
4
+ data.tar.gz: fbde7e739014cfeb049f55421aaac00c2b14461de0911aae40b623a089b177d2
5
5
  SHA512:
6
- metadata.gz: 2fc75f3100b4021899d76b77c52210418ae0f832f97732d0edb8c53a037130394f025469f99d1bfba5943a3073c2d14b26858725d3828bcd44855e84804ad330
7
- data.tar.gz: bf00ba029b9f15f73465ee1ab9aa59cffc6296f8b45392defd4d7b330498c2c4cae0c89007bbffc0114a95dc0a97cefc7643f56c42494f2c37fdd8c72f33ffbf
6
+ metadata.gz: a0f5da89ce627a15211a2b5e69fc415453bec5781d81089369d8198b83d8a56e8ddbeabe5f44a4a38b7caba3daf82a90175f036f3c4af2cfee38af218e887486
7
+ data.tar.gz: 1bacbc9b718fa72eaae21cdb139859d098873a41e8256020bcc32619e5299b7cdb17f297bd94ac73f130a899e1a663cad381efec89406e69122fa69d44205d28
@@ -9,7 +9,7 @@ class Api::V2::ApplicationController < ActionController::API
9
9
 
10
10
  before_action :authenticate_request
11
11
  before_action :extract_model
12
- before_action :find_record, only: [:show, :destroy, :update]
12
+ before_action :find_record, only: [:show, :destroy, :update, :patch]
13
13
 
14
14
  # GET :controller/
15
15
  def index
@@ -91,6 +91,9 @@ class Api::V2::ApplicationController < ActionController::API
91
91
  render json: @record.to_json(json_attrs), status: 200
92
92
  end
93
93
 
94
+ # Define the path method as an alias to the update one, they are basically the same method
95
+ alias_method :patch, :update
96
+
94
97
  def update_multi
95
98
  authorize! :update, @model
96
99
  ids = params[:ids].split(",")
@@ -516,9 +516,9 @@ class Api::V2::InfoController < Api::V2::ApplicationController
516
516
  }
517
517
  # Non CRUD or Search, but custom, usually bulk operations endpoints
518
518
  new_custom_actions = ("Endpoints::#{d.model_name.name}".constantize.instance_methods(false) rescue [])
519
- # Rails.logger.debug "New Custom Actions (#{d.model_name.name}): #{new_custom_actions}"
519
+ Rails.logger.debug "New Custom Actions (#{d.model_name.name}): #{new_custom_actions}"
520
520
  new_custom_actions.each do |action|
521
- openapi_definition = "Endpoints::#{d.model_name.name}".constantize.definitions[action.to_sym] rescue false
521
+ openapi_definition = "Endpoints::#{d.model_name.name}".constantize.definitions[d.model_name.name][action.to_sym] rescue []
522
522
 
523
523
  # Add the tag to the openapi definition
524
524
  openapi_definition.each do |k, v|
@@ -1,5 +1,5 @@
1
1
  class Endpoints::TestApi < NonCrudEndpoints
2
- self.desc :test, {
2
+ self.desc 'TestApi', :test, {
3
3
  # Define the action name using openapi swagger format
4
4
  get: {
5
5
  summary: "Test API Custom Action",
data/config/routes.rb CHANGED
@@ -44,7 +44,7 @@ Rails.application.routes.draw do
44
44
 
45
45
  # # CRUD Delete
46
46
  delete '*path/:id/multi', to: 'application#destroy_multi'
47
- # delete '*path/:id', to: 'application#destroy'
47
+ delete '*path/:id', to: 'application#destroy'
48
48
  end
49
49
  end
50
50
  end
@@ -1,3 +1,3 @@
1
1
  module ModelDrivenApi
2
- VERSION = "3.1.13".freeze
2
+ VERSION = "3.2.1".freeze
3
3
  end
@@ -4,9 +4,16 @@ class NonCrudEndpoints
4
4
  self.definitions = {}
5
5
  # Add a validation method which will be inherited by all the instances, and automatically run before any method call
6
6
  def initialize(m, params)
7
- # Check if self hase the m method, if not, raise a NoMethodError
7
+ # Rails.logger.debug "Initializing NonCrudEndpoints"
8
+ # Showing the class name of the instance, and also, if there's a class inheriting from this one, the name of the child class
9
+ # Rails.logger.debug "Class: #{self.class.name} - Child Class: #{self.class.superclass.name if self.class.superclass != Object}"
10
+ # Check if self has the m method, if not, raise a NoMethodError
8
11
  raise NoMethodError, "The method #{m} does not exist in #{self.class.name}" unless self.respond_to? m
9
- @definition = self.definitions[m.to_sym].with_indifferent_access
12
+ # To avoid having conflicting keys from different classes, we will use a two levels object to store the definitions
13
+ # the first level is the class name, and the second level is the method name
14
+ self.definitions[self.class.name] ||= {}
15
+ self.definitions[self.class.name][m.to_sym] ||= {}
16
+ @definition = self.definitions[self.class.name][m.to_sym].with_indifferent_access
10
17
 
11
18
  # self.send(m, { explain: true }) rescue []
12
19
  validate_request(params)
@@ -25,8 +32,9 @@ class NonCrudEndpoints
25
32
 
26
33
  private
27
34
 
28
- def self.desc(key, definition)
29
- self.definitions[key] = definition
35
+ def self.desc(endpoint, key, definition)
36
+ self.definitions[endpoint] ||= {}
37
+ self.definitions[endpoint][key] = definition
30
38
  end
31
39
 
32
40
  def get_type(type)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: model_driven_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.13
4
+ version: 3.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriele Tassoni
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-10 00:00:00.000000000 Z
11
+ date: 2024-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thecore_backend_commons
@@ -167,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
167
  - !ruby/object:Gem::Version
168
168
  version: '0'
169
169
  requirements: []
170
- rubygems_version: 3.5.3
170
+ rubygems_version: 3.5.9
171
171
  signing_key:
172
172
  specification_version: 4
173
173
  summary: Convention based RoR engine which uses DB schema introspection to create