Class: Polidef::Policy

Inherits:
Object
  • Object
show all
Defined in:
lib/polidef/policy.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePolicy

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_policiesObject



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_attrsObject



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_tryObject



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

#policyObject

Raises:

  • (NotImplementedError)


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