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

Use Mongoid::Config#models in Rake task, resolves #247 #255

Merged
merged 2 commits into from
Aug 17, 2018
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 6.0.1 (Next)

* Your contribution here.
* [#255](https:/mongoid/mongoid-slug/pull/255): Use mongoid::config#models in rake task, resolves #247 - [@kailan](https:/kailan).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally a prettier, clickable syntax for this is

[#255](https:/mongoid/mongoid-slug/pull/255), [#247](https:/mongoid/mongoid-slug/pull/247): Use `mongoid::config#models` in rake task - [@kailan](https:/kailan).


## 6.0.0 (2018/09/17)

Expand Down
6 changes: 1 addition & 5 deletions lib/tasks/mongoid_slug.rake
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ namespace :mongoid_slug do
desc 'Goes though all documents and sets slug if not already set'
task set: :environment do |_, args|
::Rails.application.eager_load! if defined?(Rails)
klasses = Module.constants.find_all do |const|
next if const == :MissingSourceFile
const != const.upcase ? Mongoid::Slug > (Object.const_get const) : nil
end
klasses.map! { |klass| klass.to_s.constantize }
klasses = Mongoid::Config.models.find_all { |c| c.ancestors.include?(Mongoid::Slug) }
unless klasses.blank?
models = args.extras
klasses = (klasses.map(&:to_s) & models.map(&:classify)).map(&:constantize) if models.any?
Expand Down