rao-resource_controller 0.0.13.pre
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 +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +34 -0
- data/Rakefile +25 -0
- data/app/concerns/rao/resource_controller/location_history_concern.rb +42 -0
- data/app/concerns/rao/resource_controller/resource_concern.rb +13 -0
- data/app/concerns/rao/resource_controller/resource_inflections_concern.rb +18 -0
- data/app/concerns/rao/resource_controller/rest_actions_concern.rb +83 -0
- data/app/concerns/rao/resource_controller/rest_resource_urls_concern.rb +29 -0
- data/app/controllers/rao/resource_controller/base.rb +11 -0
- data/config/locales/de.yml +28 -0
- data/config/locales/en.yml +28 -0
- data/lib/generators/rao/resource_controller/install_generator.rb +15 -0
- data/lib/generators/rao/resource_controller/templates/initializer.rb +7 -0
- data/lib/rao/resource_controller/configuration.rb +11 -0
- data/lib/rao/resource_controller/engine.rb +7 -0
- data/lib/rao/resource_controller/version.rb +7 -0
- data/lib/rao/resource_controller.rb +11 -0
- data/lib/rao-resource_controller.rb +3 -0
- metadata +131 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 609d38240914ca0d18bcabf1e5d3dd89f3ef5a21a3ee472682fccbea58796c82
|
4
|
+
data.tar.gz: ebe6b7184a94bb72e4f4a0d1756123cec5b9dc34649e2c4ad0c90c8174daf541
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 51b8c387fbce5cd7936a950c854eefc07e6a48c1c1b37ff1143e820d690439b54a0a7ae4bee8b6716e9755780c7dc77c7c7050c69d88e8b2a7e2e32100557b15
|
7
|
+
data.tar.gz: e28cbbabc3cab6a048309be780ff5a875b82ca8f714164dd67b0c697e33d23c0c873d1573ab06169b1ab192de43ec4f133177b84d670d7d4159dfeef968659d8
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2018 Roberto Vasquez Angel
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# Rails AddOns Resource Controller
|
2
|
+
Short description and motivation.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
How to use my plugin.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'rao-resource_controller'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
```bash
|
21
|
+
$ gem install rao-resource_controller
|
22
|
+
```
|
23
|
+
|
24
|
+
Generate the initializer:
|
25
|
+
|
26
|
+
```bash
|
27
|
+
$ rails g rao:resource_controller:install
|
28
|
+
```
|
29
|
+
|
30
|
+
## Contributing
|
31
|
+
Contribution directions go here.
|
32
|
+
|
33
|
+
## License
|
34
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Rails Add-Ons Resources Controller'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
|
21
|
+
load 'rails/tasks/statistics.rake'
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
require 'bundler/gem_tasks'
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Rao
|
2
|
+
module ResourceController::LocationHistoryConcern
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
if respond_to?(:before_action)
|
7
|
+
before_action :store_location
|
8
|
+
else
|
9
|
+
before_filter :store_location
|
10
|
+
end
|
11
|
+
|
12
|
+
helper_method :last_location
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def store_location
|
18
|
+
return if request.referer.nil?
|
19
|
+
truncate_location_history(9)
|
20
|
+
puts "[LocationHistoryConcern] Storing last location [#{request.referer}]"
|
21
|
+
location_history[Time.zone.now] = request.referer
|
22
|
+
end
|
23
|
+
|
24
|
+
def location_history
|
25
|
+
session[:location_history] ||= {}
|
26
|
+
end
|
27
|
+
|
28
|
+
def last_location
|
29
|
+
location_history.sort.last.try(:last)
|
30
|
+
end
|
31
|
+
|
32
|
+
def truncate_location_history(count = 0)
|
33
|
+
return if location_history.size <= count
|
34
|
+
truncated = session[:location_history].sort.last(count)
|
35
|
+
session[:location_history] = if truncated.respond_to?(:to_h)
|
36
|
+
truncated.to_h
|
37
|
+
else
|
38
|
+
truncated.each_with_object({}) { |a, hash| hash[a.first] = a.last }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Rao
|
2
|
+
module ResourceController::ResourceInflectionsConcern
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
helper_method :inflections
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def inflections
|
12
|
+
{
|
13
|
+
resource_name: resource_class.model_name.human(count: 1),
|
14
|
+
collection_name: resource_class.model_name.human(count: 2)
|
15
|
+
}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module Rao
|
2
|
+
module ResourceController::RestActionsConcern
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
include ActionController::MimeResponds
|
7
|
+
|
8
|
+
respond_to :html
|
9
|
+
responders :flash
|
10
|
+
|
11
|
+
if respond_to?(:before_action)
|
12
|
+
before_action :load_resource, only: [:show, :edit, :destroy, :update]
|
13
|
+
before_action :initialize_resource, only: [:new]
|
14
|
+
before_action :initialize_resource_for_create, only: [:create]
|
15
|
+
before_action :before_rest_action, if: -> { respond_to?(:before_rest_action, true) }
|
16
|
+
else
|
17
|
+
before_filter :load_resource, only: [:show, :edit, :destroy, :update]
|
18
|
+
before_filter :initialize_resource, only: [:new]
|
19
|
+
before_filter :initialize_resource_for_create, only: [:create]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def new; end
|
24
|
+
def show; end
|
25
|
+
def edit; end
|
26
|
+
|
27
|
+
def update
|
28
|
+
if @resource.send(update_method_name, permitted_params) && respond_to?(:after_update_location, true) && after_update_location.present?
|
29
|
+
respond_with(respond_with_namespace, @resource, location: after_update_location)
|
30
|
+
else
|
31
|
+
respond_with(respond_with_namespace, @resource)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def destroy
|
36
|
+
@resource.destroy
|
37
|
+
if respond_to?(:after_destroy_location, true) && after_destroy_location.present?
|
38
|
+
respond_with(respond_with_namespace, @resource, location: after_destroy_location)
|
39
|
+
else
|
40
|
+
respond_with(respond_with_namespace, @resource)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def create
|
45
|
+
if @resource.save && respond_to?(:after_create_location, true) && after_create_location.present?
|
46
|
+
respond_with(respond_with_namespace, @resource, location: after_create_location)
|
47
|
+
else
|
48
|
+
respond_with(respond_with_namespace, @resource)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def update_method_name
|
55
|
+
Rails::VERSION::MAJOR < 4 ? :update_attributes : :update
|
56
|
+
end
|
57
|
+
|
58
|
+
def respond_with_namespace
|
59
|
+
nil
|
60
|
+
end
|
61
|
+
|
62
|
+
def load_resource_scope
|
63
|
+
resource_class
|
64
|
+
end
|
65
|
+
|
66
|
+
def load_resource
|
67
|
+
# @resource = load_resource_scope.find(params[:id])
|
68
|
+
raise "Please define #load_resource in #{self.class.name} and tell me how to load @resource."
|
69
|
+
end
|
70
|
+
|
71
|
+
def initialize_resource
|
72
|
+
@resource = resource_class.new
|
73
|
+
end
|
74
|
+
|
75
|
+
def initialize_resource_for_create
|
76
|
+
@resource = resource_class.new(permitted_params)
|
77
|
+
end
|
78
|
+
|
79
|
+
def permitted_params
|
80
|
+
raise "not implemented"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Rao
|
2
|
+
module ResourceController::RestResourceUrlsConcern
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
helper_method :new_resource_path
|
7
|
+
helper_method :resource_path
|
8
|
+
helper_method :edit_resource_path
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def new_resource_path
|
14
|
+
resource_router.send(:url_for, { action: :new, only_path: true })
|
15
|
+
end
|
16
|
+
|
17
|
+
def resource_path(resource)
|
18
|
+
resource_router.send(:url_for, { action: :show, id: resource, only_path: true })
|
19
|
+
end
|
20
|
+
|
21
|
+
def edit_resource_path(resource)
|
22
|
+
resource_router.send(:url_for, { action: :edit, id: resource, only_path: true })
|
23
|
+
end
|
24
|
+
|
25
|
+
def resource_router
|
26
|
+
self
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Rao
|
2
|
+
module ResourceController
|
3
|
+
class Base < Rao::ResourceController::Configuration.resource_controller_base_class_name.constantize
|
4
|
+
include RestActionsConcern
|
5
|
+
include ResourceConcern
|
6
|
+
include RestResourceUrlsConcern
|
7
|
+
include ResourceInflectionsConcern
|
8
|
+
include LocationHistoryConcern
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
de:
|
2
|
+
flash:
|
3
|
+
actions:
|
4
|
+
create:
|
5
|
+
notice: "%{resource_name} wurde erstellt."
|
6
|
+
update:
|
7
|
+
notice: "%{resource_name} wurde aktualisiert."
|
8
|
+
destroy:
|
9
|
+
notice: "%{resource_name} wurde gelöscht."
|
10
|
+
alert: "%{resource_name} konnte nicht gelöscht werden."
|
11
|
+
perform:
|
12
|
+
notice: "%{resource_name} wurde ausgeführt."
|
13
|
+
alert: "%{resource_name} konnte nicht ausgeführt werden. Es traten folgende Fehler auf: %{errors}"
|
14
|
+
rao:
|
15
|
+
resource_controller:
|
16
|
+
base:
|
17
|
+
form_buttons:
|
18
|
+
cancel: "Abbrechen"
|
19
|
+
edit:
|
20
|
+
title: "%{resource_name} bearbeiten"
|
21
|
+
index:
|
22
|
+
new: "Erstellen"
|
23
|
+
new:
|
24
|
+
title: "%{resource_name} erstellen"
|
25
|
+
show_actions:
|
26
|
+
back: "Zurück"
|
27
|
+
delete: "Löschen"
|
28
|
+
edit: "Bearbeiten"
|
@@ -0,0 +1,28 @@
|
|
1
|
+
en:
|
2
|
+
flash:
|
3
|
+
actions:
|
4
|
+
create:
|
5
|
+
notice: "%{resource_name} was successfully created."
|
6
|
+
update:
|
7
|
+
notice: "%{resource_name} was successfully updated."
|
8
|
+
destroy:
|
9
|
+
notice: "%{resource_name} was successfully destroyed."
|
10
|
+
alert: "%{resource_name} could not be destroyed."
|
11
|
+
perform:
|
12
|
+
notice: "%{resource_name} was executed."
|
13
|
+
alert: "%{resource_name} could not be executed. Errors: %{errors}"
|
14
|
+
rao:
|
15
|
+
resource_controller:
|
16
|
+
base:
|
17
|
+
form_buttons:
|
18
|
+
cancel: "Cancel"
|
19
|
+
edit:
|
20
|
+
title: "Edit %{resource_name}"
|
21
|
+
index:
|
22
|
+
new: "New"
|
23
|
+
new:
|
24
|
+
title: "New %{resource_name}"
|
25
|
+
show_actions:
|
26
|
+
back: "Back"
|
27
|
+
delete: "Delete"
|
28
|
+
edit: "Edit"
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Rao
|
2
|
+
module ResourceController
|
3
|
+
module Generators
|
4
|
+
class InstallGenerator < Rails::Generators::Base
|
5
|
+
desc 'Generates the initializer'
|
6
|
+
|
7
|
+
source_root File.expand_path('../templates', __FILE__)
|
8
|
+
|
9
|
+
def generate_initializer
|
10
|
+
template 'initializer.rb', 'config/initializers/rao-resource_controller.rb'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
Rao::ResourceController.configure do |config|
|
2
|
+
# Set the base controller for resource controllers.
|
3
|
+
#
|
4
|
+
# default: config.resource_controller_base_class_name = '::ApplicationController'
|
5
|
+
#
|
6
|
+
config.resource_controller_base_class_name = '::ApplicationController'
|
7
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require "rao/resource_controller/configuration"
|
2
|
+
require "rao/resource_controller/version"
|
3
|
+
require "rao/resource_controller/engine"
|
4
|
+
|
5
|
+
module Rao
|
6
|
+
module ResourceController
|
7
|
+
extend Configuration
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
Rao.configure { |c| c.register_configuration(:resource_controller, Rao::ResourceController) }
|
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rao-resource_controller
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.13.pre
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Roberto Vasquez Angel
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-03-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rao
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: guard-rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: guard-bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- roberto@vasquez-angel.de
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- MIT-LICENSE
|
91
|
+
- README.md
|
92
|
+
- Rakefile
|
93
|
+
- app/concerns/rao/resource_controller/location_history_concern.rb
|
94
|
+
- app/concerns/rao/resource_controller/resource_concern.rb
|
95
|
+
- app/concerns/rao/resource_controller/resource_inflections_concern.rb
|
96
|
+
- app/concerns/rao/resource_controller/rest_actions_concern.rb
|
97
|
+
- app/concerns/rao/resource_controller/rest_resource_urls_concern.rb
|
98
|
+
- app/controllers/rao/resource_controller/base.rb
|
99
|
+
- config/locales/de.yml
|
100
|
+
- config/locales/en.yml
|
101
|
+
- lib/generators/rao/resource_controller/install_generator.rb
|
102
|
+
- lib/generators/rao/resource_controller/templates/initializer.rb
|
103
|
+
- lib/rao-resource_controller.rb
|
104
|
+
- lib/rao/resource_controller.rb
|
105
|
+
- lib/rao/resource_controller/configuration.rb
|
106
|
+
- lib/rao/resource_controller/engine.rb
|
107
|
+
- lib/rao/resource_controller/version.rb
|
108
|
+
homepage: https://github.com/rails-add_ons
|
109
|
+
licenses:
|
110
|
+
- MIT
|
111
|
+
metadata: {}
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">"
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: 1.3.1
|
126
|
+
requirements: []
|
127
|
+
rubygems_version: 3.0.2
|
128
|
+
signing_key:
|
129
|
+
specification_version: 4
|
130
|
+
summary: Singular Resource Controllers for Ruby on Rails.
|
131
|
+
test_files: []
|