miau 0.1.2 → 1.0.1
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 +4 -4
- data/.github/workflows/rake.yml +2 -6
- data/.gitignore +2 -0
- data/.ruby-gemset +1 -1
- data/.ruby-version +1 -1
- data/Gemfile.lock +40 -66
- data/LICENSE +2 -2
- data/README.md +49 -28
- data/lib/miau/application_policy.rb +11 -0
- data/lib/miau/storage.rb +73 -16
- data/lib/miau/version.rb +3 -1
- data/lib/miau.rb +2 -2
- data/miau.gemspec +2 -7
- metadata +6 -62
- data/.watchr +0 -59
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d8a96cf2921c9a1b4e82104205f3a8f583d28fb27424aabc6a689c67f1cf5456
|
|
4
|
+
data.tar.gz: 0a176ee2311f8a8ebc13279e9ccb31209a3c0fce62e5db9e5a64a2305afad199
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f23488dbe4e46ffe75d4626dcf9d36d6d89f5b29218ed95e75aab005b7c9441764a303643c4a88da70ea5a3cbfd2206bcf53fadedca68676f4315716c788a6a8
|
|
7
|
+
data.tar.gz: 9d40fd3e56874a5419f757f7f6cda20d4c3f5785c6b87318b5dec8482430faaa80f67dcb900234418cf9a7691e999a79a37ba368f522fdc6c90a7a749590deea
|
data/.github/workflows/rake.yml
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
# see also https://github.com/whitequark/parser/blob/master/.github/workflows/test.yml
|
|
2
2
|
name: Rake
|
|
3
3
|
|
|
4
|
-
#on: [push, pull_request]
|
|
5
4
|
on: [push]
|
|
6
5
|
|
|
7
6
|
jobs:
|
|
@@ -9,16 +8,13 @@ jobs:
|
|
|
9
8
|
strategy:
|
|
10
9
|
fail-fast: false
|
|
11
10
|
matrix:
|
|
12
|
-
# os: [ubuntu-latest, macos-latest]
|
|
13
11
|
os: [ubuntu-latest]
|
|
14
|
-
|
|
15
|
-
# ruby: [2.5, 2.6, 2.7, '3.0', head, jruby, jruby-head, truffleruby, truffleruby-head]
|
|
16
|
-
ruby: ["2.7.2", "2.7.3", "3.0.2"]
|
|
12
|
+
ruby: ["2.7", "3.0", "3.2", head]
|
|
17
13
|
test_command: ["bundle exec rake test"]
|
|
18
14
|
runs-on: ${{ matrix.os }}
|
|
19
15
|
|
|
20
16
|
steps:
|
|
21
|
-
- uses: actions/checkout@
|
|
17
|
+
- uses: actions/checkout@v3
|
|
22
18
|
- uses: ruby/setup-ruby@v1
|
|
23
19
|
with:
|
|
24
20
|
ruby-version: ${{ matrix.ruby }}
|
data/.gitignore
CHANGED
data/.ruby-gemset
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
rails-
|
|
1
|
+
rails-7.0
|
data/.ruby-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
ruby-3.
|
|
1
|
+
ruby-3.2.2
|
data/Gemfile.lock
CHANGED
|
@@ -1,105 +1,79 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
miau (0.1
|
|
4
|
+
miau (1.0.1)
|
|
5
5
|
activesupport
|
|
6
6
|
|
|
7
7
|
GEM
|
|
8
8
|
remote: https://rubygems.org/
|
|
9
9
|
specs:
|
|
10
|
-
|
|
11
|
-
actionview (= 6.1.4.1)
|
|
12
|
-
activesupport (= 6.1.4.1)
|
|
13
|
-
rack (~> 2.0, >= 2.0.9)
|
|
14
|
-
rack-test (>= 0.6.3)
|
|
15
|
-
rails-dom-testing (~> 2.0)
|
|
16
|
-
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
|
17
|
-
actionview (6.1.4.1)
|
|
18
|
-
activesupport (= 6.1.4.1)
|
|
19
|
-
builder (~> 3.1)
|
|
20
|
-
erubi (~> 1.4)
|
|
21
|
-
rails-dom-testing (~> 2.0)
|
|
22
|
-
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
|
23
|
-
activemodel (6.1.4.1)
|
|
24
|
-
activesupport (= 6.1.4.1)
|
|
25
|
-
activesupport (6.1.4.1)
|
|
10
|
+
activesupport (7.0.4.3)
|
|
26
11
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
27
12
|
i18n (>= 1.6, < 2)
|
|
28
13
|
minitest (>= 5.1)
|
|
29
14
|
tzinfo (~> 2.0)
|
|
30
|
-
zeitwerk (~> 2.3)
|
|
31
15
|
ast (2.4.2)
|
|
32
|
-
benchmark-ips (2.
|
|
33
|
-
|
|
34
|
-
concurrent-ruby (1.1.9)
|
|
35
|
-
crass (1.0.6)
|
|
16
|
+
benchmark-ips (2.12.0)
|
|
17
|
+
concurrent-ruby (1.2.2)
|
|
36
18
|
docile (1.4.0)
|
|
37
|
-
|
|
38
|
-
i18n (1.8.11)
|
|
19
|
+
i18n (1.12.0)
|
|
39
20
|
concurrent-ruby (~> 1.0)
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
minitest (5.
|
|
44
|
-
nokogiri (1.12.5-x86_64-linux)
|
|
45
|
-
racc (~> 1.4)
|
|
21
|
+
json (2.6.3)
|
|
22
|
+
language_server-protocol (3.17.0.3)
|
|
23
|
+
lint_roller (1.0.0)
|
|
24
|
+
minitest (5.18.0)
|
|
46
25
|
observr (1.0.5)
|
|
47
|
-
parallel (1.
|
|
48
|
-
parser (3.
|
|
26
|
+
parallel (1.23.0)
|
|
27
|
+
parser (3.2.2.0)
|
|
49
28
|
ast (~> 2.4.1)
|
|
50
|
-
|
|
51
|
-
rack (2.2.3)
|
|
52
|
-
rack-test (1.1.0)
|
|
53
|
-
rack (>= 1.0, < 3)
|
|
54
|
-
rails-dom-testing (2.0.3)
|
|
55
|
-
activesupport (>= 4.2.0)
|
|
56
|
-
nokogiri (>= 1.6)
|
|
57
|
-
rails-html-sanitizer (1.4.2)
|
|
58
|
-
loofah (~> 2.3)
|
|
59
|
-
rainbow (3.0.0)
|
|
29
|
+
rainbow (3.1.1)
|
|
60
30
|
rake (13.0.6)
|
|
61
|
-
regexp_parser (2.
|
|
31
|
+
regexp_parser (2.8.0)
|
|
62
32
|
rexml (3.2.5)
|
|
63
|
-
ricecream (0.2.
|
|
64
|
-
rubocop (1.
|
|
33
|
+
ricecream (0.2.1)
|
|
34
|
+
rubocop (1.50.2)
|
|
35
|
+
json (~> 2.3)
|
|
65
36
|
parallel (~> 1.10)
|
|
66
|
-
parser (>= 3.
|
|
37
|
+
parser (>= 3.2.0.0)
|
|
67
38
|
rainbow (>= 2.2.2, < 4.0)
|
|
68
39
|
regexp_parser (>= 1.8, < 3.0)
|
|
69
|
-
rexml
|
|
70
|
-
rubocop-ast (>= 1.
|
|
40
|
+
rexml (>= 3.2.5, < 4.0)
|
|
41
|
+
rubocop-ast (>= 1.28.0, < 2.0)
|
|
71
42
|
ruby-progressbar (~> 1.7)
|
|
72
|
-
unicode-display_width (>=
|
|
73
|
-
rubocop-ast (1.
|
|
74
|
-
parser (>= 3.
|
|
75
|
-
rubocop-performance (1.
|
|
43
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
|
44
|
+
rubocop-ast (1.28.0)
|
|
45
|
+
parser (>= 3.2.1.0)
|
|
46
|
+
rubocop-performance (1.16.0)
|
|
76
47
|
rubocop (>= 1.7.0, < 2.0)
|
|
77
48
|
rubocop-ast (>= 0.4.0)
|
|
78
|
-
ruby-progressbar (1.
|
|
79
|
-
simplecov (0.
|
|
49
|
+
ruby-progressbar (1.13.0)
|
|
50
|
+
simplecov (0.22.0)
|
|
80
51
|
docile (~> 1.1)
|
|
81
52
|
simplecov-html (~> 0.11)
|
|
82
53
|
simplecov_json_formatter (~> 0.1)
|
|
83
54
|
simplecov-html (0.12.3)
|
|
84
|
-
simplecov_json_formatter (0.1.
|
|
85
|
-
standard (1.
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
55
|
+
simplecov_json_formatter (0.1.4)
|
|
56
|
+
standard (1.28.0)
|
|
57
|
+
language_server-protocol (~> 3.17.0.2)
|
|
58
|
+
lint_roller (~> 1.0)
|
|
59
|
+
rubocop (~> 1.50.2)
|
|
60
|
+
standard-custom (~> 1.0.0)
|
|
61
|
+
standard-performance (~> 1.0.1)
|
|
62
|
+
standard-custom (1.0.0)
|
|
63
|
+
lint_roller (~> 1.0)
|
|
64
|
+
standard-performance (1.0.1)
|
|
65
|
+
lint_roller (~> 1.0)
|
|
66
|
+
rubocop-performance (~> 1.16.0)
|
|
67
|
+
tzinfo (2.0.6)
|
|
89
68
|
concurrent-ruby (~> 1.0)
|
|
90
|
-
unicode-display_width (2.
|
|
91
|
-
zeitwerk (2.5.1)
|
|
69
|
+
unicode-display_width (2.4.2)
|
|
92
70
|
|
|
93
71
|
PLATFORMS
|
|
94
72
|
x86_64-linux
|
|
95
73
|
|
|
96
74
|
DEPENDENCIES
|
|
97
|
-
actionpack
|
|
98
|
-
activemodel
|
|
99
75
|
benchmark-ips
|
|
100
|
-
bundler
|
|
101
76
|
miau!
|
|
102
|
-
minitest
|
|
103
77
|
observr
|
|
104
78
|
rake
|
|
105
79
|
ricecream
|
|
@@ -107,4 +81,4 @@ DEPENDENCIES
|
|
|
107
81
|
standard
|
|
108
82
|
|
|
109
83
|
BUNDLED WITH
|
|
110
|
-
2.
|
|
84
|
+
2.4.10
|
data/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
MIT License
|
|
1
|
+
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2021 Dittmar Krall
|
|
3
|
+
Copyright (c) 2021-2023 Dittmar Krall (www.matiq.com)
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
data/README.md
CHANGED
|
@@ -2,34 +2,32 @@ Miau
|
|
|
2
2
|
====
|
|
3
3
|
[](http://badge.fury.io/rb/miau)
|
|
4
4
|
|
|
5
|
-
Miau (MIcro AUthorization) is a simple authorization
|
|
5
|
+
Miau (MIcro AUthorization) is a simple authorization gem for Rails
|
|
6
6
|
inspired by Pundit and Banken.
|
|
7
7
|
Miau provides a set of helpers which restricts what resources
|
|
8
8
|
a given user is allowed to access.
|
|
9
9
|
|
|
10
|
-
Installation
|
|
11
|
-
------------
|
|
10
|
+
## Installation
|
|
12
11
|
|
|
13
|
-
|
|
12
|
+
As usual:
|
|
13
|
+
```ruby
|
|
14
14
|
# Gemfile
|
|
15
15
|
gem "miau"
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
```
|
|
18
17
|
and run "bundle install".
|
|
19
18
|
|
|
20
|
-
Usage (as intended)
|
|
21
|
-
-------------------
|
|
19
|
+
## Usage (as intended)
|
|
22
20
|
|
|
23
|
-
|
|
21
|
+
```ruby
|
|
24
22
|
# app/models/application_controller.rb
|
|
25
23
|
class ApplicationController < ActionController::Base
|
|
26
24
|
...
|
|
27
25
|
include Miau
|
|
28
26
|
...
|
|
29
27
|
end
|
|
30
|
-
|
|
28
|
+
```
|
|
31
29
|
|
|
32
|
-
|
|
30
|
+
```ruby
|
|
33
31
|
# app/controllers/posts_controller.rb # app/views/posts/update.rb
|
|
34
32
|
class PostsController < ApplicationController <% if authorized? %>
|
|
35
33
|
... ...
|
|
@@ -40,9 +38,9 @@ end
|
|
|
40
38
|
end
|
|
41
39
|
...
|
|
42
40
|
end
|
|
43
|
-
|
|
41
|
+
```
|
|
44
42
|
|
|
45
|
-
|
|
43
|
+
```ruby
|
|
46
44
|
# app/policies/application_policy.rb # app/policies/posts_policy.rb
|
|
47
45
|
class ApplicationPolicy class PostsPolicy < ApplicationPolicy
|
|
48
46
|
attr_reader :user, :resource ...
|
|
@@ -51,19 +49,15 @@ end
|
|
|
51
49
|
@user = user end
|
|
52
50
|
@resource = resource ...
|
|
53
51
|
end end
|
|
54
|
-
...
|
|
55
|
-
def update
|
|
56
|
-
false
|
|
57
|
-
end
|
|
58
|
-
...
|
|
59
52
|
end
|
|
60
|
-
|
|
53
|
+
```
|
|
61
54
|
|
|
62
55
|
"authorize!" will raise an exception (which can be handled by "rescue")
|
|
63
56
|
in case a policy returns "false" or isn't available.
|
|
64
57
|
|
|
65
58
|
"authorized?" will return the value of the policy.
|
|
66
59
|
|
|
60
|
+
"app/policies/application_policy.rb" is included in the gem.
|
|
67
61
|
|
|
68
62
|
Internals
|
|
69
63
|
---------
|
|
@@ -75,16 +69,16 @@ The policy method has access to the "user" and the "resource".
|
|
|
75
69
|
|
|
76
70
|
"user" is set by the default method "miau_user" (can be overwritten) as:
|
|
77
71
|
|
|
78
|
-
|
|
72
|
+
```ruby
|
|
79
73
|
# app/models/application_controller.rb
|
|
80
74
|
...
|
|
81
75
|
def miau_user
|
|
82
76
|
current_user
|
|
83
77
|
end
|
|
84
78
|
...
|
|
85
|
-
|
|
79
|
+
```
|
|
86
80
|
|
|
87
|
-
The default value for "policy" is inferred from "params[:controller]"
|
|
81
|
+
The default value for "policy" is inferred from "params[:controller]",
|
|
88
82
|
i.e. "authorize!" called from "PostsController" will
|
|
89
83
|
set the "policy" to "PostsPolicy".
|
|
90
84
|
|
|
@@ -94,14 +88,14 @@ The default value for "action" is set by "params[:action]".
|
|
|
94
88
|
|
|
95
89
|
A full blown sample :
|
|
96
90
|
|
|
97
|
-
|
|
98
|
-
authorize! article, policy: :
|
|
99
|
-
|
|
91
|
+
```ruby
|
|
92
|
+
authorize! article, policy: :posts, action: :show
|
|
93
|
+
```
|
|
100
94
|
|
|
101
95
|
Usage (more elaborated)
|
|
102
96
|
-----------------------
|
|
103
97
|
|
|
104
|
-
|
|
98
|
+
```ruby
|
|
105
99
|
# app/models/application_controller.rb
|
|
106
100
|
class ApplicationController
|
|
107
101
|
...
|
|
@@ -125,19 +119,46 @@ class ApplicationController
|
|
|
125
119
|
|
|
126
120
|
...
|
|
127
121
|
end
|
|
128
|
-
|
|
122
|
+
```
|
|
129
123
|
|
|
130
124
|
Policies remain as before.
|
|
131
125
|
Rescue's may be inserted previously in the exception chain.
|
|
132
126
|
|
|
133
127
|
"verify_authorized" checks that an "authorize!" has been called.
|
|
134
128
|
|
|
129
|
+
DRYing
|
|
130
|
+
------
|
|
131
|
+
|
|
132
|
+
```ruby
|
|
133
|
+
# app/policies/posts_policy.rb --> # app/policies/posts_policy.rb
|
|
134
|
+
class PostsPolicy < ApplicationPolicy class PostsPolicy < ApplicationPolicy
|
|
135
|
+
def new miau %i[create edit], :new
|
|
136
|
+
user.admin? && Time.now.monday?
|
|
137
|
+
end def new
|
|
138
|
+
user.admin? && Time.now.monday?
|
|
139
|
+
def create end
|
|
140
|
+
user.admin? && Time.now.monday? ...
|
|
141
|
+
end end
|
|
142
|
+
|
|
143
|
+
def edit
|
|
144
|
+
user.admin? && Time.now.monday?
|
|
145
|
+
end
|
|
146
|
+
...
|
|
147
|
+
end
|
|
148
|
+
```
|
|
135
149
|
|
|
136
150
|
PORO
|
|
137
151
|
----
|
|
138
|
-
Miau is a
|
|
152
|
+
Miau is a small gem, it just provides a few helpers.
|
|
139
153
|
All of the policy classes are just plain Ruby classes,
|
|
140
154
|
allowing DRY, encapsulation, aliasing and inheritance.
|
|
141
155
|
|
|
142
156
|
There is no magic behind the scenes.
|
|
143
157
|
Just the embedding in Rails required some specific knowledge.
|
|
158
|
+
|
|
159
|
+
## Miscellaneous
|
|
160
|
+
|
|
161
|
+
Copyright (c) 2021-2023 Dittmar Krall (www.matiq.com),
|
|
162
|
+
released under the MIT license:
|
|
163
|
+
|
|
164
|
+
* https://opensource.org/licenses/MIT
|
data/lib/miau/storage.rb
CHANGED
|
@@ -6,37 +6,94 @@ module Miau
|
|
|
6
6
|
class PolicyStorage
|
|
7
7
|
include Singleton
|
|
8
8
|
|
|
9
|
+
# Example @policies:
|
|
10
|
+
# {
|
|
11
|
+
# posts: {
|
|
12
|
+
# delete: :delete,
|
|
13
|
+
# remove: :delete
|
|
14
|
+
# },
|
|
15
|
+
# application: {
|
|
16
|
+
# admin: :check
|
|
17
|
+
# }
|
|
18
|
+
# }
|
|
9
19
|
attr_reader :policies
|
|
20
|
+
attr_reader :instances # { posts: PostsPolicy.new }
|
|
10
21
|
|
|
11
22
|
def initialize
|
|
23
|
+
reset
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def reset
|
|
12
27
|
@policies = {}
|
|
28
|
+
@instances = {}
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def add(klass, action, meth)
|
|
32
|
+
kls = klass.name.underscore[0..-8] # remove "_policy"
|
|
33
|
+
kls = kls.to_sym
|
|
34
|
+
@policies[kls] ||= {}
|
|
35
|
+
@instances[kls] ||= klass.new
|
|
36
|
+
@policies[kls][action.to_sym] = meth.to_sym
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# return instance of policy (may be nil) and the method
|
|
40
|
+
# klass and action are symbols
|
|
41
|
+
# Priority:
|
|
42
|
+
# - method of <klass>Policy
|
|
43
|
+
# - method of <klass>Policy specified by "miau action, method"
|
|
44
|
+
# - method of ApplicationPolicy (independent of klass)
|
|
45
|
+
# - method of ApplicationPolicy specified by "miau action, method"
|
|
46
|
+
# - nil
|
|
47
|
+
|
|
48
|
+
# returns policy: [instance, method]
|
|
49
|
+
def find_policy(klass, action)
|
|
50
|
+
kls = instance_of(klass)
|
|
51
|
+
act = policy_method(klass, action)
|
|
52
|
+
return [kls, act] if kls.respond_to?(act)
|
|
53
|
+
|
|
54
|
+
klass = :application
|
|
55
|
+
kls = instance_of(klass)
|
|
56
|
+
act = policy_method(klass, action)
|
|
57
|
+
return [kls, act] if kls.respond_to?(act)
|
|
58
|
+
|
|
59
|
+
# return nil
|
|
13
60
|
end
|
|
14
61
|
|
|
15
62
|
def run(klass, action, user, resource)
|
|
16
|
-
|
|
17
|
-
|
|
63
|
+
arr = find_policy(klass, action)
|
|
64
|
+
unless arr
|
|
65
|
+
msg = "class <#{klass}> action <#{action}>"
|
|
66
|
+
raise Miau::NotDefinedError, msg
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
policy, meth = arr
|
|
70
|
+
policy.user = user
|
|
71
|
+
policy.resource = resource
|
|
72
|
+
policy.send(meth)
|
|
73
|
+
end
|
|
18
74
|
|
|
19
|
-
|
|
20
|
-
|
|
75
|
+
def to_yaml
|
|
76
|
+
"# === @policies ===\n" + YAML.dump(@policies) +
|
|
77
|
+
"# === @instances ===\n" + YAML.dump(@instances)
|
|
21
78
|
end
|
|
22
79
|
|
|
23
80
|
private
|
|
24
81
|
|
|
25
|
-
def
|
|
26
|
-
|
|
27
|
-
if
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
end
|
|
82
|
+
def instance_of(klass)
|
|
83
|
+
res = @instances[klass]
|
|
84
|
+
return res if res
|
|
85
|
+
|
|
86
|
+
name = "#{klass.to_s.camelcase}Policy"
|
|
87
|
+
return nil unless Object.const_defined?(name)
|
|
32
88
|
|
|
33
|
-
|
|
89
|
+
@instances[klass] = name.constantize.new
|
|
34
90
|
end
|
|
35
91
|
|
|
36
|
-
def
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
92
|
+
def policy_method(klass, action)
|
|
93
|
+
act = @policies[klass]
|
|
94
|
+
return action unless act
|
|
95
|
+
|
|
96
|
+
act[action] || action
|
|
40
97
|
end
|
|
41
98
|
end
|
|
42
99
|
end
|
data/lib/miau/version.rb
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Miau
|
|
4
|
-
VERSION = "0.1
|
|
4
|
+
VERSION = "1.0.1" # 2023-04-24
|
|
5
|
+
# VERSION = "1.0.0" # 2022-01-23
|
|
6
|
+
# VERSION = "0.1.2" # 2021-12-10
|
|
5
7
|
# VERSION = "0.1.1" # 2021-11-06
|
|
6
8
|
# VERSION = "0.1.0" # 2021-09-13
|
|
7
9
|
# VERSION = "0.0.2" # 2021-09-11
|
data/lib/miau.rb
CHANGED
|
@@ -4,6 +4,7 @@ require "active_support/concern"
|
|
|
4
4
|
require "miau/version"
|
|
5
5
|
require "miau/error"
|
|
6
6
|
require "miau/storage"
|
|
7
|
+
require "miau/application_policy"
|
|
7
8
|
|
|
8
9
|
module Miau
|
|
9
10
|
extend ActiveSupport::Concern
|
|
@@ -49,10 +50,9 @@ module Miau
|
|
|
49
50
|
|
|
50
51
|
def klass_action(hsh)
|
|
51
52
|
klass = hsh[:class]
|
|
52
|
-
klass ||= params[:controller]
|
|
53
|
+
klass ||= params[:controller]
|
|
53
54
|
action = hsh[:action]
|
|
54
55
|
action ||= params[:action]
|
|
55
|
-
|
|
56
56
|
[klass, action]
|
|
57
57
|
end
|
|
58
58
|
end
|
data/miau.gemspec
CHANGED
|
@@ -17,18 +17,13 @@ Gem::Specification.new do |s|
|
|
|
17
17
|
s.require_paths = ["lib"]
|
|
18
18
|
|
|
19
19
|
s.authors = ["Dittmar Krall"]
|
|
20
|
-
s.email = "dittmar.krall@
|
|
21
|
-
s.homepage = "https://
|
|
20
|
+
s.email = "dittmar.krall@matiq.com"
|
|
21
|
+
s.homepage = "https://matiq.com"
|
|
22
22
|
|
|
23
23
|
s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|features)/}) }
|
|
24
24
|
|
|
25
25
|
s.add_runtime_dependency "activesupport"
|
|
26
|
-
|
|
27
|
-
s.add_development_dependency "activemodel"
|
|
28
|
-
s.add_development_dependency "actionpack"
|
|
29
|
-
s.add_development_dependency "bundler"
|
|
30
26
|
s.add_development_dependency "rake"
|
|
31
27
|
|
|
32
|
-
s.add_development_dependency "minitest"
|
|
33
28
|
s.add_development_dependency "ricecream"
|
|
34
29
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: miau
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1
|
|
4
|
+
version: 1.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Dittmar Krall
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2023-04-24 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|
|
@@ -24,48 +24,6 @@ dependencies:
|
|
|
24
24
|
- - ">="
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
26
|
version: '0'
|
|
27
|
-
- !ruby/object:Gem::Dependency
|
|
28
|
-
name: activemodel
|
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
|
30
|
-
requirements:
|
|
31
|
-
- - ">="
|
|
32
|
-
- !ruby/object:Gem::Version
|
|
33
|
-
version: '0'
|
|
34
|
-
type: :development
|
|
35
|
-
prerelease: false
|
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
-
requirements:
|
|
38
|
-
- - ">="
|
|
39
|
-
- !ruby/object:Gem::Version
|
|
40
|
-
version: '0'
|
|
41
|
-
- !ruby/object:Gem::Dependency
|
|
42
|
-
name: actionpack
|
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
|
44
|
-
requirements:
|
|
45
|
-
- - ">="
|
|
46
|
-
- !ruby/object:Gem::Version
|
|
47
|
-
version: '0'
|
|
48
|
-
type: :development
|
|
49
|
-
prerelease: false
|
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
-
requirements:
|
|
52
|
-
- - ">="
|
|
53
|
-
- !ruby/object:Gem::Version
|
|
54
|
-
version: '0'
|
|
55
|
-
- !ruby/object:Gem::Dependency
|
|
56
|
-
name: bundler
|
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
|
58
|
-
requirements:
|
|
59
|
-
- - ">="
|
|
60
|
-
- !ruby/object:Gem::Version
|
|
61
|
-
version: '0'
|
|
62
|
-
type: :development
|
|
63
|
-
prerelease: false
|
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
-
requirements:
|
|
66
|
-
- - ">="
|
|
67
|
-
- !ruby/object:Gem::Version
|
|
68
|
-
version: '0'
|
|
69
27
|
- !ruby/object:Gem::Dependency
|
|
70
28
|
name: rake
|
|
71
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -80,20 +38,6 @@ dependencies:
|
|
|
80
38
|
- - ">="
|
|
81
39
|
- !ruby/object:Gem::Version
|
|
82
40
|
version: '0'
|
|
83
|
-
- !ruby/object:Gem::Dependency
|
|
84
|
-
name: minitest
|
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
|
86
|
-
requirements:
|
|
87
|
-
- - ">="
|
|
88
|
-
- !ruby/object:Gem::Version
|
|
89
|
-
version: '0'
|
|
90
|
-
type: :development
|
|
91
|
-
prerelease: false
|
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
-
requirements:
|
|
94
|
-
- - ">="
|
|
95
|
-
- !ruby/object:Gem::Version
|
|
96
|
-
version: '0'
|
|
97
41
|
- !ruby/object:Gem::Dependency
|
|
98
42
|
name: ricecream
|
|
99
43
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -111,7 +55,7 @@ dependencies:
|
|
|
111
55
|
description: |
|
|
112
56
|
MIAU (MIcro AUthorization) provides a set of helpers which restricts what
|
|
113
57
|
resources a given user is allowed to access.
|
|
114
|
-
email: dittmar.krall@
|
|
58
|
+
email: dittmar.krall@matiq.com
|
|
115
59
|
executables: []
|
|
116
60
|
extensions: []
|
|
117
61
|
extra_rdoc_files: []
|
|
@@ -120,18 +64,18 @@ files:
|
|
|
120
64
|
- ".gitignore"
|
|
121
65
|
- ".ruby-gemset"
|
|
122
66
|
- ".ruby-version"
|
|
123
|
-
- ".watchr"
|
|
124
67
|
- Gemfile
|
|
125
68
|
- Gemfile.lock
|
|
126
69
|
- LICENSE
|
|
127
70
|
- README.md
|
|
128
71
|
- Rakefile
|
|
129
72
|
- lib/miau.rb
|
|
73
|
+
- lib/miau/application_policy.rb
|
|
130
74
|
- lib/miau/error.rb
|
|
131
75
|
- lib/miau/storage.rb
|
|
132
76
|
- lib/miau/version.rb
|
|
133
77
|
- miau.gemspec
|
|
134
|
-
homepage: https://
|
|
78
|
+
homepage: https://matiq.com
|
|
135
79
|
licenses:
|
|
136
80
|
- MIT
|
|
137
81
|
metadata:
|
|
@@ -151,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
151
95
|
- !ruby/object:Gem::Version
|
|
152
96
|
version: '0'
|
|
153
97
|
requirements: []
|
|
154
|
-
rubygems_version: 3.
|
|
98
|
+
rubygems_version: 3.4.10
|
|
155
99
|
signing_key:
|
|
156
100
|
specification_version: 4
|
|
157
101
|
summary: Simple and lightweight authorization solution for Rails.
|
data/.watchr
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
TESTING = %w[test]
|
|
2
|
-
HH = "#" * 22 unless defined?(HH)
|
|
3
|
-
H = "#" * 5 unless defined?(H)
|
|
4
|
-
|
|
5
|
-
def usage
|
|
6
|
-
puts <<-EOS
|
|
7
|
-
Ctrl-\\ or ctrl-4 Running all tests
|
|
8
|
-
Ctrl-C Exit
|
|
9
|
-
EOS
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def run(cmd)
|
|
13
|
-
puts "#{HH} #{Time.now} #{HH}"
|
|
14
|
-
puts "#{H} #{cmd}"
|
|
15
|
-
system "/usr/bin/time --format '#{HH} Elapsed time %E' #{cmd}"
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def run_it(type, file)
|
|
19
|
-
case type
|
|
20
|
-
when "test" then run %(bundle exec ruby -I test #{file})
|
|
21
|
-
# when 'spec'; run %(rspec -X #{file})
|
|
22
|
-
else; puts "#{H} unknown type: #{type}, file: #{file}"
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def run_all_tests
|
|
27
|
-
puts "\n#{HH} Running all tests #{HH}\n"
|
|
28
|
-
TESTING.each { |dir| run "bundle exec rake #{dir}" if File.exist?(dir) }
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def run_matching_files(base)
|
|
32
|
-
base = base.split("_").first
|
|
33
|
-
TESTING.each { |type|
|
|
34
|
-
files = Dir["#{type}/**/*.rb"].select { |file| file =~ /#{base}_.*\.rb/ }
|
|
35
|
-
run_it type, files.join(" ") unless files.empty?
|
|
36
|
-
}
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
TESTING.each { |type|
|
|
40
|
-
watch("#{type}/#{type}_helper\.rb") { run_all_tests }
|
|
41
|
-
watch("lib/.*\.rb") { run_all_tests }
|
|
42
|
-
watch("#{type}/.*/*_#{type}\.rb") { |match| run_it type, match[0] }
|
|
43
|
-
watch("#{type}/data/(.*)\.rb") { |match|
|
|
44
|
-
m1 = match[1]
|
|
45
|
-
run_matching_files("#{type}/#{m1}/#{m1}_#{type}.rb")
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
%w[rb erb haml slim].each { |type|
|
|
50
|
-
watch(".*/(.*)\.#{type}") { |match|
|
|
51
|
-
run_matching_files(match[1])
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
# Ctrl-\ or ctrl-4
|
|
56
|
-
Signal.trap("QUIT") { run_all_tests }
|
|
57
|
-
# Ctrl-C
|
|
58
|
-
Signal.trap("INT") { abort("Interrupted\n") }
|
|
59
|
-
usage
|