authoraise 0.1.0 → 0.1.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: c413ae8e74f7d4f2d61548b8d18381805f8e20f4
4
- data.tar.gz: a4fdd291b24a7a163908c2fd1c175c87169c4515
3
+ metadata.gz: 5f24e784a52e7c2725bfc0eade0fe98a1909fcd4
4
+ data.tar.gz: cb91b76b2dea79aac821e178bfa288947d7d5f46
5
5
  SHA512:
6
- metadata.gz: 61092df57488c5df6f74dd84ae22a74e30c485b7d3569cb3d6460c648f758791338df5c41f921c4a6d372879da7509d2d15adf92e54f21929824e5d54fb88863
7
- data.tar.gz: bed1f0f0adcd85f44e01967532351bc9e9f56f8ff47edaabe1cfffaeec680e302867ca6a40d7cd3502d5b0bf12cd2258014f152b92bd0b57bdd5e0e6e2e6060c
6
+ metadata.gz: 4c60e2997ea5f5dabd5773a09315c9d81015b2064d85ad4d4d7b301a7ac410c17f249ab51e3ced94db87c75b1447162bc9329899ecf4a8f3911ccffa6b20601b
7
+ data.tar.gz: 922747b570f4d91313c363af7e394faf7f7cb853863808b2f2c2d7ed633d3b850d75b1bf7c18f0495c41166fe511e3172ec7d0f259c5410862b3d1e35564c2ec
data/README.md CHANGED
@@ -54,9 +54,9 @@ Authoraise.strict_mode = true
54
54
  # In stict mode any missing key raises an error, even if other checks passed.
55
55
  authorize(user: 'sammy') do |policy|
56
56
  policy.allow { |user| user == 'sammy' }
57
- policy.allow { |post| post.published? }
57
+ policy.allow { |post| post == 'foo' }
58
58
  end
59
- # => Authoraise::Error: Inconclusive authorization, missing keys: [:post]
59
+ # => Authoraise::Error: Strict mode found missing keys: [:post]
60
60
  ~~~
61
61
 
62
62
  ## Installation
@@ -1,3 +1,3 @@
1
1
  module Authoraise
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/authoraise.rb CHANGED
@@ -7,9 +7,9 @@ module Authoraise
7
7
  class << self; attr_accessor :strict_mode end
8
8
 
9
9
  def authorize(options = {})
10
- policy = Policy.new(options)
10
+ policy = Policy.new
11
11
  yield(policy)
12
- policy.authorize
12
+ policy.authorize(options)
13
13
  end
14
14
 
15
15
  class Check
@@ -36,8 +36,7 @@ module Authoraise
36
36
  end
37
37
 
38
38
  class Policy
39
- def initialize(options = {})
40
- @options = options
39
+ def initialize
41
40
  @checks = []
42
41
  @mode = :any
43
42
  end
@@ -47,15 +46,15 @@ module Authoraise
47
46
  Check.new(procedure.parameters.map(&:last), procedure)
48
47
  end
49
48
 
50
- def authorize
49
+ def authorize(options = {})
51
50
  raise Error, 'Policy is empty' if @checks.empty?
52
- given_keys = @options.keys.to_set
51
+ given_keys = options.keys.to_set
53
52
  assert_all_keys_match(given_keys) if Authoraise.strict_mode
54
53
  missing_keys = Set.new
55
54
 
56
55
  @checks.each do |check|
57
56
  if check.required_keys.subset?(given_keys)
58
- return true if check.(@options)
57
+ return true if check.(options)
59
58
  else
60
59
  missing_keys += check.missing_keys(given_keys)
61
60
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authoraise
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maxim Chernyak