Class: PickyGuard::Validator
- Inherits:
-
Object
- Object
- PickyGuard::Validator
- Defined in:
- lib/picky_guard/validator.rb
Class Method Summary collapse
- .all_valid_actions?(actions) ⇒ Boolean
- .all_valid_policy_classes?(policies) ⇒ Boolean
- .child_and_parent?(child_class, parent_class) ⇒ Boolean
- .valid_action?(action) ⇒ Boolean
- .valid_conditions?(conditions) ⇒ Boolean
- .valid_effect?(effect) ⇒ Boolean
- .valid_policy?(policy) ⇒ Boolean
- .valid_resource_class?(resource) ⇒ Boolean
- .valid_role?(role) ⇒ Boolean
- .valid_statement?(statement) ⇒ Boolean
- .validate_all_actions!(actions) ⇒ Object
- .validate_all_policy_classes!(policies) ⇒ Object
- .validate_conditions!(conditions) ⇒ Object
- .validate_effect!(effect) ⇒ Object
- .validate_resource_class!(resource) ⇒ Object
- .validate_role!(role) ⇒ Object
- .validate_statement!(statement) ⇒ Object
Class Method Details
.all_valid_actions?(actions) ⇒ Boolean
24 25 26 27 28 29 |
# File 'lib/picky_guard/validator.rb', line 24 def self.all_valid_actions?(actions) return false unless actions.is_a? Array actions.all? do |action| valid_action?(action) end end |
.all_valid_policy_classes?(policies) ⇒ Boolean
35 36 37 38 39 40 |
# File 'lib/picky_guard/validator.rb', line 35 def self.all_valid_policy_classes?(policies) return false unless policies.is_a? Array policies.all? do |policy| valid_policy?(policy) end end |
.child_and_parent?(child_class, parent_class) ⇒ Boolean
46 47 48 |
# File 'lib/picky_guard/validator.rb', line 46 def self.child_and_parent?(child_class, parent_class) child_class < parent_class end |
.valid_action?(action) ⇒ Boolean
20 21 22 |
# File 'lib/picky_guard/validator.rb', line 20 def self.valid_action?(action) action.is_a?(Symbol) || action.is_a?(String) end |
.valid_conditions?(conditions) ⇒ Boolean
42 43 44 |
# File 'lib/picky_guard/validator.rb', line 42 def self.valid_conditions?(conditions) conditions.instance_of?(Hash) || conditions.instance_of?(Proc) end |
.valid_effect?(effect) ⇒ Boolean
50 51 52 |
# File 'lib/picky_guard/validator.rb', line 50 def self.valid_effect?(effect) PickyGuard::Statement::EFFECTS.include? effect end |
.valid_policy?(policy) ⇒ Boolean
31 32 33 |
# File 'lib/picky_guard/validator.rb', line 31 def self.valid_policy?(policy) child_and_parent?(policy, PickyGuard::Policy) end |
.valid_resource_class?(resource) ⇒ Boolean
8 9 10 |
# File 'lib/picky_guard/validator.rb', line 8 def self.valid_resource_class?(resource) child_and_parent?(resource, ActiveRecord::Base) end |
.valid_role?(role) ⇒ Boolean
12 13 14 |
# File 'lib/picky_guard/validator.rb', line 12 def self.valid_role?(role) role.is_a?(Symbol) || role.is_a?(String) end |
.valid_statement?(statement) ⇒ Boolean
16 17 18 |
# File 'lib/picky_guard/validator.rb', line 16 def self.valid_statement?(statement) statement.is_a? PickyGuard::Statement end |
.validate_all_actions!(actions) ⇒ Object
64 65 66 67 |
# File 'lib/picky_guard/validator.rb', line 64 def self.validate_all_actions!(actions) raise ArgumentError, 'Invalid actions' unless Validator.all_valid_actions?(actions) actions end |
.validate_all_policy_classes!(policies) ⇒ Object
69 70 71 72 |
# File 'lib/picky_guard/validator.rb', line 69 def self.validate_all_policy_classes!(policies) raise ArgumentError, 'Invalid policies' unless Validator.all_valid_policy_classes?(policies) policies end |
.validate_conditions!(conditions) ⇒ Object
79 80 81 82 |
# File 'lib/picky_guard/validator.rb', line 79 def self.validate_conditions!(conditions) raise ArgumentError, 'Invalid conditions' unless Validator.valid_conditions?(conditions) conditions end |
.validate_effect!(effect) ⇒ Object
84 85 86 87 |
# File 'lib/picky_guard/validator.rb', line 84 def self.validate_effect!(effect) raise ArgumentError, 'Invalid effect' unless Validator.valid_effect?(effect) effect end |
.validate_resource_class!(resource) ⇒ Object
59 60 61 62 |
# File 'lib/picky_guard/validator.rb', line 59 def self.validate_resource_class!(resource) raise ArgumentError, 'Invalid Resource' unless Validator.valid_resource_class?(resource) resource end |
.validate_role!(role) ⇒ Object
74 75 76 77 |
# File 'lib/picky_guard/validator.rb', line 74 def self.validate_role!(role) raise ArgumentError, 'Invalid roles' unless Validator.valid_role?(role) role end |
.validate_statement!(statement) ⇒ Object
54 55 56 57 |
# File 'lib/picky_guard/validator.rb', line 54 def self.validate_statement!(statement) raise ArgumentError, 'Invalid Statement' unless Validator.valid_statement?(statement) statement end |