Class: CanTango::PermitEngine::Factory

Inherits:
Object
  • Object
show all
Includes:
Helpers::Debug
Defined in:
lib/cantango/permit_engine/factory.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::Debug

#debug

Constructor Details

#initialize(ability) ⇒ Factory

creates the factory for the ability note that the ability contains the roles and role groups of the user (or account)

Parameters:

  • the (Permits::Ability)

    ability



11
12
13
# File 'lib/cantango/permit_engine/factory.rb', line 11

def initialize ability
  @ability = ability
end

Instance Attribute Details

#abilityObject

Returns the value of attribute ability.



6
7
8
# File 'lib/cantango/permit_engine/factory.rb', line 6

def ability
  @ability
end

Instance Method Details

#build!Object



15
16
17
18
# File 'lib/cantango/permit_engine/factory.rb', line 15

def build!
  debug "PermitEngine Factory: No permits could be built" if permits.empty?
  permits
end

#builder_class(builder) ⇒ Object



44
45
46
47
# File 'lib/cantango/permit_engine/factory.rb', line 44

def builder_class builder
  return "CanTango::PermitEngine::Builder::SpecialPermits" if builder == :special
  "CanTango::Permits::#{builder.to_s.camelize}Permit::Builder"
end

#buildersObject



49
50
51
# File 'lib/cantango/permit_engine/factory.rb', line 49

def builders
  CanTango.config.permits.enabled
end

#create_builder(builder) ⇒ Object



39
40
41
42
# File 'lib/cantango/permit_engine/factory.rb', line 39

def create_builder builder
  clazz = builder_class(builder)
  clazz.constantize.new(ability)
end

#optionsObject



53
54
55
# File 'lib/cantango/permit_engine/factory.rb', line 53

def options
  ability.options
end

#permitsObject

return hash of permits built, keyed by name of builder



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/cantango/permit_engine/factory.rb', line 21

def permits
  @permits ||= builders.inject({}) do |permits, builder|
    debug "++ Permit Builder: #{builder_class builder}"
    built_permits = permits_built_with(builder)

    if built_permits
      debug "== Permits built: #{built_permits.size}"
      permits[builder] = built_permits
    end

    permits
  end
end

#permits_built_with(builder) ⇒ Object



35
36
37
# File 'lib/cantango/permit_engine/factory.rb', line 35

def permits_built_with builder
  create_builder(builder).build
end