effective_resources 0.8.10 → 0.8.11
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/README.md +10 -0
- data/app/models/concerns/acts_as_tokened.rb +44 -0
- data/lib/effective_resources/engine.rb +7 -0
- data/lib/effective_resources/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 085758676d246a9dd5d66beaafb5cdaf9590e25d
|
4
|
+
data.tar.gz: d9e777683dbe93f7e8aa8729f88f9731ad5b09ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 730e4cecbdbfd7ee0fac449657e90d37bf40417c45ec4ab24519f50fb48588b2bf8c3e73eea0a355a70d0d793c3e301ee28e2b7ca53a2a6ff15d2438a809e7a5
|
7
|
+
data.tar.gz: b95e549ee16faaceb680920bd3261109ac2a9cbf2b80c1b3eeda41e069657e6056aa2efd1150b7a0471dba359ebbb748126cfcb1bce5fa6a92325aba2190d9cd
|
data/README.md
CHANGED
@@ -173,6 +173,16 @@ to render just the `Save` button, with appropriate data-disable, title, etc.
|
|
173
173
|
|
174
174
|
= effective_submit(f) do
|
175
175
|
= f.save 'Will be appended'
|
176
|
+
```
|
177
|
+
|
178
|
+
### acts_as_tokened
|
179
|
+
|
180
|
+
Quickly adds rails 5 `has_secure_token` to your model, along with some `Post.find()` enhancements to work with tokens instead of IDs.
|
181
|
+
|
182
|
+
This prevents enumeration of this resource.
|
183
|
+
|
184
|
+
Make sure to create a string `token` field on your model, then just declare `acts_as_tokened`. There are no options.
|
185
|
+
|
176
186
|
|
177
187
|
## License
|
178
188
|
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# ActsAsTokened
|
2
|
+
#
|
3
|
+
# Implements rails 5 has_secure_token
|
4
|
+
# Extends the find() method to work with tokens instead of ids. Prevents enumeration of this resource.
|
5
|
+
|
6
|
+
module ActsAsTokened
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
module ActiveRecord
|
10
|
+
def acts_as_tokened(options = nil)
|
11
|
+
raise 'must respond to token' unless new().respond_to?(:token)
|
12
|
+
|
13
|
+
include ::ActsAsTokened
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
included do
|
18
|
+
has_secure_token
|
19
|
+
|
20
|
+
extend FinderMethods
|
21
|
+
end
|
22
|
+
|
23
|
+
module ClassMethods
|
24
|
+
def relation
|
25
|
+
super.tap { |relation| relation.extend(FinderMethods) }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
module FinderMethods
|
30
|
+
def find(*args)
|
31
|
+
return super unless args.length == 1
|
32
|
+
return super if block_given?
|
33
|
+
|
34
|
+
find_by_token(args.first) || raise(::ActiveRecord::RecordNotFound.new("Couldn't find #{name} with 'token'=#{args.first}"))
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Instance Methods
|
39
|
+
def to_param
|
40
|
+
token
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
@@ -16,5 +16,12 @@ module EffectiveResources
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
+
# Include acts_as_addressable concern and allow any ActiveRecord object to call it
|
20
|
+
initializer 'effective_resources.active_record' do |app|
|
21
|
+
ActiveSupport.on_load :active_record do
|
22
|
+
ActiveRecord::Base.extend(ActsAsTokened::ActiveRecord)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
19
26
|
end
|
20
27
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_resources
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-05-
|
11
|
+
date: 2018-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -38,6 +38,7 @@ files:
|
|
38
38
|
- app/controllers/concerns/effective/crud_controller.rb
|
39
39
|
- app/controllers/concerns/effective/flash_messages.rb
|
40
40
|
- app/helpers/effective_resources_helper.rb
|
41
|
+
- app/models/concerns/acts_as_tokened.rb
|
41
42
|
- app/models/effective/access_denied.rb
|
42
43
|
- app/models/effective/attribute.rb
|
43
44
|
- app/models/effective/code_reader.rb
|