protector 0.5.5 → 0.6.0.beta.1

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
  SHA1:
3
- metadata.gz: ce979a4af923d6268b9a931f6ef02c41a907f482
4
- data.tar.gz: 4eeb250b2363f4cb0c00187a4f33bcdc0204c9a1
3
+ metadata.gz: 8246af354a37e155b5bfbcb3df55fb001b10d3a4
4
+ data.tar.gz: c0d84e8e3ab4a909a693397a420bbd60ede12e2c
5
5
  SHA512:
6
- metadata.gz: d790737a8c94f9c562f160b557a9d40b6e2503a9bf37a30b4a904df25cf1600dd4e0fe28b9c6b246a907e6cf495784abed60b4c7b64fb168660b3abaa6d4bbe2
7
- data.tar.gz: 92cf86b82aaed28a4a1ea10be9a97c4fdb28b6d142758f4153564ae4e035e4059a99840a3b37477dec0e9a2eaffff1b8fdcc5e1fd2e5b18d22e5d70ad8fb3a25
6
+ metadata.gz: 9d4ce7f662b483d145d390082f6457168b1c2823fce888c09393d0dfd942a15c72ed0efe231393544949ff92f12b6550262c6378d65af96a0d858ac32f5f48b4
7
+ data.tar.gz: 773f20d60bbbd7f62e6023fcff64aa686b1f4706a5c5716575559a3b0778b304e9ba277eb3df350ce6c8fb889f3cfe20c514cc6cddadfbeccc20225e996ff122
@@ -130,7 +130,7 @@ module Protector
130
130
  unscoped.protector_mimic_base!
131
131
 
132
132
  # Finally we merge unscoped basic relation extended with protection scope
133
- relation = relation.merge unscoped.instance_eval(&meta.scope_proc)
133
+ relation = relation.merge meta.eval_scope_procs(unscoped)
134
134
  end
135
135
  end
136
136
  else
@@ -40,7 +40,7 @@ module Protector
40
40
  return each_without_protector(*args, &block) unless protector_subject?
41
41
 
42
42
  relation = protector_defend_graph(clone, protector_subject)
43
- relation = relation.instance_eval(&protector_meta.scope_proc) if protector_meta.scoped?
43
+ relation = protector_meta.eval_scope_procs(relation) if protector_meta.scoped?
44
44
 
45
45
  relation.row_proc = Restrictor.new(protector_subject, relation.row_proc)
46
46
  relation.each_without_protector(*args, &block)
@@ -55,7 +55,7 @@ module Protector
55
55
  model = reflection[:class_name].constantize unless model
56
56
  meta = model.protector_meta.evaluate(subject)
57
57
 
58
- relation = relation.instance_eval(&meta.scope_proc) if meta.scoped?
58
+ relation = meta.eval_scope_procs(relation) if meta.scoped?
59
59
  end
60
60
 
61
61
  relation
data/lib/protector/dsl.rb CHANGED
@@ -17,7 +17,7 @@ module Protector
17
17
  @model = model
18
18
  @fields = fields
19
19
  @access = {update: {}, view: {}, create: {}}
20
- @scope_proc = false
20
+ @scope_procs = []
21
21
  @destroyable = false
22
22
 
23
23
  Protector.insecurely do
@@ -37,7 +37,7 @@ module Protector
37
37
  # Checks whether protection with given subject
38
38
  # has the selection scope defined
39
39
  def scoped?
40
- Protector.config.paranoid? || !!@scope_proc
40
+ Protector.config.paranoid? || @scope_procs.length > 0
41
41
  end
42
42
 
43
43
  # @group Protection DSL
@@ -53,25 +53,25 @@ module Protector
53
53
  # scope { none }
54
54
  # end
55
55
  def scope(&block)
56
- @scope_proc = block
57
-
58
- @relation = false
59
- @unscoped_relation = false
56
+ @scope_procs << block
57
+ @relation = false
60
58
  end
61
59
 
62
- def scope_proc
63
- unless Protector.config.paranoid?
64
- @scope_proc
65
- else
66
- @scope_proc || @adapter.null_proc
67
- end
60
+ def scope_procs
61
+ return [@adapter.null_proc] if @scope_procs.empty? && Protector.config.paranoid?
62
+ @scope_procs
68
63
  end
69
64
 
70
65
  def relation
71
66
  return false unless scoped?
72
67
 
73
- @relation ||= @model.instance_eval(&scope_proc)
74
- @relation
68
+ @relation ||= eval_scope_procs @model
69
+ end
70
+
71
+ def eval_scope_procs(instance)
72
+ return scope_procs.reduce(instance) do |relation, scope_proc|
73
+ relation.instance_eval(&scope_proc)
74
+ end
75
75
  end
76
76
 
77
77
  # Enables action for given fields.
@@ -1,4 +1,4 @@
1
1
  module Protector
2
2
  # Gem version
3
- VERSION = "0.5.5"
3
+ VERSION = "0.6.0.beta.1"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.5
4
+ version: 0.6.0.beta.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Boris Staal
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-18 00:00:00.000000000 Z
11
+ date: 2013-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -102,9 +102,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
102
102
  version: '0'
103
103
  required_rubygems_version: !ruby/object:Gem::Requirement
104
104
  requirements:
105
- - - '>='
105
+ - - '>'
106
106
  - !ruby/object:Gem::Version
107
- version: '0'
107
+ version: 1.3.1
108
108
  requirements: []
109
109
  rubyforge_project:
110
110
  rubygems_version: 2.0.6