Class: Ronflex::Rule
- Inherits:
-
Object
- Object
- Ronflex::Rule
- Defined in:
- lib/ronflex/rule.rb
Overview
Class Rule
Represents a rule that associates a specific type (e.g., ‘:admin`, `:guest`) with a custom condition defined by a block of logic. The rule can then evaluate whether a model matches the type and satisfies the condition for a particular request.
Instance Attribute Summary collapse
-
#rule ⇒ Proc
readonly
The block of logic that determines if the rule matches a given model and request.
-
#type ⇒ Symbol, String
readonly
The type of the model this rule applies to (e.g., ‘:admin` or `:guest`).
Instance Method Summary collapse
-
#initialize(type) {|model, request| ... } ⇒ Rule
constructor
Initializes a new rule.
-
#matches?(model, request) ⇒ Boolean
Checks if the rule matches a given model and request.
Constructor Details
#initialize(type) {|model, request| ... } ⇒ Rule
Initializes a new rule.
29 30 31 32 |
# File 'lib/ronflex/rule.rb', line 29 def initialize(type, &block) @type = type @rule = block end |
Instance Attribute Details
#rule ⇒ Proc (readonly)
Returns the block of logic that determines if the rule matches a given model and request.
19 20 21 |
# File 'lib/ronflex/rule.rb', line 19 def rule @rule end |
#type ⇒ Symbol, String (readonly)
Returns the type of the model this rule applies to (e.g., ‘:admin` or `:guest`).
16 17 18 |
# File 'lib/ronflex/rule.rb', line 16 def type @type end |
Instance Method Details
#matches?(model, request) ⇒ Boolean
Checks if the rule matches a given model and request.
This method evaluates whether the provided model matches the rule’s type and if the rule’s block returns ‘true` for the given model and request.
42 43 44 |
# File 'lib/ronflex/rule.rb', line 42 def matches?(model, request) rule.call(model, request) end |