u-authorization 2.0.0 → 2.1.0

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
  SHA256:
3
- metadata.gz: 49ee3c29a92d117c33706e12939a2ced02597514586ae7cf06fe73622d15897f
4
- data.tar.gz: b1991fa714603aa32a6288447796460287adcd6220a8485d6e82d6040c4e48cf
3
+ metadata.gz: fae66869f76df547c31db71f122b5b2325305e647ac8292b0580ae79e7f2baf6
4
+ data.tar.gz: 06ee2555095a23ddf2c62ade52bc7f207758762950f10b15e3a06798f0e85cdc
5
5
  SHA512:
6
- metadata.gz: d480100a329ab41e4707cb124f46d85af1750fc35ee08e615b1cc488714cb8e817394b8b91acf6c965710faf7235a90c13827cf7369c920e974e39d77ad6446b
7
- data.tar.gz: d427583d3e8c633138e018d2f2d5c339a615976622a6b224d1e0e370634cc09f08bc5ceb158caff480b9fabaa588aed85340282c58a44ca8bf509d857e181860
6
+ metadata.gz: d3f855677e13bb60e5aea15fa662b0c24d5d563ee6dbcf986404442c082c153bdbd3deb20c2844dfb4f34ee12148161a35530afb71518b56457a23c893b28ea5
7
+ data.tar.gz: f5ade9d183a7c95ee78f13628f5e9a680959ee0d8aefd4f12c1c4e5ec1f318cf55287cb4703a8c4bd32c59133ef57817338b708c7e48980f91764ade66af563d
data/.travis.yml ADDED
@@ -0,0 +1,28 @@
1
+ language: ruby
2
+
3
+ sudo: false
4
+
5
+ rvm:
6
+ - 2.2.0
7
+ - 2.3.0
8
+ - 2.4.0
9
+ - 2.5.0
10
+ - 2.6.0
11
+
12
+ cache: bundler
13
+
14
+ before_install:
15
+ - gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true
16
+ - gem install bundler -v '< 2'
17
+
18
+ install: bundle install --jobs=3 --retry=3
19
+
20
+ before_script:
21
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
22
+ - chmod +x ./cc-test-reporter
23
+ - "./cc-test-reporter before-build"
24
+
25
+ script: "rake"
26
+
27
+ after_success:
28
+ - "./cc-test-reporter after-build -t simplecov"
data/Gemfile CHANGED
@@ -1,8 +1,10 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'simplecov', require: false, group: :test
4
-
5
- gem 'minitest', '~> 5.11', '>= 5.11.3'
3
+ group :test do
4
+ gem 'minitest', '~> 5.11', '>= 5.11.3'
5
+ gem 'minitest-reporters', '~> 1.3', '>= 1.3.6'
6
+ gem 'simplecov', require: false
7
+ end
6
8
 
7
9
  # Specify your gem's dependencies in u-authorization.gemspec
8
10
  gemspec
data/Gemfile.lock CHANGED
@@ -1,15 +1,23 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- u-authorization (1.4.0)
4
+ u-authorization (2.1.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
+ ansi (1.5.0)
10
+ builder (3.2.3)
9
11
  docile (1.3.2)
10
12
  json (2.2.0)
11
13
  minitest (5.11.3)
14
+ minitest-reporters (1.3.6)
15
+ ansi
16
+ builder
17
+ minitest (>= 5.0)
18
+ ruby-progressbar
12
19
  rake (10.5.0)
20
+ ruby-progressbar (1.10.1)
13
21
  simplecov (0.17.0)
14
22
  docile (~> 1.1)
15
23
  json (>= 1.8, < 3)
@@ -21,6 +29,7 @@ PLATFORMS
21
29
 
22
30
  DEPENDENCIES
23
31
  minitest (~> 5.11, >= 5.11.3)
32
+ minitest-reporters (~> 1.3, >= 1.3.6)
24
33
  rake (~> 10.0)
25
34
  simplecov
26
35
  u-authorization!
data/README.md CHANGED
@@ -1,3 +1,8 @@
1
+ [![Gem](https://img.shields.io/gem/v/u-authorization.svg?style=flat-square)](https://rubygems.org/gems/u-authorization)
2
+ [![Build Status](https://travis-ci.com/serradura/u-authorization.svg?branch=master)](https://travis-ci.com/serradura/u-authorization)
3
+ [![Maintainability](https://api.codeclimate.com/v1/badges/19251112cf39afdf8bf6/maintainability)](https://codeclimate.com/github/serradura/u-authorization/maintainability)
4
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/19251112cf39afdf8bf6/test_coverage)](https://codeclimate.com/github/serradura/u-authorization/test_coverage)
5
+
1
6
  # µ-authorization
2
7
 
3
8
  Simple authorization library and role managment for Ruby.
@@ -27,7 +32,7 @@ $ gem install u-authorization
27
32
 
28
33
  ```ruby
29
34
  require 'ostruct'
30
- require 'authorization'
35
+ require 'u-authorization'
31
36
 
32
37
  role = OpenStruct.new(
33
38
  name: 'user',
@@ -51,10 +56,16 @@ $ gem install u-authorization
51
56
  policies: { default: :sales, sales: SalesPolicy }
52
57
  context: {
53
58
  user: user,
54
- permissions: ['dashboard', 'controllers', 'sales', 'index']
59
+ to_permit: ['dashboard', 'controllers', 'sales', 'index']
55
60
  }
56
61
  )
57
62
 
63
+ # Note: In the context, you can use :permissions key as an alias of :to_permit. e.g:
64
+ # context: {
65
+ # user: user,
66
+ # permissions: ['dashboard', 'controllers', 'sales', 'index']
67
+ # }
68
+
58
69
  # Verifying the permissions for the given context
59
70
  authorization.permissions.to?('visit') #=> true
60
71
  authorization.permissions.to?('export_as_csv') #=> false
@@ -6,8 +6,11 @@ module Micro
6
6
  attr_reader :context, :permissions
7
7
 
8
8
  def self.build(permissions:, context:, policies: {})
9
+ permissions_context =
10
+ context.delete(:to_permit) || context.delete(:permissions)
11
+
9
12
  permissions_model =
10
- Permissions.new(permissions, context: context.delete(:permissions))
13
+ Permissions.new(permissions, context: permissions_context)
11
14
 
12
15
  self.new(context, permissions: permissions_model, policies: policies)
13
16
  end
@@ -4,8 +4,8 @@ module Micro
4
4
  class Model
5
5
  attr_reader :role, :context
6
6
 
7
- def initialize(role_permissions, context:)
8
- @role = role_permissions.dup.freeze
7
+ def initialize(role, context:)
8
+ @role = role.dup.freeze
9
9
  @cache = {}
10
10
  @context = Utils.values_as_downcased_strings(context).freeze
11
11
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Micro
4
4
  module Authorization
5
- VERSION = '2.0.0'
5
+ VERSION = '2.1.0'.freeze
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: u-authorization
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rodrigo Serradura
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-07-26 00:00:00.000000000 Z
11
+ date: 2019-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -32,6 +32,7 @@ extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
34
  - ".gitignore"
35
+ - ".travis.yml"
35
36
  - Gemfile
36
37
  - Gemfile.lock
37
38
  - README.md