rails-rapido 0.7.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e760926a00345a215ee81e2f07e620e0498d666e9ebb2a392785c65309040d37
4
- data.tar.gz: aa33316931a8e3f0b9d68feddc8f05cabfe6cc13c56b536bf4bc874454f9168e
3
+ metadata.gz: b6eaff7850cbfee3ff250c0346fc8803ed9b29b6abe046622c72883eac6b3777
4
+ data.tar.gz: 61dfea4640f66a7fb095e618890b9224fcf3a0f371a6dbdcef9201194b1966b2
5
5
  SHA512:
6
- metadata.gz: a268be80dd28145f90834cdbc5af313d6164760c7cb39fda01469de23db7299e3612a10e85ef69be84ae9a40fde1ae8714a23d1965d6612a9f59319c23294b62
7
- data.tar.gz: 2a470da81728cd4aa9b654b9289cc2afaab22777b2cd287f853ab365eb1056abb98f2019364f19afae157894b7479377270c45080dc2c6a881670ad4d77cf3e3
6
+ metadata.gz: dd665acfb46b79e7b80704cc64ba8d3fbe8780c51cb7196a3d39552f036e2df35138cb442126d1f0ca08b23038ef185b8b538a4c62de42c7403c74e3a03b6fe5
7
+ data.tar.gz: c31a11e293f0e2deca6de6c69d504c1ef836c9424bb8bd18a409c1275f5030c55a5541a7751908f358fda3ed27dd56680c6bbf6407840d3a68b9ab5a7fcad6a6
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.6.3
1
+ 2.6.5
data/README.md CHANGED
@@ -32,6 +32,10 @@ Specifies the method to call to retrieve the owner, rather than retrieving by wi
32
32
 
33
33
  This can be useful when ownership exists but is not reflected in the route structure explicitly.
34
34
 
35
+ **build**
36
+
37
+ You can create override the class Rapido::Controller build method directly in situations where the owner class does not have a build_[resource] method. Note that `has_one` will execute first if set to true, ignoring any `build` method you create directly, so if you do override it do not set `has_one: true`.
38
+
35
39
  **foreign_key**
36
40
 
37
41
  Default `id`. Specifies the name of the lookup column for the owner. For example, if `Post` belongs to `User`, then in the `PostsController` if `belongs_to :user, foreign_key: :token` is supplied, then the post would be retrieved like so:
data/lib/rapido.rb CHANGED
@@ -1,9 +1,6 @@
1
1
  require 'rapido/version'
2
2
  require 'rapido/controller'
3
3
  require 'rapido/api_controller'
4
- require 'rapido/app_controller'
5
- require 'rapido/app_record_not_found'
6
- require 'rapido/auth/api_key'
7
4
 
8
5
  module Rapido
9
6
  class << self
@@ -11,12 +8,7 @@ module Rapido
11
8
  end
12
9
 
13
10
  class Configuration
14
- attr_accessor :authority_class, :authority_lookup_param, :authority_lookup_field
15
-
16
11
  def initialize
17
- @authority_class = :account
18
- @authority_lookup_param = :api_key
19
- @authority_lookup_field = :api_key
20
12
  end
21
13
  end
22
14
 
@@ -56,6 +56,7 @@ module Rapido
56
56
  @collection_presenter ||= presenter_class
57
57
  @collection_presenter_args = args if args.count > 0
58
58
  end
59
+ alias present_collection_with collection_presented_by
59
60
 
60
61
  def owner_lookup_defaults
61
62
  owner_lookup_param(@owner_class, :id)
@@ -91,6 +92,7 @@ module Rapido
91
92
  @presenter ||= presenter_class
92
93
  @presenter_args = args if args.count > 0
93
94
  end
95
+ alias present_with presented_by
94
96
  end
95
97
 
96
98
  private
@@ -1,3 +1,3 @@
1
1
  module Rapido
2
- VERSION = '0.7.1'
2
+ VERSION = '0.8.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-rapido
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Kirst
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-27 00:00:00.000000000 Z
11
+ date: 2020-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -56,18 +56,10 @@ files:
56
56
  - LICENSE
57
57
  - README.md
58
58
  - Rakefile
59
- - app/views/rapido/app/edit.slim
60
- - app/views/rapido/app/index.slim
61
- - app/views/rapido/app/new.slim
62
- - app/views/rapido/app/show.slim
63
59
  - bin/console
64
60
  - bin/setup
65
61
  - lib/rapido.rb
66
62
  - lib/rapido/api_controller.rb
67
- - lib/rapido/app_controller.rb
68
- - lib/rapido/app_record_not_found.rb
69
- - lib/rapido/auth.rb
70
- - lib/rapido/auth/api_key.rb
71
63
  - lib/rapido/controller.rb
72
64
  - lib/rapido/errors.rb
73
65
  - lib/rapido/version.rb
@@ -1,4 +0,0 @@
1
- = simple_form_for([@owner, @resource].compact) do |f|
2
- - @resource_permitted_params.each do |param|
3
- = f.input param
4
- = f.submit "Save"
@@ -1,13 +0,0 @@
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_permitted_params.each do |key|
7
- th= key.to_s.capitalize
8
- - @resource_collection.each do |resource|
9
- tr
10
- td= link_to resource.name, url_for([@owner, resource].compact)
11
- - @resource_permitted_params.each do |key|
12
- - next if key == "name"
13
- td= resource[key]
@@ -1,5 +0,0 @@
1
- h1 New #{@resource.class.name}
2
- = simple_form_for([@owner, @resource].compact) do |f|
3
- - @resource_permitted_params.each do |param|
4
- = f.input param
5
- = f.submit "Save"
@@ -1,13 +0,0 @@
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_permitted_params.each do |key, value|
9
- dt= key
10
- dd= value
11
-
12
- - owned_resources.each do |owned_resource|
13
- = link_to "View #{owned_resource.to_s.pluralize.capitalize}", url_for([nil, @owner, @resource, owned_resource].compact)
@@ -1,124 +0,0 @@
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
- Rails.logger.info 'The AppController has been deprecated and will be removed in the v1.0 release.'
12
- before_action do
13
- resource_permitted_params
14
- end
15
- helper_method :owned_resources
16
- end
17
-
18
- def index
19
- @resource_collection = resource_collection
20
- end
21
-
22
- def show
23
- @resource = resource
24
- end
25
-
26
- def new
27
- @resource = build_resource
28
- end
29
-
30
- def create
31
- new_resource = build_resource(resource_params)
32
- if new_resource.save
33
- after_create_success(new_resource)
34
- return if performed?
35
- redirect_to after_create_path(new_resource)
36
- else
37
- flash[:error] = new_resource.errors.full_messages.join('. ')
38
- after_create_failure(new_resource)
39
- return if performed?
40
- redirect_to new_path
41
- end
42
- end
43
-
44
- def destroy
45
- unless resource.destroy
46
- flash[:error] = resource.errors.full_messages.join('. ')
47
- end
48
- after_destroy_success(resource)
49
- return if performed?
50
- redirect_to after_delete_path(resource)
51
- end
52
-
53
- def edit
54
- @resource = resource
55
- end
56
-
57
- def update
58
- resource.assign_attributes(resource_params)
59
- if resource.save
60
- after_update_success(resource)
61
- return if performed?
62
- redirect_to after_update_path(resource)
63
- else
64
- flash[:error] = resource.errors.full_messages.join('. ')
65
- resource.reload
66
- after_update_failure(resource)
67
- return if performed?
68
- redirect_to edit_path(resource)
69
- end
70
- end
71
-
72
- private
73
-
74
- def after_create_success(*)
75
- end
76
-
77
- def after_create_failure(*)
78
- end
79
-
80
- def after_update_success(*)
81
- end
82
-
83
- def after_update_failure(*)
84
- end
85
-
86
- def after_destroy_success(*)
87
- end
88
-
89
- def resource_path(action, resource = nil)
90
- keys = { controller: params[:controller], action: action }
91
- keys[resource_lookup_param] = resource.send(resource_lookup_param) if resource
92
- keys[owner_lookup_param] = owner.send(owner_lookup_field) if owner_lookup_param.present?
93
- url_for(keys)
94
- end
95
-
96
- def edit_path(resource)
97
- @edit_path ||= resource_path(:edit, resource)
98
- end
99
-
100
- def show_path(resource)
101
- @show_path ||= resource_path(:show, resource)
102
- end
103
-
104
- def new_path
105
- @new_path ||= resource_path(:new)
106
- end
107
-
108
- def index_path
109
- @index_path ||= resource_path(:index)
110
- end
111
-
112
- def after_create_path(resource)
113
- show_path(resource)
114
- end
115
-
116
- def after_update_path(resource)
117
- show_path(resource)
118
- end
119
-
120
- def after_delete_path(*)
121
- index_path
122
- end
123
- end
124
- end
@@ -1,12 +0,0 @@
1
- module Rapido
2
- module AppRecordNotFound
3
- extend ActiveSupport::Concern
4
- include Rapido::Errors
5
-
6
- included do
7
- rescue_from RecordNotFound do |e|
8
- render file: 'public/404', status: :not_found, layout: false
9
- end
10
- end
11
- end
12
- end
data/lib/rapido/auth.rb DELETED
@@ -1,4 +0,0 @@
1
- module Rapido
2
- module Auth
3
- end
4
- end
@@ -1,42 +0,0 @@
1
- module Rapido
2
- module Auth
3
- module ApiKey
4
- extend ActiveSupport::Concern
5
-
6
- included do
7
- Rails.logger.info 'The Auth module has been deprecated and will be removed in the 1.0 release.'
8
- before_action :load_authority
9
-
10
- rescue_from LackAuthority do |e|
11
- render json: { error: 'Request denied.' }, status: 401
12
- end
13
- end
14
-
15
- def authority_class
16
- @authority_class ||=
17
- Rapido.configuration.authority_class.to_s.camelize.constantize
18
- end
19
-
20
- def authority_lookup_param
21
- @authority_lookup_param ||=
22
- Rapido.configuration.authority_lookup_param
23
- end
24
-
25
- def authority_lookup_field
26
- @authority_lookup_field ||=
27
- Rapido.configuration.authority_lookup_field
28
- end
29
-
30
- def load_authority
31
- @authority = authority_class.find_by(authority_lookup_field => params[authority_lookup_param])
32
- raise LackAuthority unless @authority
33
- end
34
-
35
- def authority
36
- @authority
37
- end
38
-
39
- class LackAuthority < StandardError; end
40
- end
41
- end
42
- end