class SwaggerApi::Paths
Attributes
controllers[RW]
Public Instance Methods
create()
click to toggle source
# File lib/swagger_api/paths.rb, line 8 def create return @paths unless @paths.nil? @paths = {} controllers.each do |controller| if controller.custom_path_file.nil? @paths.merge!(paths(controller)) else @paths.merge!(custom_json(controller)) end end @paths end
Private Instance Methods
action?(controller, action_name)
click to toggle source
# File lib/swagger_api/paths.rb, line 74 def action?(controller, action_name) actions(controller).include?(action_name) end
actions(controller)
click to toggle source
# File lib/swagger_api/paths.rb, line 70 def actions(controller) SwaggerApi::Actions.new(controller: controller).all! end
clean_out_delete_path(paths, controller)
click to toggle source
# File lib/swagger_api/paths.rb, line 56 def clean_out_delete_path(paths, controller) paths.delete route(controller) if paths[route(controller)].blank? paths.delete "#{route(controller)}{id}/" if paths["#{route(controller)}{id}/"].blank? end
collection_paths(paths, controller)
click to toggle source
# File lib/swagger_api/paths.rb, line 32 def collection_paths(paths, controller) paths[route(controller)][:get] = SwaggerApi::Operations::Index.new(controller: controller).create if action?(controller, 'index') paths[route(controller)][:post] = SwaggerApi::Operations::Create.new(controller: controller).create if action?(controller, 'create') end
custom_json(controller)
click to toggle source
# File lib/swagger_api/paths.rb, line 65 def custom_json(controller) file = File.read(controller.custom_path_file) JSON.parse(file) end
delete_path(paths, controller)
click to toggle source
# File lib/swagger_api/paths.rb, line 52 def delete_path(paths, controller) paths["#{route(controller)}{id}/"][:delete] = SwaggerApi::Operations::Delete.new(controller: controller).create if action?(controller, 'delete') end
member_paths(paths, controller)
click to toggle source
# File lib/swagger_api/paths.rb, line 37 def member_paths(paths, controller) show_path(paths, controller) update_path(paths, controller) delete_path(paths, controller) clean_out_delete_path(paths, controller) end
paths(controller)
click to toggle source
# File lib/swagger_api/paths.rb, line 23 def paths(controller) paths = {} paths[route(controller)] = {} paths["#{route(controller)}{id}/"] = {} collection_paths(paths, controller) member_paths(paths, controller) paths end
route(controller)
click to toggle source
# File lib/swagger_api/paths.rb, line 61 def route(controller) "/#{controller.name.demodulize.underscore.gsub('_controller', '')}/" end
show_path(paths, controller)
click to toggle source
# File lib/swagger_api/paths.rb, line 44 def show_path(paths, controller) paths["#{route(controller)}{id}/"][:get] = SwaggerApi::Operations::Show.new(controller: controller).create if action?(controller, 'show') end
update_path(paths, controller)
click to toggle source
# File lib/swagger_api/paths.rb, line 48 def update_path(paths, controller) paths["#{route(controller)}{id}/"][:put] = SwaggerApi::Operations::Update.new(controller: controller).create if action?(controller, 'update') end