Module: Timberline::Rails::ActiveRecord::ClassMethods
- Defined in:
- lib/timberline/rails/active_record.rb
Overview
Class methods that get added to any class that includes Timberline::Rails::ActiveRecord.
Instance Method Summary collapse
-
#delay_method(method_name) ⇒ Object
Mark a method as one that needs to be executed in the background.
-
#timberline_push(content, metadata = {}) ⇒ Object
Push an item onto the queue specified for this model.
-
#timberline_queue(queue_name) ⇒ Object
Set the queue name for this model.
Instance Method Details
#delay_method(method_name) ⇒ Object
Mark a method as one that needs to be executed in the background.
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/timberline/rails/active_record.rb', line 62 def delay_method(method_name) alias_method "synchronous_#{method_name}", method_name define_method "timberline_#{method_name}" do model_name = self.class.name model_key = self.send(self.class.primary_key) self.class.timberline_push({ model_name: model_name, model_key: model_key, method_name: method_name }) end alias_method method_name, "timberline_#{method_name}" end |
#timberline_push(content, metadata = {}) ⇒ Object
Push an item onto the queue specified for this model.
50 51 52 53 54 55 |
# File 'lib/timberline/rails/active_record.rb', line 50 def timberline_push(content, = {}) if @timberline_queue.nil? raise "You must specify a queue name using .timberline_queue first" end @timberline_queue.push(content, ) end |
#timberline_queue(queue_name) ⇒ Object
Set the queue name for this model. Required.
43 44 45 |
# File 'lib/timberline/rails/active_record.rb', line 43 def timberline_queue(queue_name) @timberline_queue = Timberline.queue(queue_name) end |