Class: CanTango::PermitEngine::Factory

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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



9
10
11
# File 'lib/cantango/permit_engine/factory.rb', line 9

def initialize ability
  @ability = ability
end

Instance Attribute Details

#abilityObject

Returns the value of attribute ability.



4
5
6
# File 'lib/cantango/permit_engine/factory.rb', line 4

def ability
  @ability
end

#buildersObject

Returns the value of attribute builders.



4
5
6
# File 'lib/cantango/permit_engine/factory.rb', line 4

def builders
  @builders
end

Instance Method Details

#build!Object



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

def build!
  @builders ||= builders.inject([]) do |res, builder|
    res << create_builder(builder).build
    res
  end.flatten.compact
end

#builder_class(builder) ⇒ Object



25
26
27
28
# File 'lib/cantango/permit_engine/factory.rb', line 25

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

#create_builder(builder) ⇒ Object



20
21
22
23
# File 'lib/cantango/permit_engine/factory.rb', line 20

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

#optionsObject



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

def options
  ability.options
end