Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: warning: previous definition messages #363

Merged
merged 1 commit into from
Mar 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/merit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ def self.add_observer(class_name)
@config.add_observer(class_name)
end

# If the app is reloaded, avoid printing `warning: previous definition of AppBadgeRules was here`
def self.remove_badge_rules
remove_const(:AppBadgeRules) if self.const_defined?('AppBadgeRules')
end

# If the app is reloaded, avoid printing `warning: previous definition of AppPointRules was here`
def self.remove_point_rules
remove_const(:AppPointRules) if self.const_defined?('AppPointRules')
end

class Configuration
attr_accessor :checks_on_each_request, :orm, :user_model_name, :observers,
:current_user_method
Expand Down Expand Up @@ -65,6 +75,9 @@ class Engine < Rails::Engine
ActiveSupport.on_load(:active_record) { include Merit }
ActiveSupport.on_load(app.config.api_only ? :action_controller_api : :action_controller_base) do
begin
# Remove previous definitions of constant if they are defined when app reloads
Merit.remove_badge_rules
Merit.remove_point_rules
# Load app rules on boot up
Merit::AppBadgeRules = Merit::BadgeRules.new.defined_rules
Merit::AppPointRules = Merit::PointRules.new.defined_rules
Expand Down
4 changes: 2 additions & 2 deletions test/dummy/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# This file is the source Rails uses to define your schema when running `rails
# db:schema:load`. When creating a new database, `rails db:schema:load` tends to
# This file is the source Rails uses to define your schema when running `bin/rails
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
# be faster and is potentially less error prone than running all of your
# migrations from scratch. Old migrations may fail to apply correctly if those
# migrations use external dependencies or application code.
Expand Down