Guest User

Untitled

a guest
Aug 11th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. # I have a project. Migrations are stored in lib/foo/schema/xxx_description.rb,
  2. # with classes called Foo::Schema::Description.
  3.  
  4. class Foo::Schema
  5. # Pretty simple, just tell AR to migrate based on my stored migrations
  6. def self.up
  7. ActiveRecord::Base.logger ||= Logger.new(StringIO.new)
  8. ActiveRecord::Migrator.up(migrations_path)
  9. end
  10.  
  11. def self.migrations_path
  12. File.expand_path('../schema', __FILE__)
  13. end
  14.  
  15. # Oh, but to make AR happy, the migration class names need to exist in the
  16. # global namespace, so I need to load my migrations and export all the
  17. # constants in Foo::Schema into the global namespace.
  18.  
  19. Dir.entries(migrations_path).each do |file|
  20. path = File.join(migrations_path, file)
  21. require path if File.file?(path)
  22. end
  23.  
  24. constants.each do |const_name|
  25. Kernel.const_set(const_name, const_get(const_name))
  26. end
  27. end
Add Comment
Please, Sign In to add comment