Module: Polidef::Policies
- Defined in:
- lib/polidef/policies.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #policy_fulfilled?(policy, dependencies:) ⇒ Boolean
- #policy_rejected?(policy, dependencies:) ⇒ Boolean
- #with_fulfilled_policy(policy, dependencies:) ⇒ Object
Class Method Details
.included(base) ⇒ Object
52 53 54 |
# File 'lib/polidef/policies.rb', line 52 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#policy_fulfilled?(policy, dependencies:) ⇒ Boolean
15 16 17 18 19 20 |
# File 'lib/polidef/policies.rb', line 15 def policy_fulfilled?(policy, dependencies:) policy_class = Object.const_get(policy.to_sym.to_s.split("_").map(&:capitalize).join("")).new policy_class._assign_attrs(dependencies) policy_class._policy_try end |
#policy_rejected?(policy, dependencies:) ⇒ Boolean
22 23 24 25 26 27 28 29 |
# File 'lib/polidef/policies.rb', line 22 def policy_rejected?(policy, dependencies:) policy_class = Object.const_get(policy.to_sym.to_s.split("_").map(&:capitalize).join("")).new policy_class._assign_attrs(dependencies) result = policy_class._policy_try !result end |
#with_fulfilled_policy(policy, dependencies:) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/polidef/policies.rb', line 5 def with_fulfilled_policy(policy, dependencies:) policy_class = Policy.inline_policies.find { |p| p[:name] == policy } policy_class ||= Object.const_get(policy.to_sym.to_s.split("_").map(&:capitalize).join("")).new policy_class._assign_attrs(dependencies) result = policy_class._policy_try yield if result end |