Class: Gardefou::GardeFou
- Inherits:
-
Object
- Object
- Gardefou::GardeFou
- Defined in:
- lib/gardefou/garde_fou.rb
Instance Attribute Summary collapse
-
#profile ⇒ Object
readonly
Returns the value of attribute profile.
Instance Method Summary collapse
-
#call(method, *args, **kwargs, &block) ⇒ Object
(also: #[])
Main callable interface - allows guard.call(method, *args, **kwargs).
-
#initialize(profile: nil, **profile_options) ⇒ GardeFou
constructor
A new instance of GardeFou.
-
#protect(method, *args, **kwargs, &block) ⇒ Object
Alternative syntax for those who prefer it.
Constructor Details
#initialize(profile: nil, **profile_options) ⇒ GardeFou
Returns a new instance of GardeFou.
7 8 9 |
# File 'lib/gardefou/garde_fou.rb', line 7 def initialize(profile: nil, **) @profile = profile || Profile.new(**) end |
Instance Attribute Details
#profile ⇒ Object (readonly)
Returns the value of attribute profile.
5 6 7 |
# File 'lib/gardefou/garde_fou.rb', line 5 def profile @profile end |
Instance Method Details
#call(method, *args, **kwargs, &block) ⇒ Object Also known as: []
Main callable interface - allows guard.call(method, *args, **kwargs)
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/gardefou/garde_fou.rb', line 12 def call(method, *args, **kwargs, &block) # Extract method name for tracking method_name = extract_method_name(method) # Run profile checks @profile.check(method_name, args, kwargs) # Execute the method if kwargs.empty? # Ruby 2.6 compatibility - avoid passing empty kwargs method.call(*args, &block) else method.call(*args, **kwargs, &block) end end |
#protect(method, *args, **kwargs, &block) ⇒ Object
Alternative syntax for those who prefer it
33 34 35 |
# File 'lib/gardefou/garde_fou.rb', line 33 def protect(method, *args, **kwargs, &block) call(method, *args, **kwargs, &block) end |