miau 1.1.7 → 1.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/miau/storage.rb.bak +63 -0
- data/lib/miau/version.rb +2 -1
- data/lib/miau/version.rb.bak +2 -1
- data/lib/miau.rb.bak +2 -4
- metadata +17 -3
- data/lib/miau/error.rb.bak +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d212c3d6cf76c609635ebf42d2e62229077651d0189a2ec54cb82f9a23924f9
|
4
|
+
data.tar.gz: ae723976d8a6ad3d28e5bd625a4d9884d89e2c387c71094590e64b812b3638fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c25989c839d48abc53be4a99c7e77f605cd599b48f22c5ba6eaafd170874f1cd68cd379bfd58af367c2b3f91b5132a0129ee6485c7b8fa5589777dd7b4b2c3c0
|
7
|
+
data.tar.gz: b1af02057e15ae1a36a8c58ce5c95939513bf321f24f8b7863767b9e9da803e0ff53856e0ebddc4bff8ff70261135a1336039ca1efacb510400dc06730b7bb13
|
data/README.md
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/miau.png)](http://badge.fury.io/rb/miau)
|
4
4
|
[![GEM Downloads](https://img.shields.io/gem/dt/miau?color=168AFE&logo=ruby&logoColor=FE1616)](https://rubygems.org/gems/miau)
|
5
|
+
[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](http://choosealicense.com/licenses/mit/)
|
5
6
|
|
6
7
|
Miau (MIcro AUthorization) is a simple authorization gem for Rails
|
7
8
|
inspired by Pundit and Banken.
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "singleton"
|
4
|
+
require "yaml"
|
5
|
+
|
6
|
+
module Miau
|
7
|
+
class PolicyStorage
|
8
|
+
include Singleton
|
9
|
+
|
10
|
+
# Example @policies:
|
11
|
+
# {
|
12
|
+
# posts: {
|
13
|
+
# delete: :delete,
|
14
|
+
# remove: :delete
|
15
|
+
# },
|
16
|
+
# application: {
|
17
|
+
# admin: :check
|
18
|
+
# }
|
19
|
+
# }
|
20
|
+
attr_reader :policies
|
21
|
+
attr_reader :instances # e.g. { posts: PostsPolicy.new }
|
22
|
+
|
23
|
+
def initialize
|
24
|
+
reset
|
25
|
+
end
|
26
|
+
|
27
|
+
def reset
|
28
|
+
@policies = {}
|
29
|
+
@instances = {}
|
30
|
+
end
|
31
|
+
|
32
|
+
def add_policy(kls, action, meth)
|
33
|
+
kls = kls.to_sym
|
34
|
+
action = action.to_sym
|
35
|
+
@policies[kls] ||= {}
|
36
|
+
if @policies[kls][action]
|
37
|
+
raise OverwriteError, "Can't overwrite policy(#{kls}, #{action})"
|
38
|
+
end
|
39
|
+
|
40
|
+
if meth.is_a?(Array)
|
41
|
+
meths = [meth].flatten.collect(&:to_sym)
|
42
|
+
@policies[kls][action] = meths
|
43
|
+
else
|
44
|
+
@policies[kls][action] = meth.to_sym
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def find_or_create_policy(klass)
|
49
|
+
res = @instances[klass]
|
50
|
+
return res unless res.nil?
|
51
|
+
|
52
|
+
name = "#{klass.to_s.camelcase}Policy"
|
53
|
+
return nil unless Object.const_defined?(name)
|
54
|
+
|
55
|
+
instances[klass] = name.constantize.new
|
56
|
+
end
|
57
|
+
|
58
|
+
def to_yaml
|
59
|
+
"# === @policies ===\n" + YAML.dump(@policies) +
|
60
|
+
"# === @instances ===\n" + YAML.dump(@instances)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/lib/miau/version.rb
CHANGED
data/lib/miau/version.rb.bak
CHANGED
data/lib/miau.rb.bak
CHANGED
@@ -44,11 +44,9 @@ module Miau
|
|
44
44
|
controller = params[:controller].to_sym
|
45
45
|
action = params[:action].to_sym
|
46
46
|
policy = PolicyStorage.instance.find_or_create_policy(controller)
|
47
|
-
p 22222
|
48
47
|
unless policy
|
49
|
-
|
50
|
-
|
51
|
-
# raise NotDefinedError, msg
|
48
|
+
msg = "missing class #{controller.capitalize}Policy"
|
49
|
+
raise NotDefinedError, msg
|
52
50
|
end
|
53
51
|
|
54
52
|
policy.user = miau_user
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: miau
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dittmar Krall
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-04-
|
11
|
+
date: 2024-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: listen
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: appraisal
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -82,9 +96,9 @@ files:
|
|
82
96
|
- lib/miau.rb.bak
|
83
97
|
- lib/miau/application_policy.rb
|
84
98
|
- lib/miau/error.rb
|
85
|
-
- lib/miau/error.rb.bak
|
86
99
|
- lib/miau/run.rb
|
87
100
|
- lib/miau/storage.rb
|
101
|
+
- lib/miau/storage.rb.bak
|
88
102
|
- lib/miau/version.rb
|
89
103
|
- lib/miau/version.rb.bak
|
90
104
|
homepage: https://github.com/matique/miau
|
data/lib/miau/error.rb.bak
DELETED