Module: PopulateMe::DocumentMixins::Callbacks::ClassMethods
- Defined in:
- lib/populate_me/document_mixins/callbacks.rb
Instance Attribute Summary collapse
-
#callbacks ⇒ Object
Returns the value of attribute callbacks.
Instance Method Summary collapse
- #after(name, item = nil, options = {}, &block) ⇒ Object
- #before(name, item = nil, options = {}, &block) ⇒ Object
- #register_callback(name, item = nil, options = {}, &block) ⇒ Object
Instance Attribute Details
#callbacks ⇒ Object
Returns the value of attribute callbacks.
95 96 97 |
# File 'lib/populate_me/document_mixins/callbacks.rb', line 95 def callbacks @callbacks end |
Instance Method Details
#after(name, item = nil, options = {}, &block) ⇒ Object
116 117 118 |
# File 'lib/populate_me/document_mixins/callbacks.rb', line 116 def after name, item=nil, ={}, &block register_callback "after_#{name}", item, , &block end |
#before(name, item = nil, options = {}, &block) ⇒ Object
112 113 114 |
# File 'lib/populate_me/document_mixins/callbacks.rb', line 112 def before name, item=nil, ={}, &block register_callback "before_#{name}", item, , &block end |
#register_callback(name, item = nil, options = {}, &block) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/populate_me/document_mixins/callbacks.rb', line 97 def register_callback name, item=nil, ={}, &block name = name.to_sym if block_given? = item || {} item = block end self.callbacks ||= {} self.callbacks[name] ||= [] if [:prepend] self.callbacks[name].unshift item else self.callbacks[name] << item end end |