Sha256: 10ba069da33161c4e5bcb7ec4470be7183b7ec3383951d4a945f52619f116779

Contents?: true

Size: 1.27 KB

Versions: 8

Compression:

Stored size: 1.27 KB

Contents

require "beetle_reporter/version"
require "beetle_reporter/engine"
require 'beetle_reporter/configuration'

require 'aasm'
require 'pagy'
require 'hamlit'
require 'discard'
require 'turbo-rails'

module BeetleReporter
  class << self
    def config
      return @config if defined?(@config)

      @config = Configuration.new
      @config.user_class = 'User'
      @config.current_user_method = 'current_user'
      @config.user_name_method = 'name'
      @config.main_app_root_path_method = 'root_path'
      @config.main_app_user_path_method = 'user_path'

      @config
    end

    def configure
      yield(config)
    end

    def add(record, user_id, reason)
      report = BeetleReporter::Report.pending.kept.find_by(record: record)
      if report
        report.user_ids << user_id unless report.user_ids.include?(user_id)
        report.reasons << reason unless report.reasons.include?(reason)
        # 未登录用户也有可能
        report.reported_count += 1
        report.user_ids = report.user_ids.uniq
        report.reasons = report.reasons.uniq
        report.save
      else
        report = BeetleReporter::Report.create(record: record,
          user_ids: [user_id],
          reasons: [reason],
          reported_count: 1,
        )
      end
      report
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
beetle_reporter-0.1.10 lib/beetle_reporter.rb
beetle_reporter-0.1.9 lib/beetle_reporter.rb
beetle_reporter-0.1.8 lib/beetle_reporter.rb
beetle_reporter-0.1.7 lib/beetle_reporter.rb
beetle_reporter-0.1.6 lib/beetle_reporter.rb
beetle_reporter-0.1.5 lib/beetle_reporter.rb
beetle_reporter-0.1.4 lib/beetle_reporter.rb
beetle_reporter-0.1.3 lib/beetle_reporter.rb