resource_concern 0.0.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +5 -0
- data/README.md +26 -0
- data/lib/resource_concern.rb +35 -0
- data/resource_concern.gemspec +12 -0
- data/spec/resource_concern_spec.rb +9 -0
- metadata +47 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9e98481fd61e15b0a420dbde32bfa125e1d4d3b895aa23151225457a4cb386b1
|
4
|
+
data.tar.gz: cfd18208edc8d39fcc8a93e26f38fb4739144b1c8836c7dd2b2a324e1798d498
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 24ccf8b2d32e91558c1fc0d6b59b525e840a455f3c4fc59ade76841ad7fe2f69063b7e3bded80f403dfc19488e9697cec5c0d2a0aaebc688074bb55e5b8c758c
|
7
|
+
data.tar.gz: f74aa4de7c6492adfaf4e8e5ea905cd0e1bd42c07ecd001e4ccc9e36d2555c87f0be936cb4646532e0271c0aaf8e9779987e7ffec7a2365b8bd32b63e1aa458c
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# resource_concern
|
2
|
+
Include this controller concern in a RESTful controller to automatically look up the object and store it in the variable named by the controller. It automatically applies to [:destroy, :edit, :show, :update].
|
3
|
+
|
4
|
+
If you want it to do the lookup for a different method, invoke get_resource in that method.
|
5
|
+
|
6
|
+
For example:
|
7
|
+
```
|
8
|
+
class PostController < ApplicationController
|
9
|
+
include ResourceConcern
|
10
|
+
|
11
|
+
def show
|
12
|
+
# @post is automagically defined!
|
13
|
+
end
|
14
|
+
|
15
|
+
def author_view
|
16
|
+
get_resource
|
17
|
+
# @post is now defined
|
18
|
+
end
|
19
|
+
end
|
20
|
+
```
|
21
|
+
|
22
|
+
The default resource class is the name of the controller. It throws away any namespace component.
|
23
|
+
|
24
|
+
If you want to specify a different resource class, use:
|
25
|
+
|
26
|
+
`acts_as_resourceful klass: <Class::Name>`
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ResourceConcern
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
before_action :get_resource, only: %i[destroy edit show update]
|
8
|
+
end
|
9
|
+
|
10
|
+
class_methods do
|
11
|
+
def acts_as_resourceful(klass:)
|
12
|
+
define_method :rc_resource_klass do
|
13
|
+
klass
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def get_resource
|
19
|
+
@resource = rc_resource_klass.find(params[:id])
|
20
|
+
instance_variable_set "@#{rc_resource_name}", @resource
|
21
|
+
end
|
22
|
+
|
23
|
+
alias resource get_resource
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def rc_resource_klass
|
28
|
+
@rc_resource_klass ||=
|
29
|
+
self.class.to_s.gsub(/Controller/, '').gsub(/.*::/, '').singularize.constantize
|
30
|
+
end
|
31
|
+
|
32
|
+
def rc_resource_name
|
33
|
+
rc_resource_klass.name.gsub('::', '_').underscore
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'resource_concern'
|
3
|
+
s.version = '0.0.18'
|
4
|
+
s.date = '2015-01-15'
|
5
|
+
s.summary = 'resource_concern'
|
6
|
+
s.description = 'A cool gem'
|
7
|
+
s.authors = ['Jason Olim']
|
8
|
+
s.email = 'jason@olim.org'
|
9
|
+
s.files = `git ls-files`.split($/)
|
10
|
+
s.homepage = 'http://rubygems.org/gems/resource_concern'
|
11
|
+
s.license = 'MIT'
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: resource_concern
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.18
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jason Olim
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-15 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A cool gem
|
14
|
+
email: jason@olim.org
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- Gemfile
|
20
|
+
- README.md
|
21
|
+
- lib/resource_concern.rb
|
22
|
+
- resource_concern.gemspec
|
23
|
+
- spec/resource_concern_spec.rb
|
24
|
+
homepage: http://rubygems.org/gems/resource_concern
|
25
|
+
licenses:
|
26
|
+
- MIT
|
27
|
+
metadata: {}
|
28
|
+
post_install_message:
|
29
|
+
rdoc_options: []
|
30
|
+
require_paths:
|
31
|
+
- lib
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubygems_version: 3.0.2
|
44
|
+
signing_key:
|
45
|
+
specification_version: 4
|
46
|
+
summary: resource_concern
|
47
|
+
test_files: []
|