Sha256: c4aaecec40ec1009372b24f8020e57a93eaf5b97177c74f9f9929ed34e14c29b

Contents?: true

Size: 1.68 KB

Versions: 8

Compression:

Stored size: 1.68 KB

Contents

require 'signum/engine'
require 'signum/active_record_helpers'
require 'signum/configuration'

module Signum
  class Error < StandardError
  end

  class << self
    def config
      @config ||= Configuration.new
    end

    def setup
      @config = Configuration.new
      yield config
    end

    # def i18n_store
    #   @i18n_store ||= Nuntius::I18nStore.new
    # end

    # Generic notice
    def signal(signalable_receiver, options)
      return unless signalable_receiver

      if signalable_receiver.is_a?(Signum.config.user_model_name.constantize)
        signalable_receiver.signals.create!(options)

      elsif signalable_receiver.respond_to?(:each)
        signalable_receiver.each { |signalable| signal(signalable, options) }
        nil
      end
    end

    # Signal about something that happened
    def info(signalable, options)
      return unless signalable

      signal(signalable, options.merge(kind: 'info', icon: Signum.config.icons[:info]))
    end

    # Signal about an error
    def error(signalable, options)
      return unless signalable

      signal(signalable, options.merge(kind: 'error', icon: Signum.config.icons[:error]))
    end

    # Signal about something that went sucessfully
    def success(signalable, options)
      return unless signalable

      signal(signalable, options.merge(kind: 'success', icon: Signum.config.icons[:success]))
    end

    # Signal about something that could go wrong
    def warning(signalable, options)
      return unless signalable

      signal(signalable, options.merge(kind: 'warning', icon: Signum.config.icons[:warning]))
    end
  end

  # Include helpers
  ActiveSupport.on_load(:active_record) { include ActiveRecordHelpers }
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
signum-0.6.0 lib/signum.rb
signum-0.5.1 lib/signum.rb
signum-0.5.0 lib/signum.rb
signum-0.4.13 lib/signum.rb
signum-0.4.12 lib/signum.rb
signum-0.4.11 lib/signum.rb
signum-0.4.10 lib/signum.rb
signum-0.4.8 lib/signum.rb