Class: CanTango::Configuration::PermitRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/cantango/configuration/permit_registry.rb

Direct Known Subclasses

Permits

Instance Method Summary collapse

Instance Method Details

#allObject



19
20
21
# File 'lib/cantango/configuration/permit_registry.rb', line 19

def all
  (available_types - [:special]).map{|type| permits_for(type)}
end

#available_typesObject



27
28
29
# File 'lib/cantango/configuration/permit_registry.rb', line 27

def available_types
  CanTango.config.permits.available_types
end

#permits_for(type) ⇒ Object

Raises:

  • (ArgumentError)


4
5
6
7
8
9
# File 'lib/cantango/configuration/permit_registry.rb', line 4

def permits_for type        
  raise ArgumentError, "Not an available permit type: #{type}, available are: #{available_types}" if !available_types.include? type
  inst_var_name = "@#{type}"
  instance_variable_set(inst_var_name, HashRegistry.new) if !instance_variable_get(inst_var_name)
  instance_variable_get(inst_var_name)
end

#registered_by(type) ⇒ Object



15
16
17
# File 'lib/cantango/configuration/permit_registry.rb', line 15

def registered_by type
  permits_for(type).registered
end

#registered_for(type, name = nil) ⇒ Object



11
12
13
# File 'lib/cantango/configuration/permit_registry.rb', line 11

def registered_for type, name = nil
  name ? registered_by(type)[name.to_s] : registered_by(type)
end

#show_allObject



23
24
25
# File 'lib/cantango/configuration/permit_registry.rb', line 23

def show_all
  all.map(&:registered)
end