Sha256: 862ad4073d4313d713da5bf5e1b3168000b826b04aa14081f37080fce3d14eda

Contents?: true

Size: 957 Bytes

Versions: 6

Compression:

Stored size: 957 Bytes

Contents

require "savon/hooks/hook"

module Savon
  module Hooks

    # = Savon::Hooks::Group
    #
    # Manages a list of hooks.
    class Group

      # Accepts an Array of +hooks+ to start with.
      def initialize(hooks = nil)
        self.hooks = hooks
      end

      attr_writer :hooks

      def hooks
        @hooks ||= []
      end

      # Adds a new hook.
      def define(id, hook, &block)
        hooks << Hook.new(id, hook, &block)
      end

      # Removes hooks matching the given +ids+.
      def reject!(*ids)
        ids = ids.flatten
        hooks.reject! { |hook| ids.include? hook.id }
      end

      # Returns a new group for a given +hook+.
      def select(hook)
        Group.new hooks.select { |h| h.hook == hook }
      end

      # Calls the hooks with the given +args+ and returns the
      # value of the last hooks.
      def call(*args)
        hooks.inject(nil) { |memo, hook| hook.call(*args) }
      end

    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
savon-0.9.14 lib/savon/hooks/group.rb
savon-0.9.11 lib/savon/hooks/group.rb
savon-0.9.10 lib/savon/hooks/group.rb
savon-0.9.9 lib/savon/hooks/group.rb
savon-0.9.8 lib/savon/hooks/group.rb
regenersis-savon-1.0.0 lib/savon/hooks/group.rb