action_policy 0.7.2 → 0.7.4
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/CHANGELOG.md +14 -0
- data/lib/.rbnext/3.0/action_policy/policy/cache.rb +6 -6
- data/lib/.rbnext/3.0/action_policy/policy/core.rb +34 -16
- data/lib/.rbnext/3.0/action_policy/policy/pre_check.rb +0 -2
- data/lib/.rbnext/3.0/action_policy/policy/reasons.rb +4 -3
- data/lib/.rbnext/3.2/action_policy/policy/core.rb +34 -16
- data/lib/action_policy/authorizer.rb +8 -5
- data/lib/action_policy/behaviour.rb +7 -6
- data/lib/action_policy/policy/cache.rb +6 -6
- data/lib/action_policy/policy/cached_apply.rb +5 -8
- data/lib/action_policy/policy/core.rb +34 -16
- data/lib/action_policy/policy/pre_check.rb +0 -2
- data/lib/action_policy/policy/reasons.rb +4 -3
- data/lib/action_policy/rails/authorizer.rb +4 -4
- data/lib/action_policy/rails/controller.rb +4 -1
- data/lib/action_policy/rails/policy/instrumentation.rb +3 -3
- data/lib/action_policy/rspec/dsl.rb +1 -0
- data/lib/action_policy/version.rb +1 -1
- metadata +7 -14
- data/lib/.rbnext/2.7/action_policy/behaviours/policy_for.rb +0 -70
- data/lib/.rbnext/2.7/action_policy/i18n.rb +0 -56
- data/lib/.rbnext/2.7/action_policy/policy/cache.rb +0 -101
- data/lib/.rbnext/2.7/action_policy/policy/pre_check.rb +0 -162
- data/lib/.rbnext/2.7/action_policy/rspec/be_authorized_to.rb +0 -96
- data/lib/.rbnext/2.7/action_policy/rspec/have_authorized_scope.rb +0 -130
- data/lib/.rbnext/2.7/action_policy/utils/pretty_print.rb +0 -155
- /data/lib/.rbnext/{2.7 → 3.0}/action_policy/rails/scope_matchers/action_controller_params.rb +0 -0
- /data/lib/.rbnext/{2.7 → 3.0}/action_policy/rails/scope_matchers/active_record.rb +0 -0
@@ -1,155 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
old_verbose = $VERBOSE
|
4
|
-
|
5
|
-
begin
|
6
|
-
require "method_source"
|
7
|
-
# Ignore parse warnings when patch
|
8
|
-
# Ruby version mismatches
|
9
|
-
$VERBOSE = nil
|
10
|
-
require "prism"
|
11
|
-
rescue LoadError
|
12
|
-
# do nothing
|
13
|
-
ensure
|
14
|
-
$VERBOSE = old_verbose
|
15
|
-
end
|
16
|
-
|
17
|
-
module ActionPolicy
|
18
|
-
using RubyNext
|
19
|
-
|
20
|
-
# Takes the object and a method name,
|
21
|
-
# and returns the "annotated" source code for the method:
|
22
|
-
# code is split into parts by logical operators and each
|
23
|
-
# part is evaluated separately.
|
24
|
-
#
|
25
|
-
# Example:
|
26
|
-
#
|
27
|
-
# class MyClass
|
28
|
-
# def access?
|
29
|
-
# admin? && access_feed?
|
30
|
-
# end
|
31
|
-
# end
|
32
|
-
#
|
33
|
-
# puts PrettyPrint.format_method(MyClass.new, :access?)
|
34
|
-
#
|
35
|
-
# #=> MyClass#access?
|
36
|
-
# #=> ↳ admin? #=> false
|
37
|
-
# #=> AND
|
38
|
-
# #=> access_feed? #=> true
|
39
|
-
module PrettyPrint
|
40
|
-
TRUE = "\e[32mtrue\e[0m"
|
41
|
-
FALSE = "\e[31mfalse\e[0m"
|
42
|
-
|
43
|
-
class Visitor
|
44
|
-
attr_reader :lines, :object, :source
|
45
|
-
attr_accessor :indent
|
46
|
-
|
47
|
-
def initialize(object)
|
48
|
-
@object = object
|
49
|
-
end
|
50
|
-
|
51
|
-
def collect(ast)
|
52
|
-
@lines = []
|
53
|
-
@indent = 0
|
54
|
-
@source = ast.source.source
|
55
|
-
ast = ast.value.child_nodes[0].child_nodes[0].body
|
56
|
-
|
57
|
-
visit_node(ast)
|
58
|
-
|
59
|
-
lines.join("\n")
|
60
|
-
end
|
61
|
-
|
62
|
-
def visit_node(ast)
|
63
|
-
if respond_to?("visit_#{ast.type}")
|
64
|
-
send("visit_#{ast.type}", ast)
|
65
|
-
else
|
66
|
-
visit_missing ast
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
def expression_with_result(sexp)
|
71
|
-
expression = source[sexp.location.start_offset...sexp.location.end_offset]
|
72
|
-
"#{expression} #=> #{PrettyPrint.colorize(eval_exp(expression))}"
|
73
|
-
end
|
74
|
-
|
75
|
-
def eval_exp(exp)
|
76
|
-
return "<skipped>" if ignore_exp?(exp)
|
77
|
-
object.instance_eval(exp)
|
78
|
-
rescue => e
|
79
|
-
"Failed: #{e.message}"
|
80
|
-
end
|
81
|
-
|
82
|
-
def visit_and_node(ast)
|
83
|
-
visit_node(ast.left)
|
84
|
-
lines << indented("AND")
|
85
|
-
visit_node(ast.right)
|
86
|
-
end
|
87
|
-
|
88
|
-
def visit_or_node(ast)
|
89
|
-
visit_node(ast.left)
|
90
|
-
lines << indented("OR")
|
91
|
-
visit_node(ast.right)
|
92
|
-
end
|
93
|
-
|
94
|
-
def visit_statements_node(ast)
|
95
|
-
ast.child_nodes.each do |node|
|
96
|
-
visit_node(node)
|
97
|
-
# restore indent after each expression
|
98
|
-
self.indent -= 2
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
def visit_parentheses_node(ast)
|
103
|
-
lines << indented("(")
|
104
|
-
self.indent += 2
|
105
|
-
visit_node(ast.child_nodes[0])
|
106
|
-
lines << indented(")")
|
107
|
-
end
|
108
|
-
|
109
|
-
def visit_missing(ast)
|
110
|
-
lines << indented(expression_with_result(ast))
|
111
|
-
end
|
112
|
-
|
113
|
-
def indented(str)
|
114
|
-
"#{indent.zero? ? "↳ " : ""}#{" " * indent}#{str}".tap do
|
115
|
-
# increase indent after the first expression
|
116
|
-
self.indent += 2 if indent.zero?
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
# Some lines should not be evaled
|
121
|
-
def ignore_exp?(exp)
|
122
|
-
PrettyPrint.ignore_expressions.any? { |_1| exp.match?(_1) }
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
class << self
|
127
|
-
attr_accessor :ignore_expressions
|
128
|
-
|
129
|
-
if defined?(::Prism) && defined?(::MethodSource)
|
130
|
-
def available?() ; true; end
|
131
|
-
|
132
|
-
def print_method(object, method_name)
|
133
|
-
ast = Prism.parse(object.method(method_name).source)
|
134
|
-
|
135
|
-
Visitor.new(object).collect(ast)
|
136
|
-
end
|
137
|
-
else
|
138
|
-
def available?() ; false; end
|
139
|
-
|
140
|
-
def print_method(_, _) ; ""; end
|
141
|
-
end
|
142
|
-
|
143
|
-
def colorize(val)
|
144
|
-
return val unless $stdout.isatty
|
145
|
-
return TRUE if val.eql?(true) # rubocop:disable Lint/DeprecatedConstants
|
146
|
-
return FALSE if val.eql?(false) # rubocop:disable Lint/DeprecatedConstants
|
147
|
-
val
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
self.ignore_expressions = [
|
152
|
-
/^\s*binding\.(pry|irb)\s*$/s
|
153
|
-
]
|
154
|
-
end
|
155
|
-
end
|
/data/lib/.rbnext/{2.7 → 3.0}/action_policy/rails/scope_matchers/action_controller_params.rb
RENAMED
File without changes
|
File without changes
|