Sha256: dc23c13b2484d3030d03c47c0dcccac61703754b9b4673502a12d7e2374b76f0

Contents?: true

Size: 1.76 KB

Versions: 6

Compression:

Stored size: 1.76 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
      else
        Signal.create!(options.merge(key: signalable_receiver.to_s))
      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

6 entries across 6 versions & 1 rubygems

Version Path
signum-0.7.9 lib/signum.rb
signum-0.7.8 lib/signum.rb
signum-0.7.4 lib/signum.rb
signum-0.7.2 lib/signum.rb
signum-0.7.1 lib/signum.rb
signum-0.7.0 lib/signum.rb