Class: Collective::Policy::Instance

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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Instance

including options will merge over these options



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/collective/policy.rb', line 25

def initialize( options = {} )
  if options[:policy] then
    policy   = options.delete(:policy)
    defaults = policy.dup
  else
    defaults = DEFAULTS
  end

  options  = Hash[ options.map { |k,v| [ k.to_sym, v ] } ] # poor man's symbolize keys
  @options = defaults.merge( options )
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol, *arguments) ⇒ Object



41
42
43
# File 'lib/collective/policy.rb', line 41

def method_missing( symbol, *arguments )
  @options[symbol.to_sym]
end

Instance Method Details

#after_forkObject



53
54
55
# File 'lib/collective/policy.rb', line 53

def after_fork
  (after_forks || []).each { |f| f.call }
end

#before_forkObject



49
50
51
# File 'lib/collective/policy.rb', line 49

def before_fork
  (before_forks || []).each { |f| f.call }
end

#dupObject



45
46
47
# File 'lib/collective/policy.rb', line 45

def dup
  @options.dup
end

#storageObject



37
38
39
# File 'lib/collective/policy.rb', line 37

def storage
  Collective::Utilities::StorageBase.resolve @options[:storage]
end