Sha256: 03f0c5f1d38c1736c37846d5cddcbc13590d9c7b6b4552bbff1f6242eae458d1

Contents?: true

Size: 749 Bytes

Versions: 3

Compression:

Stored size: 749 Bytes

Contents

require 'controll/notify/flash'

module Controll
  module Notify
    class Typed < Flash
      class MissingNotifyHandlerClass < StandardError; end

      include Controll::Notify::Macros

      types.each do |type|      
        define_method type do        
          clazz = handler_class(type)
          raise MissingNotifyHandlerClass, "#{clazz} class missing" unless clazz
          var = "@#{type}"
          instance_variable_get(var) || instance_variable_set(var, clazz.new(flash))
        end
      end

      protected

      def handler_class name
        handler_classes[name] ||= "#{self.class}::#{name.to_s.camelize}Handler".constantize
      end 

      def handler_classes
        @handler_classes ||= {}
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
controll-0.3.2 lib/controll/notify/typed.rb
controll-0.3.1 lib/controll/notify/typed.rb
controll-0.3.0 lib/controll/notify/typed.rb