Class: Polidef::Policy
- Inherits:
-
Object
- Object
- Polidef::Policy
- Defined in:
- lib/polidef/policy.rb
Class Method Summary collapse
- .add_inline_policy(policy_hash) ⇒ Object
- .inline_policies ⇒ Object
- .policy_dependencies(*args) ⇒ Object
Instance Method Summary collapse
- #_assign_attrs(dependencies) ⇒ Object
- #_generate_attrs ⇒ Object
- #_or_policy(single_policy) ⇒ Object
- #_policy_chain(policies_collection) ⇒ Object
- #_policy_try ⇒ Object
-
#initialize ⇒ Policy
constructor
A new instance of Policy.
- #or_policy(single_policy) ⇒ Object
- #policy ⇒ Object
- #policy_chain(policies_collection) ⇒ Object
Constructor Details
#initialize ⇒ Policy
Returns a new instance of Policy.
17 18 19 |
# File 'lib/polidef/policy.rb', line 17 def initialize _generate_attrs end |
Class Method Details
.add_inline_policy(policy_hash) ⇒ Object
13 14 15 |
# File 'lib/polidef/policy.rb', line 13 def self.add_inline_policy(policy_hash) inline_policies << policy_hash end |
.inline_policies ⇒ Object
9 10 11 |
# File 'lib/polidef/policy.rb', line 9 def self.inline_policies @inline_policies ||= [] end |
.policy_dependencies(*args) ⇒ Object
5 6 7 |
# File 'lib/polidef/policy.rb', line 5 def self.policy_dependencies(*args) @policy_dependencies ||= args end |
Instance Method Details
#_assign_attrs(dependencies) ⇒ Object
62 63 64 65 66 |
# File 'lib/polidef/policy.rb', line 62 def _assign_attrs(dependencies) dependencies.each do |key, value| send(:"#{key}=", value) end end |
#_generate_attrs ⇒ Object
55 56 57 58 59 60 |
# File 'lib/polidef/policy.rb', line 55 def _generate_attrs self.class.policy_dependencies.each do |dep| instance_variable_set(:"@#{dep}", nil) self.class.send(:attr_accessor, dep) end end |
#_or_policy(single_policy) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/polidef/policy.rb', line 44 def _or_policy(single_policy) return if @_policy_state @_policy_state = send(:single_policy) itself end |
#_policy_chain(policies_collection) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/polidef/policy.rb', line 33 def _policy_chain(policies_collection) @_policy_state = nil policies_collection.each do |chain_link| break unless @_policy_state @_policy_state = send(:chain_link) end itself end |
#_policy_try ⇒ Object
51 52 53 |
# File 'lib/polidef/policy.rb', line 51 def _policy_try send(:policy) end |
#or_policy(single_policy) ⇒ Object
29 30 31 |
# File 'lib/polidef/policy.rb', line 29 def or_policy(single_policy) _or_policy(single_policy) end |
#policy ⇒ Object
21 22 23 |
# File 'lib/polidef/policy.rb', line 21 def policy raise NotImplementedError end |
#policy_chain(policies_collection) ⇒ Object
25 26 27 |
# File 'lib/polidef/policy.rb', line 25 def policy_chain(policies_collection) _policy_chain(policies_collection) end |