perm 0.0.3 → 0.0.4

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: 939b74007f4554f28e417a3bb90126d717b338cb
4
- data.tar.gz: de861cba01bbe5c5d56b88966ec6a71493e506e2
3
+ metadata.gz: 712b2f9eb9df31bcd6f824064ada3f172463369f
4
+ data.tar.gz: 4294f43680738d9e0288b692c36d89fa3d5a5ba5
5
5
  SHA512:
6
- metadata.gz: fb4b3b0598e6516c95272a4d40c819f34a2a8fa698ec208a26d9d27cb125ee78e1a8dcedd972c556ff8d7e798f6903b864d9e0ed69ea94959b86a2cdded8f118
7
- data.tar.gz: 1dec4acfade13ebb62e1c87ef4b47e17c548c28ab4d97943890ae2abc74e8a88a67bcf04a37dcff9186b5990647b84dd5b3bcd1f41c7cb336f3752677feee84f
6
+ metadata.gz: 50030e29d11afd37313356220d0f9c0c61cd68cf38903b6e095ad24d71741dae56bbc9e58d5694fa63c6abe67ea113316d6b6ea7b2064e87a5b2734840b4986a
7
+ data.tar.gz: 8ace162e770291491995a59c93e6a593dc750e79334b272c85aadb39ff1aefccd677c7caee85f41e628d19e45d4b15e1002b6e18ad824a24b64d1be589d7c7a5
@@ -1,6 +1,7 @@
1
1
  require "roleup"
2
2
  require_relative "perm/version"
3
3
  require_relative "perm/authorizer"
4
+ require_relative "perm/has_authorizer"
4
5
 
5
6
  module Perm
6
7
  end
@@ -0,0 +1,22 @@
1
+ require "forwardable"
2
+
3
+ module Perm
4
+ module HasAuthorizer
5
+ extend Forwardable
6
+ def_delegators :"self.class", :authorizer_class, :user_method
7
+
8
+ def self.included(mod)
9
+ class << mod
10
+ attr_reader :authorizer_class, :user_method
11
+ def authorizes_with(klass, user_method)
12
+ @authorizer_class = klass
13
+ @user_method = user_method
14
+ end
15
+ end
16
+ end
17
+
18
+ def authorized_user
19
+ @authorized_user ||= authorizer_class.new(send(user_method))
20
+ end
21
+ end
22
+ end
@@ -1,3 +1,3 @@
1
1
  module Perm
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -1,11 +1,4 @@
1
- require "simplecov"
2
- require 'coveralls'
3
-
4
- SimpleCov.start
5
- SimpleCov.command_name "mt"
6
- Coveralls.wear!
7
-
8
- require_relative "../lib/perm"
1
+ require_relative "test_helper"
9
2
 
10
3
  module Perm
11
4
  class AuthorizerTest < MicroTest::Test
@@ -0,0 +1,38 @@
1
+ require_relative "test_helper"
2
+
3
+ module Perm
4
+ class HasAuthorizerTest < MicroTest::Test
5
+
6
+ class ExampleAuthorizer < Authorizer
7
+ def can_view?(object)
8
+ user[:roles].include? :viewer
9
+ end
10
+ end
11
+
12
+ class Example
13
+ include HasAuthorizer
14
+ authorizes_with ExampleAuthorizer, :current_user
15
+
16
+ attr_writer :current_user
17
+ def current_user
18
+ @current_user ||= { roles: [:viewer] }
19
+ end
20
+ end
21
+
22
+ before do
23
+ @example = Example.new
24
+ end
25
+
26
+ test "viewer can view" do
27
+ assert @example.authorized_user.can_view?({})
28
+ end
29
+
30
+ test "non-viewer cannot view" do
31
+ example = Example.new
32
+ example.current_user = { roles: [:other] }
33
+ assert !example.authorized_user.can_view?({})
34
+ end
35
+
36
+ end
37
+ end
38
+
@@ -0,0 +1,8 @@
1
+ require "simplecov"
2
+ require 'coveralls'
3
+
4
+ SimpleCov.start
5
+ SimpleCov.command_name "mt"
6
+ Coveralls.wear!
7
+
8
+ require_relative "../lib/perm"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: perm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Hopkins
@@ -89,8 +89,11 @@ extra_rdoc_files: []
89
89
  files:
90
90
  - lib/perm.rb
91
91
  - lib/perm/authorizer.rb
92
+ - lib/perm/has_authorizer.rb
92
93
  - lib/perm/version.rb
93
94
  - test/authorizer_test.rb
95
+ - test/has_authorizer_test.rb
96
+ - test/test_helper.rb
94
97
  homepage: https://github.com/hopsoft/perm
95
98
  licenses:
96
99
  - MIT
@@ -117,3 +120,5 @@ specification_version: 4
117
120
  summary: Simple permission management
118
121
  test_files:
119
122
  - test/authorizer_test.rb
123
+ - test/has_authorizer_test.rb
124
+ - test/test_helper.rb