rest_framework 0.8.16 → 0.8.17

Sign up to get free protection for your applications and to get access to all the features.
data/docs/index.md ADDED
@@ -0,0 +1,133 @@
1
+ ---
2
+ ---
3
+
4
+ # Rails REST Framework
5
+
6
+ [![Gem Version](https://badge.fury.io/rb/rest_framework.svg)](https://badge.fury.io/rb/rest_framework)
7
+ [![Pipeline](https://github.com/gregschmit/rails-rest-framework/actions/workflows/pipeline.yml/badge.svg)](https://github.com/gregschmit/rails-rest-framework/actions/workflows/pipeline.yml)
8
+ [![Coverage](https://coveralls.io/repos/github/gregschmit/rails-rest-framework/badge.svg?branch=master)](https://coveralls.io/github/gregschmit/rails-rest-framework?branch=master)
9
+ [![Maintainability](https://api.codeclimate.com/v1/badges/ba5df7706cb544d78555/maintainability)](https://codeclimate.com/github/gregschmit/rails-rest-framework/maintainability)
10
+
11
+ A framework for DRY RESTful APIs in Ruby on Rails.
12
+
13
+ **The Problem**: Building controllers for APIs usually involves writing a lot of redundant CRUD
14
+ logic, and routing them can be obnoxious. Building and maintaining features like ordering,
15
+ filtering, and pagination can be tedious.
16
+
17
+ **The Solution**: This framework implements browsable API responses, CRUD actions for your models,
18
+ and features like ordering/filtering/pagination, so you can focus on building awesome APIs.
19
+
20
+ Website/Guide: [rails-rest-framework.com](https://rails-rest-framework.com)
21
+
22
+ Demo: [demo.rails-rest-framework.com](https://demo.rails-rest-framework.com)
23
+
24
+ Source: [github.com/gregschmit/rails-rest-framework](https://github.com/gregschmit/rails-rest-framework)
25
+
26
+ YARD Docs: [rubydoc.info/gems/rest_framework](https://rubydoc.info/gems/rest_framework)
27
+
28
+ ## Installation
29
+
30
+ Add this line to your application's Gemfile:
31
+
32
+ ```ruby
33
+ gem 'rest_framework'
34
+ ```
35
+
36
+ And then execute:
37
+
38
+ ```shell
39
+ $ bundle install
40
+ ```
41
+
42
+ Or install it yourself with:
43
+
44
+ ```shell
45
+ $ gem install rest_framework
46
+ ```
47
+
48
+ ## Quick Usage Tutorial
49
+
50
+ ### Controller Mixins
51
+
52
+ To transform a controller into a RESTful controller, you can either include `BaseControllerMixin`,
53
+ `ReadOnlyModelControllerMixin`, or `ModelControllerMixin`. `BaseControllerMixin` provides a `root`
54
+ action and a simple interface for routing arbitrary additional actions:
55
+
56
+ ```ruby
57
+ class ApiController < ApplicationController
58
+ include RESTFramework::BaseControllerMixin
59
+ self.extra_actions = {test: [:get]}
60
+
61
+ def test
62
+ render api_response({message: "Test successful!"})
63
+ end
64
+ end
65
+ ```
66
+
67
+ `ModelControllerMixin` assists with providing the standard model CRUD for your controller.
68
+
69
+ ```ruby
70
+ class Api::MoviesController < ApiController
71
+ include RESTFramework::ModelControllerMixin
72
+
73
+ self.recordset = Movie.where(enabled: true)
74
+ end
75
+ ```
76
+
77
+ `ReadOnlyModelControllerMixin` only enables list/show actions, but since we're naming this
78
+ controller in a way that doesn't make the model obvious, we can set that explicitly:
79
+
80
+ ```ruby
81
+ class Api::ReadOnlyMoviesController < ApiController
82
+ include RESTFramework::ReadOnlyModelControllerMixin
83
+
84
+ self.model = Movie
85
+ end
86
+ ```
87
+
88
+ Note that you can also override the `get_recordset` instance method to override the API behavior
89
+ dynamically per-request.
90
+
91
+ ### Routing
92
+
93
+ You can use Rails' `resource`/`resources` routers to route your API, however if you want
94
+ `extra_actions` / `extra_member_actions` to be routed automatically, then you can use `rest_route`
95
+ for non-resourceful controllers, or `rest_resource` / `rest_resources` resourceful routers. You can
96
+ also use `rest_root` to route the root of your API:
97
+
98
+ ```ruby
99
+ Rails.application.routes.draw do
100
+ rest_root :api # will find `api_controller` and route the `root` action to '/api'
101
+ namespace :api do
102
+ rest_resources :movies
103
+ rest_resources :users
104
+ end
105
+ end
106
+ ```
107
+
108
+ Or if you want the API root to be routed to `Api::RootController#root`:
109
+
110
+ ```ruby
111
+ Rails.application.routes.draw do
112
+ namespace :api do
113
+ rest_root # will route `Api::RootController#root` to '/' in this namespace ('/api')
114
+ rest_resources :movies
115
+ rest_resources :users
116
+ end
117
+ end
118
+ ```
119
+
120
+ ## Development/Testing
121
+
122
+ After you clone the repository, cd'ing into the directory should create a new gemset if you are
123
+ using RVM. Then run `bundle install` to install the appropriate gems.
124
+
125
+ To run the test suite:
126
+
127
+ ```shell
128
+ $ rails test
129
+ ```
130
+
131
+ The top-level `bin/rails` proxies all Rails commands to the test project, so you can operate it via
132
+ the usual commands. Ensure you run `rails db:setup` before running `rails server` or
133
+ `rails console`.
@@ -281,7 +281,7 @@ class RESTFramework::NativeSerializer < RESTFramework::BaseSerializer
281
281
  end
282
282
  else
283
283
  self.define_singleton_method(f) do |record|
284
- next record.send(f).map { |x| x.attachment&.url }
284
+ next record.send(f).map(&:url)
285
285
  end
286
286
  end
287
287
  elsif @model.method_defined?(f)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rest_framework
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.16
4
+ version: 0.8.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregory N. Schmit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-03 00:00:00.000000000 Z
11
+ date: 2023-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -40,6 +40,23 @@ files:
40
40
  - app/views/rest_framework/_raw_form.html.erb
41
41
  - app/views/rest_framework/_route.html.erb
42
42
  - app/views/rest_framework/_routes.html.erb
43
+ - docs/CNAME
44
+ - docs/Gemfile
45
+ - docs/Gemfile.lock
46
+ - docs/_config.yml
47
+ - docs/_guide/1_routers.md
48
+ - docs/_guide/2_controller_mixins.md
49
+ - docs/_guide/3_serializers.md
50
+ - docs/_guide/4_filtering_and_ordering.md
51
+ - docs/_guide/5_pagination.md
52
+ - docs/_includes/anchor_headings.html
53
+ - docs/_includes/head.html
54
+ - docs/_includes/header.html
55
+ - docs/_layouts/default.html
56
+ - docs/assets/css/rest_framework.css
57
+ - docs/assets/images/favicon.ico
58
+ - docs/assets/js/rest_framework.js
59
+ - docs/index.md
43
60
  - lib/rest_framework.rb
44
61
  - lib/rest_framework/controller_mixins.rb
45
62
  - lib/rest_framework/controller_mixins/base.rb