Module: CanTango::Config::Permits::Registration

Includes:
Permit::Helper::Naming
Included in:
CanTango::Config::Permits
Defined in:
lib/cantango/permits_ext/config/permits/registration.rb

Instance Method Summary collapse

Methods included from Permit::Helper::Naming

#account_name, #permit_name, #permit_type

Instance Method Details

#register(permit_clazz, options = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/cantango/permits_ext/config/permits/registration.rb', line 14

def register permit_clazz, options = {}
  permit_name = options[:name]    || permit_name(permit_clazz)
  permit_type = options[:type]    || permit_type(permit_clazz)
  acc_name    = options[:account] || (permit_clazz. if permit_clazz.respond_to?(:account_name))

  registry = acc_name ? accounts.registry_for(acc_name) : self
  
  unless registry
    raise acc_name ? "Missing Permit account Registry for #{acc_name}" : "Missing Permit Registry for #{self}"
  end 
          
  acc_debug = acc_name ? "(#{acc_name})" : ''
  debug "Registering #{permit_type} permit: #{permit_name} of class #{permit_clazz} #{acc_debug}"

  permit_registry = registry.registry_for(permit_type)
  permit_registry.register permit_name => permit_clazz        
end

#register_permit(clazz, options = {}) ⇒ Object



6
7
8
# File 'lib/cantango/permits_ext/config/permits/registration.rb', line 6

def register_permit clazz, options = {}
  register clazz, options
end

#register_permit_type(clazz, options = {}) ⇒ Object



10
11
12
# File 'lib/cantango/permits_ext/config/permits/registration.rb', line 10

def register_permit_type clazz, options = {}
  types.register permit_name(clazz), clazz
end