Added 'Seedable' concern to (re-)seed models based on their seed files in /db/seeds .
This commit is contained in:
parent
8ef2970234
commit
d160a86e09
2 changed files with 24 additions and 0 deletions
23
app/models/concerns/seedable.rb
Normal file
23
app/models/concerns/seedable.rb
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
|
||||||
|
module Seedable
|
||||||
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
|
# methods defined here are going to extend the class, not the instance of it
|
||||||
|
class_methods do
|
||||||
|
|
||||||
|
def reseed
|
||||||
|
destroy_all
|
||||||
|
seed
|
||||||
|
end
|
||||||
|
|
||||||
|
def seed
|
||||||
|
UserInfo.ensure_current_user_id do
|
||||||
|
load seedfile
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def seedfile
|
||||||
|
"#{Rails.root}/db/seeds/#{name.pluralize.underscore}.rb"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -3,6 +3,7 @@
|
||||||
class Overview < ApplicationModel
|
class Overview < ApplicationModel
|
||||||
include NotifiesClients
|
include NotifiesClients
|
||||||
include LatestChangeObserved
|
include LatestChangeObserved
|
||||||
|
include Seedable
|
||||||
|
|
||||||
load 'overview/assets.rb'
|
load 'overview/assets.rb'
|
||||||
include Overview::Assets
|
include Overview::Assets
|
||||||
|
|
Loading…
Reference in a new issue