Sha256: d5dba2d0b73c841201cdd0f7ad666b96f3ced26f5d3ad8327bd6b22cedca6d73

Contents?: true

Size: 670 Bytes

Versions: 2

Compression:

Stored size: 670 Bytes

Contents

# frozen_string_literal: true

module Nina
  class Builder
    # Utility to get user defined callbacks
    class Callbacks
      def initialize(allow_list, atts = {})
        @allow_list = allow_list
        @atts = atts
      end

      def copy
        Callbacks.new(@allow_list, to_h.dup)
      end

      def method_missing(method, *args, **kwargs, &block)
        return super unless @allow_list.include?(method)

        @atts[method] unless block
        @atts[method] ||= []
        @atts[method] << block
      end

      def respond_to_missing?(method, include_private = false)
        super
      end

      def to_h
        @atts
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
nina-0.2.1 lib/nina/builder/callbacks.rb
nina-0.2.0 lib/nina/builder/callbacks.rb