protector 0.7.6 → 0.7.7

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: 8d6e09054172469d5a87d231ad7f173504cb370d
4
- data.tar.gz: 6711053459b16743c42b18192406bbda09a1bd45
3
+ metadata.gz: 887a8a01b4826c0199726be2a4ec3375df624476
4
+ data.tar.gz: 240ab6a77289a4813f0e141d12f6dd4cb7f95fd3
5
5
  SHA512:
6
- metadata.gz: 73b84873fae0417524c733ccf96216e311923fc80fe69bf3bf690c26624a237297dd9c4166171830c2ed3e7978ce9dd5d28daf05e3e910f30e4b42ae48c12536
7
- data.tar.gz: d7390a28c52aa295aa46fa295a8cd250e5548c5e8916b71c39db6e077fd1cccfbe345710bcf3292249672a5925f8948f5889d56b95b6af82654a99ba62547da7
6
+ metadata.gz: fcec818537f70793185f37e1cf0ca1add42dc43d7de09cae213b899616f43c4516814a13fa96984e6bd1ca61f250393c06ee4b84ea5f420ea3cbf0182c331132
7
+ data.tar.gz: 2da8876bd0c678c98ab1e43903db81d47b85d3b86a5dedabe62a2bff83cd575da82828ee06d70239a47618ebd8fd8824f62c4d87a0936c2da05cf76124176421
@@ -2,6 +2,11 @@ rvm:
2
2
  - 1.9.3
3
3
  - jruby-19mode
4
4
  - 2.0.0
5
+ - 2.1.0
6
+
7
+ matrix:
8
+ allow_failures:
9
+ - gemfile: gemfiles/AR_edge.gemfile
5
10
 
6
11
  gemfile:
7
12
  - gemfiles/AR_3.2.gemfile
@@ -11,4 +16,4 @@ gemfile:
11
16
  - gemfiles/Rails_4.gemfile
12
17
  - gemfiles/Sequel.gemfile
13
18
 
14
- script: bundle exec rspec
19
+ script: bundle exec rspec
@@ -58,7 +58,7 @@ module Protector
58
58
  module ClassMethods
59
59
  # Storage of {Protector::DSL::Meta}
60
60
  def protector_meta
61
- @protector_meta ||= Protector::DSL::Meta.new(Protector::Adapters::ActiveRecord, self) do
61
+ ensure_protector_meta!(Protector::Adapters::ActiveRecord) do
62
62
  column_names
63
63
  end
64
64
  end
@@ -18,7 +18,7 @@ module Protector
18
18
  module ClassMethods
19
19
  # Storage of {Protector::DSL::Meta}
20
20
  def protector_meta
21
- @protector_meta ||= Protector::DSL::Meta.new(Protector::Adapters::Sequel, self) do
21
+ ensure_protector_meta!(Protector::Adapters::Sequel) do
22
22
  columns
23
23
  end
24
24
  end
@@ -212,7 +212,7 @@ module Protector
212
212
 
213
213
  fields.each do |k, v|
214
214
  case x = @access[part][k]
215
- when Range
215
+ when Enumerable
216
216
  return k unless x.include?(v)
217
217
  when Proc
218
218
  return k unless Protector.insecurely{ x.call(v) }
@@ -257,11 +257,21 @@ module Protector
257
257
  @blocks ||= []
258
258
  end
259
259
 
260
+ def blocks=(blocks)
261
+ @blocks = blocks
262
+ end
263
+
260
264
  # Register another protection block
261
265
  def <<(block)
262
266
  blocks << block
263
267
  end
264
268
 
269
+ def inherit(model, &fields_proc)
270
+ clone = self.class.new(@adapter, model, &fields_proc)
271
+ clone.blocks = @blocks.clone unless @blocks.nil?
272
+ clone
273
+ end
274
+
265
275
  # Calculate protection at the context of subject
266
276
  #
267
277
  # @param subject [Object] Restriction subject
@@ -317,6 +327,14 @@ module Protector
317
327
  def protect(&block)
318
328
  protector_meta << block
319
329
  end
330
+
331
+ def ensure_protector_meta!(adapter, &column_names)
332
+ @protector_meta ||= if superclass && superclass.respond_to?(:protector_meta)
333
+ superclass.protector_meta.inherit(self, &column_names)
334
+ else
335
+ Protector::DSL::Meta.new(adapter, self, &column_names)
336
+ end
337
+ end
320
338
  end
321
339
  end
322
340
  end
@@ -1,4 +1,4 @@
1
1
  module Protector
2
2
  # Gem version
3
- VERSION = '0.7.6'
3
+ VERSION = '0.7.7'
4
4
  end
@@ -0,0 +1,3 @@
1
+ ru:
2
+ protector:
3
+ invalid: "Нет прав доступа к полю '%{field}'"
@@ -21,6 +21,23 @@ shared_examples_for "a model" do
21
21
  meta.access[:update].should == fields
22
22
  end
23
23
 
24
+ it "respects inheritance" do
25
+ dummy.instance_eval do
26
+ protect do
27
+ can :read, :test
28
+ end
29
+ end
30
+
31
+ attempt = Class.new(dummy) do
32
+ protect do
33
+ can :create, :test
34
+ end
35
+ end
36
+
37
+ dummy.protector_meta.evaluate(nil, nil).access.should == {read: {"test"=>nil}}
38
+ attempt.protector_meta.evaluate(nil, nil).access.should == {read: {"test"=>nil}, create: {"test"=>nil}}
39
+ end
40
+
24
41
  it "drops meta on restrict" do
25
42
  d = Dummy.first
26
43
 
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.7.6
4
+ version: 0.7.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Boris Staal
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-06 00:00:00.000000000 Z
11
+ date: 2014-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -81,6 +81,7 @@ files:
81
81
  - lib/protector/engine.rb
82
82
  - lib/protector/version.rb
83
83
  - locales/en.yml
84
+ - locales/ru.yml
84
85
  - migrations/active_record.rb
85
86
  - migrations/sequel.rb
86
87
  - perf/active_record_perf.rb
@@ -118,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
119
  version: '0'
119
120
  requirements: []
120
121
  rubyforge_project:
121
- rubygems_version: 2.0.3
122
+ rubygems_version: 2.0.14
122
123
  signing_key:
123
124
  specification_version: 4
124
125
  summary: 'Protector is a successor to the Heimdallr gem: it hits the same goals keeping