Callbacks

StimulusReflex server callbacks PR that I made where you can see a more advanced example on what you can do with this Callbacks module:
https://github.com/hopsoft/stimulus_reflex/pull/160

Some of the code used in this video:

module Benchmarkable
  extend ActiveSupport::Concern

  included do
    include ActiveSupport::Callbacks

    define_callbacks :benchmark
    # you can set before, around or after
    set_callback :benchmark, :around, :around_benchmark
  end

  def around_benchmark
    time_before = Time.now
    yield
    time_after = Time.now

    puts "TOTAL TIME: #{time_after - time_before} seconds"
  end
end

class Person
  include Benchmarkable

  def do_something
    run_callbacks :benchmark do
      puts "DO SOMETHING"
      sleep 3
    end
  end
end

p = Person.new
p.do_something

ActiveSupport - The unnoticed power behind Rails

Buy nowLearn more

Intro

  • Intro
  • System requirements / Versions
  • How to use ActiveSupport outside of Rails

Modules

  • ActionableError
  • Benchmarkable
  • Callbacks
  • Concern
  • Configurable1
  • Dependencies/Autoload
  • DescendantsTracker
  • Gzip
  • LazyLoadHooks
  • Notifications
  • NumberHelper
  • Rescuable
  • SecurityUtils
  • TaggedLogging
  • XmlMini

Classes

  • BacktraceCleaner
  • Cache
  • ConfigurationFile
  • CurrentAttributes
  • Deprecation
  • Inquirers
  • Duration
  • HashWithIndifferentAccess
  • ParameterFilter
  • TestCase