Module: Canable::Actor
- Defined in:
- lib/canable/actor.rb
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#canable_included_role ⇒ Object
Override attr_accessor to make sure the role has been included so that we can return an accurate value “lazy” role including.
Class Method Summary collapse
Instance Method Summary collapse
- #__get_role_constant ⇒ Object
-
#__initialize_canable_role ⇒ Object
Called every time a role is needed to make sure the lazy load has been completed.
-
#act(role) ⇒ Object
Sets the role of this actor by including a role module.
Instance Attribute Details
#canable_included_role ⇒ Object
Override attr_accessor to make sure the role has been included so that we can return an accurate value “lazy” role including
16 17 18 |
# File 'lib/canable/actor.rb', line 16 def canable_included_role @canable_included_role end |
Class Method Details
.included(base) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/canable/actor.rb', line 5 def self.included(base) base.instance_eval do include Canable::Cans end class << base include ClassMethods end end |
Instance Method Details
#__get_role_constant ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/canable/actor.rb', line 34 def __get_role_constant if self.class.canable_role_proc.respond_to?(:call) attribute = self.class.canable_role_proc.call(self) elsif self.instance_variable_get(:@role) attribute = @role end attribute || nil end |
#__initialize_canable_role ⇒ Object
Called every time a role is needed to make sure the lazy load has been completed
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/canable/actor.rb', line 22 def __initialize_canable_role return if @_canable_initialized == true @_canable_intialize == true role_constant = self.__get_role_constant if role_constant == nil default_role = self.class.canable_default_role self.act(default_role) unless default_role == nil else self.act(role_constant) end end |
#act(role) ⇒ Object
Sets the role of this actor by including a role module
44 45 46 47 48 49 50 |
# File 'lib/canable/actor.rb', line 44 def act(role) unless(role.respond_to?(:included)) role = Canable::Roles.const_get((role.to_s.capitalize+"Role").intern) end self.extend role self.canable_included_role = role end |