Sha256: 703473ed4a760bcab70338e52acfcde10384bd7066c6ab51222fd95414eabab9

Contents?: true

Size: 652 Bytes

Versions: 13

Compression:

Stored size: 652 Bytes

Contents

module JsonapiCompliable
  module Util
    class Hooks
      def self.record
        self.hooks = []
        begin
          yield.tap { run }
        ensure
          self.hooks = []
        end
      end

      def self._hooks
        Thread.current[:_compliable_hooks] ||= []
      end
      private_class_method :_hooks

      def self.hooks=(val)
        Thread.current[:_compliable_hooks] = val
      end

      # Because hooks will be added from the outer edges of
      # the graph, working inwards
      def self.add(prc)
        _hooks.unshift(prc)
      end

      def self.run
        _hooks.each { |h| h.call }
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
jsonapi_compliable-0.11.34 lib/jsonapi_compliable/util/hooks.rb
jsonapi_compliable-0.11.33 lib/jsonapi_compliable/util/hooks.rb
jsonapi_compliable-0.11.32 lib/jsonapi_compliable/util/hooks.rb
jsonapi_compliable-0.11.31 lib/jsonapi_compliable/util/hooks.rb
jsonapi_compliable-0.11.30 lib/jsonapi_compliable/util/hooks.rb
jsonapi_compliable-0.11.29 lib/jsonapi_compliable/util/hooks.rb
jsonapi_compliable-0.11.28 lib/jsonapi_compliable/util/hooks.rb
jsonapi_compliable-0.11.27 lib/jsonapi_compliable/util/hooks.rb
jsonapi_compliable-0.11.26 lib/jsonapi_compliable/util/hooks.rb
jsonapi_compliable-0.11.25 lib/jsonapi_compliable/util/hooks.rb
jsonapi_compliable-1.0.alpha.2 lib/jsonapi_compliable/util/hooks.rb
jsonapi_compliable-0.11.24 lib/jsonapi_compliable/util/hooks.rb
jsonapi_compliable-0.11.23 lib/jsonapi_compliable/util/hooks.rb