Skip to content

Instantly share code, notes, and snippets.

@msroot
Last active April 29, 2020 12:04
Show Gist options
  • Save msroot/d7fdbf5b8a978183e439524db0343ee7 to your computer and use it in GitHub Desktop.
Save msroot/d7fdbf5b8a978183e439524db0343ee7 to your computer and use it in GitHub Desktop.
Check if all monetize attributes set
# rake monetize:verify
namespace :monetize do
desc "Verifies if all monetize attributes are set"
task verify: :environment do
ActiveRecord::Base.connection.tables.sort.map do |model|
next if %w(schema_migrations ar_internal_metadata versions).include?(model)
puts "Scanning: #{model}"
model = model.classify.safe_constantize
to_add = []
model.attribute_names.map { |e|
postfix = MoneyRails.amount_column[:postfix]
next unless e.end_with?(postfix)
at = e.gsub(postfix, '')
has_money = model.new.send(at).is_a?(Money) rescue nil
unless has_money
to_add << e
end
}
if to_add.any?
puts '=' * 10
puts "Add to #{model}"
puts '=' * 10
to_add.sort.map { |e|
puts "monetize :#{e}"
}
exit(0)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment