Module: CassandraModel::Callbacks::ClassMethods

Defined in:
lib/cassandra-model/callbacks.rb

Instance Method Summary collapse

Instance Method Details

#define_callbacks(*callbacks) ⇒ Object



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/cassandra-model/callbacks.rb', line 206

def define_callbacks(*callbacks)
  callbacks.each do |callback|
    class_eval "      def self.\#{callback}(*methods, &block)                             # def self.before_save(*methods, &block)\n        callbacks = CallbackChain.build(:\#{callback}, *methods, &block)  #   callbacks = CallbackChain.build(:before_save, *methods, &block)\n        @\#{callback}_callbacks ||= CallbackChain.new                     #   @before_save_callbacks ||= CallbackChain.new\n        @\#{callback}_callbacks.concat callbacks                          #   @before_save_callbacks.concat callbacks\n      end                                                                # end\n                                                                         #\n      def self.\#{callback}_callback_chain                                # def self.before_save_callback_chain\n        @\#{callback}_callbacks ||= CallbackChain.new                     #   @before_save_callbacks ||= CallbackChain.new\n                                                                         #\n        if superclass.respond_to?(:\#{callback}_callback_chain)           #   if superclass.respond_to?(:before_save_callback_chain)\n          CallbackChain.new(                                             #     CallbackChain.new(\n            superclass.\#{callback}_callback_chain +                      #       superclass.before_save_callback_chain +\n            @\#{callback}_callbacks                                       #       @before_save_callbacks\n          )                                                              #     )\n        else                                                             #   else\n          @\#{callback}_callbacks                                         #     @before_save_callbacks\n        end                                                              #   end\n      end                                                                # end\n    end_eval\n  end\nend\n"