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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7c8bdc84abf94942e54c5007aedf0d5ed6258473
4
- data.tar.gz: b4cee9fb014e4a40ba1cdbba3d1caee1e45cf084
3
+ metadata.gz: 085758676d246a9dd5d66beaafb5cdaf9590e25d
4
+ data.tar.gz: d9e777683dbe93f7e8aa8729f88f9731ad5b09ae
5
5
  SHA512:
6
- metadata.gz: eefe5e914263f9fe5da1c41362d1c67b7289db996a19b86b5cc51edb67848ab07cdfcfa3ce049c7a38d3b85b2fcfd2901c9d6a7eba51aa31de8e0141ab975f56
7
- data.tar.gz: 0b37485ef2faca4106f55b81cac1fb8966854c75f9fa8faf31ca1ca8d05d2e8f7b3ba3634ee34ed3a3c2403ea33f5c98475c27759138def3dd7cf7001540d8bd
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
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '0.8.10'.freeze
2
+ VERSION = '0.8.11'.freeze
3
3
  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.10
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-08 00:00:00.000000000 Z
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