Class: McpAuthorization::Cache::Recorder
- Inherits:
-
Object
- Object
- McpAuthorization::Cache::Recorder
show all
- Defined in:
- lib/mcp_authorization/cache/recorder.rb
Overview
Wraps a server context during a cold compile and records every gating
decision the compiler reads — so the cache key can be rebuilt later from
just those decisions. Two contexts that answer every recorded predicate
identically (same permissions, feature flags, tiers, defaults) produce
the same key and share a cache entry; flip one feature flag and the
vector — and the key — change.
Transparently delegates everything to the wrapped context. The compiler
reaches the user via current_user, so that returns a RecorderUser to
capture can? and default_for.
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(target) ⇒ Recorder
Returns a new instance of Recorder.
44
45
46
47
48
|
# File 'lib/mcp_authorization/cache/recorder.rb', line 44
def initialize(target)
@__target = target
@consulted = []
@__user = nil
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/mcp_authorization/cache/recorder.rb', line 64
def method_missing(name, *args, &block)
result = @__target.public_send(name, *args, &block)
if name.to_s.end_with?("?") && args.size == 1
@consulted << Signature.new(:context, name.to_s, args.first)
end
result
end
|
Instance Attribute Details
#__target ⇒ Object
38
39
40
|
# File 'lib/mcp_authorization/cache/recorder.rb', line 38
def __target
@__target
end
|
#consulted ⇒ Object
41
42
43
|
# File 'lib/mcp_authorization/cache/recorder.rb', line 41
def consulted
@consulted
end
|
Instance Method Details
#current_user ⇒ Object
51
52
53
54
55
56
|
# File 'lib/mcp_authorization/cache/recorder.rb', line 51
def current_user
user = @__target.current_user
return nil unless user
@__user ||= RecorderUser.new(user, @consulted)
end
|
#respond_to_missing?(name, include_private = false) ⇒ Boolean
59
60
61
|
# File 'lib/mcp_authorization/cache/recorder.rb', line 59
def respond_to_missing?(name, include_private = false)
@__target.respond_to?(name, include_private)
end
|