module RailsRbs::Models::FollowsScope
This model concern adds convenience methods to active record objects that utilize rule_sets and rules. This concern is included in the ActiveRecord::Base object.
Public Instance Methods
Apply the provided rule_set to the current model instance. The rule_set will only be applied if the the instance follows all the rules in associated with the set. @param rule_set [RuleSet] The rule_set to check and apply the instance to
# File lib/rails_rbs/models/follows_scope.rb, line 30 def apply_rule_set(rule_set) rule_set.apply_rule_set(self) end
Query the active record class for objects that follow the rule(s) or set(s) provided. @param rules_or_sets [Array<Rule> | Array<RuleSet> | Rule | Set] The rule(s) or rule_set(s) to query objects with. @return Array<ActiveRecord::Object> Collection of active record objects that follow the rule(s) or set(s)
# File lib/rails_rbs/models/follows_scope.rb, line 41 def following(*rules_or_sets) rules_or_sets.reduce(self) { |followers, rule_or_set| rule_or_set.filter_objects(followers) } end
Check if a model instance follows a rule or rule_set. When using a rule_set the model must pass every rule in the set. @param rule_or_set [Rule | RuleSet] The rule or rule_set to check this instance follows. @return true if this model instance follows the provided rule or all rules in the provided rule_set
# File lib/rails_rbs/models/follows_scope.rb, line 19 def follows?(rule_or_set) if rule_or_set.is_a?(RuleSet) rule_or_set.follows_rule_set?(self) else rule_or_set.follows_rule?(self) end end