rails-rapido 0.1.0 → 0.3.2
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 +4 -4
- data/.rubocop.yml +1 -1
- data/README.md +7 -69
- data/Rakefile +5 -1
- data/app/views/rapido/app/edit.slim +4 -0
- data/app/views/rapido/app/index.slim +14 -0
- data/app/views/rapido/app/new.slim +4 -0
- data/app/views/rapido/app/show.slim +10 -0
- data/lib/rapido.rb +29 -0
- data/lib/rapido/api_controller.rb +50 -0
- data/lib/rapido/app_controller.rb +95 -0
- data/lib/rapido/app_record_not_found.rb +12 -0
- data/lib/rapido/app_views.rb +21 -0
- data/lib/rapido/auth.rb +4 -0
- data/lib/rapido/auth/api_key.rb +41 -0
- data/lib/rapido/controller.rb +112 -89
- data/lib/rapido/errors.rb +8 -0
- data/lib/rapido/version.rb +1 -1
- data/rapido.gemspec +1 -0
- metadata +28 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d0cc71591ad6a2b6b8b2226f0c8c7a6a336599a
|
4
|
+
data.tar.gz: 0560d78f59cdc2e438558dc83b8eaa4375f1534b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39b81c33f1dbd7dfdbf72c2c0640698e4805df177d92916b447d954df1b922c8dd4861881d7f6a5546e80ec3f56aff728005d8229688510388046c2d72eaab0f
|
7
|
+
data.tar.gz: cd4497effc05b8e1b62d8774065fec76c7b5332857896dc133be45b782e1250cbb4c46ce3cc287f9fbb925dedbd261ee3fa8d81e804d60e9335504addce236cc
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -1,76 +1,10 @@
|
|
1
1
|
# Rapido
|
2
2
|
|
3
|
-
|
3
|
+
[](https://codeclimate.com/github/starfighterheavy/rapido)
|
4
4
|
|
5
|
-
|
5
|
+
Rapido is a simple, highly opinionated library that can be included into your Rails controllers to enforce standardized behavior and security.
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
```ruby
|
10
|
-
gem 'rapido'
|
11
|
-
```
|
12
|
-
|
13
|
-
And then execute:
|
14
|
-
|
15
|
-
$ bundle
|
16
|
-
|
17
|
-
Or install it yourself as:
|
18
|
-
|
19
|
-
$ gem install rapido
|
20
|
-
|
21
|
-
## Usage
|
22
|
-
|
23
|
-
Simply including the Rapido::Controller module into your controller is all you need to do if:
|
24
|
-
|
25
|
-
1. Odd controller name: your controller's name follows the standard [Resource.pluralize]Controller format.
|
26
|
-
1. Odd controller methods: you don't need any additional API endpoints other then the standard REST create/show/index/delete/update endpoints.
|
27
|
-
1. Resource ownership: the resource governed by your controller is not nested within an owner, e.g. /api/v1/[parent_resource]/[parent_resource_id]/[my_resource]
|
28
|
-
|
29
|
-
If your controller has any of these characteristics, you'll need to do a little bit more work to properly configure your controller.
|
30
|
-
|
31
|
-
### Odd controller name
|
32
|
-
|
33
|
-
If for some reason your controller name does not follow the standard format, you'll need to override the override the `resource_class` method. For example, if you have a controller named `MyOddleNamedWidgetController` for the `Widget` resource:
|
34
|
-
|
35
|
-
```
|
36
|
-
class MyOddlyNamedWidgetController < ApplicationController
|
37
|
-
include Rapido::Controller
|
38
|
-
|
39
|
-
private
|
40
|
-
|
41
|
-
def resource_class
|
42
|
-
Widget
|
43
|
-
end
|
44
|
-
end
|
45
|
-
```
|
46
|
-
|
47
|
-
|
48
|
-
### Odd controller methods
|
49
|
-
|
50
|
-
If you have endpoints other than create, show, index, update, and delete, you can add them as additional methods like so:
|
51
|
-
|
52
|
-
```
|
53
|
-
class WidgetsController < ApplicationController
|
54
|
-
include Rapido::Controller
|
55
|
-
|
56
|
-
def spin
|
57
|
-
resource.spin!
|
58
|
-
head :ok
|
59
|
-
end
|
60
|
-
end
|
61
|
-
```
|
62
|
-
|
63
|
-
### Resource ownership
|
64
|
-
|
65
|
-
If your resources has a `belongs_to` relationship that is reflected in the API route as a nested resource, you can specify the `resource_owner` class to include the relationship when retrieving the resource.
|
66
|
-
|
67
|
-
```
|
68
|
-
class WidgetsController < ApplicationController
|
69
|
-
include Radido::Controller
|
70
|
-
|
71
|
-
resource_owner_name :widget_factory
|
72
|
-
end
|
73
|
-
```
|
7
|
+
Documentation coming soon.
|
74
8
|
|
75
9
|
## Development
|
76
10
|
|
@@ -78,6 +12,10 @@ After checking out the repo, run `bin/setup` to install dependencies. You can al
|
|
78
12
|
|
79
13
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
80
14
|
|
15
|
+
## Testing
|
16
|
+
|
17
|
+
Run `rake` to execute the feature tests written for the sample application in the `test` directory.
|
18
|
+
|
81
19
|
## Contributing
|
82
20
|
|
83
21
|
Bug reports and pull requests are welcome on GitHub at https://github.com/jskirst/rapido.
|
data/Rakefile
CHANGED
@@ -0,0 +1,14 @@
|
|
1
|
+
h2= [@owner.name, @resource_class.name.capitalize.pluralize].compact.join(" ")
|
2
|
+
= link_to "New #{@resource_class.name.capitalize}", @new_path
|
3
|
+
table
|
4
|
+
thead
|
5
|
+
tr
|
6
|
+
- @resource_class.new.to_h.keys.each do |key|
|
7
|
+
th= key.to_s.capitalize
|
8
|
+
- @resource_collection.each do |resource|
|
9
|
+
tr
|
10
|
+
- resource.keys.each_with_index do |key, index|
|
11
|
+
- if index == 0
|
12
|
+
td= link_to resource.name, url_for([@owner, resource].compact)
|
13
|
+
- else
|
14
|
+
td= resource[key]
|
@@ -0,0 +1,10 @@
|
|
1
|
+
h2= @resource.name
|
2
|
+
|
3
|
+
= link_to "Edit", url_for([:edit, @owner, @resource].compact)
|
4
|
+
= link_to "Delete", url_for([@owner, @resource].compact), method: :delete
|
5
|
+
= link_to "Back", controller: params[:controller], action: "index"
|
6
|
+
|
7
|
+
dl
|
8
|
+
- @resource.to_h.each do |key, value|
|
9
|
+
dt= key
|
10
|
+
dd= value
|
data/lib/rapido.rb
CHANGED
@@ -1,5 +1,34 @@
|
|
1
1
|
require 'rapido/version'
|
2
2
|
require 'rapido/controller'
|
3
|
+
require 'rapido/api_controller'
|
4
|
+
require 'rapido/app_controller'
|
5
|
+
require 'rapido/app_views'
|
6
|
+
require 'rapido/app_record_not_found'
|
7
|
+
require 'rapido/auth/api_key'
|
3
8
|
|
4
9
|
module Rapido
|
10
|
+
class << self
|
11
|
+
attr_writer :configuration
|
12
|
+
end
|
13
|
+
|
14
|
+
class Configuration
|
15
|
+
attr_accessor :authority_class, :authority_lookup_param, :authority_lookup_field
|
16
|
+
|
17
|
+
def initialize
|
18
|
+
@authority_class = :account
|
19
|
+
@authority_lookup_param = :api_key
|
20
|
+
@authority_lookup_field = :api_key
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class Engine < ::Rails::Engine
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.configuration
|
28
|
+
@configuration ||= Configuration.new
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.configure
|
32
|
+
yield(configuration)
|
33
|
+
end
|
5
34
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
require 'active_support/core_ext'
|
3
|
+
require 'active_support/rescuable'
|
4
|
+
require 'rapido/errors'
|
5
|
+
|
6
|
+
module Rapido
|
7
|
+
module ApiController
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
include Rapido::Errors
|
11
|
+
|
12
|
+
included do
|
13
|
+
rescue_from RecordNotFound do |e|
|
14
|
+
render json: { errors: [ e.to_s ] }, status: 404
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def index
|
19
|
+
render json: resource_collection.map(&:to_h)
|
20
|
+
end
|
21
|
+
|
22
|
+
def show
|
23
|
+
render json: resource.to_h
|
24
|
+
end
|
25
|
+
|
26
|
+
def create
|
27
|
+
new_resource = build_resource
|
28
|
+
if new_resource.save
|
29
|
+
render json: new_resource.to_h, status: :created
|
30
|
+
else
|
31
|
+
render json: { errors: new_resource.errors.full_messages }, status: 422
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def destroy
|
36
|
+
resource_hsh = resource.to_h
|
37
|
+
resource.destroy
|
38
|
+
render json: resource_hsh
|
39
|
+
end
|
40
|
+
|
41
|
+
def update
|
42
|
+
resource.assign_attributes(resource_params)
|
43
|
+
if resource.save
|
44
|
+
render json: resource.to_h
|
45
|
+
else
|
46
|
+
render json: { errors: resource.errors.full_messages }, status: 422
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
require 'active_support/core_ext'
|
3
|
+
require 'rapido/errors'
|
4
|
+
|
5
|
+
module Rapido
|
6
|
+
module AppController
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
include Rapido::Errors
|
9
|
+
|
10
|
+
included do
|
11
|
+
before_action do
|
12
|
+
resource_permitted_params
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def index
|
17
|
+
@resource_collection = resource_collection
|
18
|
+
end
|
19
|
+
|
20
|
+
def show
|
21
|
+
@resource = resource
|
22
|
+
end
|
23
|
+
|
24
|
+
def new
|
25
|
+
@resource = owner.send(resource_class_name.pluralize).new
|
26
|
+
end
|
27
|
+
|
28
|
+
def create
|
29
|
+
new_resource = build_resource
|
30
|
+
if new_resource.save
|
31
|
+
redirect_to after_create_path(new_resource)
|
32
|
+
else
|
33
|
+
flash[:error] = new_resource.errors.full_messages.join('. ')
|
34
|
+
redirect_to new_path
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def destroy
|
39
|
+
resource.destroy
|
40
|
+
redirect_to after_delete_path(resource)
|
41
|
+
end
|
42
|
+
|
43
|
+
def edit
|
44
|
+
@resource = resource
|
45
|
+
end
|
46
|
+
|
47
|
+
def update
|
48
|
+
resource.assign_attributes(resource_params)
|
49
|
+
if resource.save
|
50
|
+
redirect_to after_update_path(resource)
|
51
|
+
else
|
52
|
+
flash[:error] = resource.errors.full_messages.join('. ')
|
53
|
+
resource.reload
|
54
|
+
redirect_to edit_path(resource)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def resource_path(action, resource = nil)
|
61
|
+
keys = { controller: params[:controller], action: action }
|
62
|
+
keys[resource_lookup_param] = resource.send(resource_lookup_param) if resource
|
63
|
+
keys[owner_lookup_param] = owner.send(owner_lookup_field) if owner_lookup_param.present?
|
64
|
+
url_for(keys)
|
65
|
+
end
|
66
|
+
|
67
|
+
def edit_path(resource)
|
68
|
+
@edit_path ||= resource_path(:edit, resource)
|
69
|
+
end
|
70
|
+
|
71
|
+
def show_path(resource)
|
72
|
+
@show_path ||= resource_path(:show, resource)
|
73
|
+
end
|
74
|
+
|
75
|
+
def new_path
|
76
|
+
@new_path ||= resource_path(:new)
|
77
|
+
end
|
78
|
+
|
79
|
+
def index_path
|
80
|
+
@index_path ||= resource_path(:index)
|
81
|
+
end
|
82
|
+
|
83
|
+
def after_create_path(resource)
|
84
|
+
show_path(resource)
|
85
|
+
end
|
86
|
+
|
87
|
+
def after_update_path(resource)
|
88
|
+
show_path(resource)
|
89
|
+
end
|
90
|
+
|
91
|
+
def after_delete_path(*)
|
92
|
+
index_path
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Rapido
|
2
|
+
module AppViews
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
before_action do
|
7
|
+
append_view_path (Rapido::Engine.root + 'app/views/rapido')
|
8
|
+
new_path
|
9
|
+
index_path
|
10
|
+
resource_class
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class_methods do
|
15
|
+
def local_prefixes
|
16
|
+
[controller_path, 'app']
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
data/lib/rapido/auth.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
module Rapido
|
2
|
+
module Auth
|
3
|
+
module ApiKey
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
before_action :load_authority
|
8
|
+
|
9
|
+
rescue_from LackAuthority do |e|
|
10
|
+
render json: { error: 'Request denied.' }, status: 401
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def authority_class
|
15
|
+
@authority_class ||=
|
16
|
+
Rapido.configuration.authority_class.to_s.camelize.constantize
|
17
|
+
end
|
18
|
+
|
19
|
+
def authority_lookup_param
|
20
|
+
@authority_lookup_param ||=
|
21
|
+
Rapido.configuration.authority_lookup_param
|
22
|
+
end
|
23
|
+
|
24
|
+
def authority_lookup_field
|
25
|
+
@authority_lookup_field ||=
|
26
|
+
Rapido.configuration.authority_lookup_field
|
27
|
+
end
|
28
|
+
|
29
|
+
def load_authority
|
30
|
+
@authority = authority_class.find_by(authority_lookup_field => params[authority_lookup_param])
|
31
|
+
raise LackAuthority unless @authority
|
32
|
+
end
|
33
|
+
|
34
|
+
def authority
|
35
|
+
@authority
|
36
|
+
end
|
37
|
+
|
38
|
+
class LackAuthority < StandardError; end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/rapido/controller.rb
CHANGED
@@ -1,150 +1,173 @@
|
|
1
1
|
require 'active_support'
|
2
2
|
require 'active_support/core_ext'
|
3
|
-
require '
|
3
|
+
require 'rapido/errors'
|
4
4
|
|
5
5
|
module Rapido
|
6
6
|
module Controller
|
7
7
|
extend ActiveSupport::Concern
|
8
8
|
|
9
|
-
|
10
|
-
rescue_from ActiveRecord::RecordNotFound do |e|
|
11
|
-
render json: { errors: [ e.to_s ] }, status: 404
|
12
|
-
end
|
13
|
-
end
|
9
|
+
include Rapido::Errors
|
14
10
|
|
15
11
|
class_methods do
|
16
|
-
def
|
17
|
-
@
|
18
|
-
@resource_owner_name
|
12
|
+
def authority(sym)
|
13
|
+
@authority_getter = sym.to_sym
|
19
14
|
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def index
|
23
|
-
render json: { resource_name.pluralize => resource_collection.map(&:to_h), meta: index_meta }
|
24
|
-
end
|
25
15
|
|
26
|
-
|
27
|
-
|
28
|
-
|
16
|
+
def belongs_to(sym, opts = {})
|
17
|
+
@owner_class = sym.to_sym
|
18
|
+
return @owner_getter = opts[:getter] if opts[:getter]
|
19
|
+
return owner_lookup_defaults unless opts[:foreign_key]
|
20
|
+
@owner_lookup_field = opts[:foreign_key]
|
21
|
+
if opts[:foreign_key_param]
|
22
|
+
owner_lookup_param(opts[:foreign_key_param])
|
23
|
+
else
|
24
|
+
owner_lookup_param(@owner_class, opts[:foreign_key])
|
25
|
+
end
|
26
|
+
end
|
29
27
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
render json: new_resource.to_h
|
34
|
-
else
|
35
|
-
render json: { errors: new_resource.errors.full_messages }, status: 422
|
28
|
+
def owner_lookup_defaults
|
29
|
+
owner_lookup_param(@owner_class, :id)
|
30
|
+
owner_lookup_field(:id)
|
36
31
|
end
|
37
|
-
end
|
38
32
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
33
|
+
def owner_lookup_param(*args)
|
34
|
+
return @owner_lookup_param = str.to_sym if args.count == 1
|
35
|
+
@owner_lookup_param = args.join('_').to_sym
|
36
|
+
end
|
43
37
|
|
44
|
-
|
45
|
-
|
46
|
-
if resource.save
|
47
|
-
render json: resource.to_h
|
48
|
-
else
|
49
|
-
render json: { errors: resource.errors.full_messages }, status: 422
|
38
|
+
def owner_lookup_field(str)
|
39
|
+
@owner_lookup_field = str.to_sym
|
50
40
|
end
|
51
|
-
end
|
52
41
|
|
53
|
-
|
42
|
+
def resource_class(str)
|
43
|
+
@resource_class = str.to_sym
|
44
|
+
end
|
54
45
|
|
55
|
-
def
|
56
|
-
|
57
|
-
pagination: {
|
58
|
-
per_page: resource_collection.limit_value,
|
59
|
-
total_pages: resource_collection.total_pages,
|
60
|
-
total_objects: resource_collection.count,
|
61
|
-
}
|
62
|
-
}
|
46
|
+
def lookup_param(str)
|
47
|
+
@resource_lookup_param = str.to_sym
|
63
48
|
end
|
64
49
|
|
65
|
-
def
|
66
|
-
|
50
|
+
def attr_permitted(*ary)
|
51
|
+
@resource_permitted_params = ary.map(&:to_sym)
|
67
52
|
end
|
68
53
|
|
69
|
-
def
|
70
|
-
|
54
|
+
def free_from_authority!
|
55
|
+
@free_from_authority = true
|
71
56
|
end
|
72
57
|
|
73
|
-
def
|
74
|
-
|
58
|
+
def permit_all_params!
|
59
|
+
@permit_all_params = true
|
75
60
|
end
|
61
|
+
end
|
76
62
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
63
|
+
private
|
64
|
+
|
65
|
+
def authority
|
66
|
+
@authority ||= begin
|
67
|
+
if setting(:free_from_authority)
|
68
|
+
nil
|
69
|
+
else
|
70
|
+
send(setting(:authority_getter))
|
71
|
+
end
|
72
|
+
end
|
81
73
|
end
|
82
74
|
|
83
|
-
def
|
84
|
-
|
85
|
-
|
86
|
-
.permit(resource_create_permitted_params)
|
75
|
+
def resource_permitted_params
|
76
|
+
@resource_permitted_params ||=
|
77
|
+
setting(:resource_permitted_params)
|
87
78
|
end
|
88
79
|
|
89
|
-
def
|
90
|
-
|
91
|
-
|
92
|
-
|
80
|
+
def resource_params
|
81
|
+
base = params.require(resource_class_name)
|
82
|
+
if setting(:permit_all_params)
|
83
|
+
base.permit!
|
84
|
+
else
|
85
|
+
base.permit(resource_permitted_params)
|
86
|
+
end
|
93
87
|
end
|
94
88
|
|
95
89
|
def build_resource
|
96
|
-
|
90
|
+
owner.send(resource_class_name.pluralize).new(resource_params)
|
97
91
|
end
|
98
92
|
|
99
93
|
def resource_collection
|
100
|
-
|
101
|
-
|
102
|
-
.page(params[:page])
|
94
|
+
@resource_collection ||= begin
|
95
|
+
raise RecordNotFound unless owner
|
96
|
+
owner.send(resource_class_name.pluralize).page(params[:page])
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def owner_class
|
101
|
+
@owner_class ||= begin
|
102
|
+
name = setting(:owner_class)
|
103
|
+
name.to_s.camelize.constantize
|
104
|
+
rescue NameError
|
105
|
+
raise BadOwnerClassName, name
|
106
|
+
end
|
103
107
|
end
|
104
108
|
|
105
|
-
def
|
106
|
-
|
107
|
-
@resource_owner_name ||= resource_owner.class.name.underscore
|
109
|
+
def owner_class_name
|
110
|
+
@owner_class_name ||= owner_class.name.downcase
|
108
111
|
end
|
109
112
|
|
110
|
-
def
|
111
|
-
@
|
113
|
+
def owner_lookup_param
|
114
|
+
@owner_lookup_param ||=
|
115
|
+
setting(:owner_lookup_param).to_s
|
112
116
|
end
|
113
117
|
|
114
|
-
def
|
115
|
-
|
118
|
+
def owner_lookup_field
|
119
|
+
@owner_lookup_field ||=
|
120
|
+
(setting(:owner_lookup_field) || owner_lookup_param).to_s
|
116
121
|
end
|
117
122
|
|
118
|
-
def
|
119
|
-
@
|
123
|
+
def owner
|
124
|
+
@owner ||= begin
|
125
|
+
if setting(:owner_getter)
|
126
|
+
send(setting(:owner_getter))
|
127
|
+
else
|
128
|
+
if setting(:free_from_authority)
|
129
|
+
base = owner_class
|
130
|
+
else
|
131
|
+
base = authority.send(owner_class_name.pluralize)
|
132
|
+
end
|
133
|
+
base.find_by!(owner_lookup_field => params[owner_lookup_param])
|
134
|
+
end
|
135
|
+
rescue ActiveRecord::RecordNotFound
|
136
|
+
raise RecordNotFound
|
137
|
+
end
|
120
138
|
end
|
121
139
|
|
122
140
|
def resource
|
123
|
-
@resource ||=
|
124
|
-
|
125
|
-
.
|
126
|
-
.
|
141
|
+
@resource ||= begin
|
142
|
+
owner
|
143
|
+
.send(resource_class_name.pluralize)
|
144
|
+
.find_by!(resource_lookup_param => params[resource_lookup_param])
|
145
|
+
rescue ActiveRecord::RecordNotFound
|
146
|
+
raise RecordNotFound
|
147
|
+
end
|
127
148
|
end
|
128
149
|
|
129
|
-
def
|
130
|
-
|
150
|
+
def resource_lookup_param
|
151
|
+
@resource_lookup_param ||=
|
152
|
+
setting(:resource_lookup_param) || :id
|
131
153
|
end
|
132
154
|
|
133
155
|
def resource_class
|
134
156
|
@resource_class ||=
|
135
|
-
|
157
|
+
(setting(:resource_class) ||
|
158
|
+
resource_class_from_controller).to_s.camelize.constantize
|
136
159
|
end
|
137
160
|
|
138
|
-
def
|
139
|
-
|
140
|
-
@resource_name ||= resource_controller_class.underscore
|
161
|
+
def resource_class_name(name = nil)
|
162
|
+
@resource_class_name ||= resource_class.name.underscore
|
141
163
|
end
|
142
164
|
|
143
|
-
def
|
144
|
-
|
145
|
-
self.class.name.split('::')[-1].remove('Controller').singularize
|
165
|
+
def resource_class_from_controller
|
166
|
+
self.class.name.split('::')[-1].remove('Controller').singularize.underscore
|
146
167
|
end
|
147
168
|
|
148
|
-
|
169
|
+
def setting(var)
|
170
|
+
self.class.instance_variable_get("@#{var}")
|
171
|
+
end
|
149
172
|
end
|
150
173
|
end
|
data/lib/rapido/version.rb
CHANGED
data/rapido.gemspec
CHANGED
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
22
22
|
spec.require_paths = ['lib']
|
23
23
|
|
24
|
+
spec.add_dependency 'kaminari', '~> 1.1'
|
24
25
|
spec.add_development_dependency 'bundler', '~> 1.14'
|
25
26
|
spec.add_development_dependency 'rake', '~> 10.0'
|
26
27
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-rapido
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Kirst
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: kaminari
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.1'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,10 +66,21 @@ files:
|
|
52
66
|
- Gemfile
|
53
67
|
- README.md
|
54
68
|
- Rakefile
|
69
|
+
- app/views/rapido/app/edit.slim
|
70
|
+
- app/views/rapido/app/index.slim
|
71
|
+
- app/views/rapido/app/new.slim
|
72
|
+
- app/views/rapido/app/show.slim
|
55
73
|
- bin/console
|
56
74
|
- bin/setup
|
57
75
|
- lib/rapido.rb
|
76
|
+
- lib/rapido/api_controller.rb
|
77
|
+
- lib/rapido/app_controller.rb
|
78
|
+
- lib/rapido/app_record_not_found.rb
|
79
|
+
- lib/rapido/app_views.rb
|
80
|
+
- lib/rapido/auth.rb
|
81
|
+
- lib/rapido/auth/api_key.rb
|
58
82
|
- lib/rapido/controller.rb
|
83
|
+
- lib/rapido/errors.rb
|
59
84
|
- lib/rapido/version.rb
|
60
85
|
- rapido.gemspec
|
61
86
|
homepage: https://github.com/jskirst/rapido
|
@@ -78,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
103
|
version: '0'
|
79
104
|
requirements: []
|
80
105
|
rubyforge_project:
|
81
|
-
rubygems_version: 2.
|
106
|
+
rubygems_version: 2.5.2
|
82
107
|
signing_key:
|
83
108
|
specification_version: 4
|
84
109
|
summary: Rails API Dryer-o
|