Class: Reactor::AttributeHandlers
- Inherits:
-
Object
- Object
- Reactor::AttributeHandlers
- Includes:
- Singleton
- Defined in:
- lib/reactor/attributes.rb
Class Method Summary collapse
-
.install_attributes(klass) ⇒ Object
Use this method to install attributes into class.
- .obj_class(klass) ⇒ Object
-
.reinstall_attributes(klass, obj_class) ⇒ Object
Use this method if attributes changed and you wish to reinstall them.
Instance Method Summary collapse
-
#initialize ⇒ AttributeHandlers
constructor
A new instance of AttributeHandlers.
- #install(klass, obj_class) ⇒ Object
- #regenerate_attribute_handler(obj_class_name) ⇒ Object
Constructor Details
#initialize ⇒ AttributeHandlers
Returns a new instance of AttributeHandlers.
14 15 16 17 18 |
# File 'lib/reactor/attributes.rb', line 14 def initialize # t1 = Time.now self.generate_attribute_handlers # Rails.logger.debug "Reactor::AttributeHandlers: generate_attribute_handlers took #{Time.now - t1}" end |
Class Method Details
.install_attributes(klass) ⇒ Object
Use this method to install attributes into class
21 22 23 |
# File 'lib/reactor/attributes.rb', line 21 def self.install_attributes(klass) Reactor::AttributeHandlers.instance.install(klass, obj_class(klass)) end |
.obj_class(klass) ⇒ Object
33 34 35 |
# File 'lib/reactor/attributes.rb', line 33 def self.obj_class(klass) klass.name.split('::').last end |
.reinstall_attributes(klass, obj_class) ⇒ Object
Use this method if attributes changed and you wish to reinstall them
26 27 28 29 30 31 |
# File 'lib/reactor/attributes.rb', line 26 def self.reinstall_attributes(klass, obj_class) Reactor::AttributeHandlers.instance.tap do |handler| handler.regenerate_attribute_handler(obj_class) handler.install(klass, obj_class) end end |
Instance Method Details
#install(klass, obj_class) ⇒ Object
37 38 39 40 41 |
# File 'lib/reactor/attributes.rb', line 37 def install(klass, obj_class) if obj_class_known?(obj_class) klass.send(:include, handler_module(obj_class)) end end |
#regenerate_attribute_handler(obj_class_name) ⇒ Object
43 44 45 |
# File 'lib/reactor/attributes.rb', line 43 def regenerate_attribute_handler(obj_class_name) generate_attribute_handler(RailsConnector::Meta::EagerLoader.instance.obj_class(obj_class_name)) end |