Class: CanTango::PermitEngine::Factory
- Inherits:
-
Object
- Object
- CanTango::PermitEngine::Factory
- Includes:
- Helpers::Debug
- Defined in:
- lib/cantango/permit_engine/factory.rb
Instance Attribute Summary collapse
-
#ability ⇒ Object
Returns the value of attribute ability.
Instance Method Summary collapse
- #build! ⇒ Object
- #builder_class(builder) ⇒ Object
- #builders ⇒ Object
- #create_builder(builder) ⇒ Object
-
#initialize(ability) ⇒ Factory
constructor
creates the factory for the ability note that the ability contains the roles and role groups of the user (or account).
- #options ⇒ Object
-
#permits ⇒ Object
return hash of permits built, keyed by name of builder.
- #permits_built_with(builder) ⇒ Object
Methods included from Helpers::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)
11 12 13 |
# File 'lib/cantango/permit_engine/factory.rb', line 11 def initialize ability @ability = ability end |
Instance Attribute Details
#ability ⇒ Object
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 |
#builders ⇒ Object
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 |
#options ⇒ Object
53 54 55 |
# File 'lib/cantango/permit_engine/factory.rb', line 53 def ability. end |
#permits ⇒ Object
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 |