Module: JsonapiSwaggerHelpers::ResourceMixin
- Defined in:
- lib/jsonapi_swagger_helpers/resource_mixin.rb
Instance Method Summary collapse
- #jsonapi_resource(base_path, tags: [], descriptions: {}, only: [], except: [], singular: false) ⇒ Object
- #load_resource(config) ⇒ Object
Instance Method Details
#jsonapi_resource(base_path, tags: [], descriptions: {}, only: [], except: [], singular: false) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/jsonapi_swagger_helpers/resource_mixin.rb', line 4 def jsonapi_resource(base_path, tags: [], descriptions: {}, only: [], except: [], singular: false) self.resources << { base_path: base_path, tags: , descriptions: descriptions, only: only, except: except, singular: singular } end |
#load_resource(config) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/jsonapi_swagger_helpers/resource_mixin.rb', line 20 def load_resource(config) base_path = config[:base_path] = config[:tags] descriptions = config[:descriptions] only = config[:only] except = config[:except] singular = config[:singular] actions = %i[index show create update destroy] actions.select! { |a| only.include?(a) } unless only.empty? actions.reject! { |a| except.include?(a) } unless except.empty? prefix = @swagger_root_node.data[:basePath] full_path = [prefix, base_path].join('/').gsub('//', '/') controller = JsonapiSwaggerHelpers::Util.controller_for(full_path) actions.each do |action| next unless controller.action_methods.include?(action.to_s) path = if !singular && %i[show update destroy].include?(action) "#{base_path}/{id}" else base_path end swagger_path path do action_class_name = "#{action.to_s.camelize}Action" action_class = JsonapiSwaggerHelpers.const_get(action_class_name) action_object = action_class.new \ self, controller, tags: , description: descriptions[action], singular: singular action_object.generate end end end |