Class: Starter::Orms
- Inherits:
-
Object
- Object
- Starter::Orms
- Defined in:
- lib/starter/orms.rb
Class Method Summary collapse
- .add_migration(klass_name, resource) ⇒ Object
- .build(name, dest, orm) ⇒ Object
- .config ⇒ Object
- .load_orm(orm: ::Starter::Config.read[:orm]) ⇒ Object
- .standalone_migrations ⇒ Object
Class Method Details
.add_migration(klass_name, resource) ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/starter/orms.rb', line 55 def add_migration(klass_name, resource) load_orm return if @orm.nil? file_name = "#{Time.now.strftime('%Y%m%d%H%m%S')}_create_#{klass_name.downcase}.rb" migration_dest = File.join(Dir.pwd, 'db', 'migrate', file_name) FileOps.write_file(migration_dest, migration(klass_name, resource)) end |
.build(name, dest, orm) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/starter/orms.rb', line 6 def build(name, dest, orm) load_orm(orm: orm) return if @orm.nil? @name = name if @orm == 'ar' || @orm == 'activerecord' # Fixes pooling add_middleware(dest, 'ActiveRecord::Rack::ConnectionManagement') build_standalone_migrations(File.join(dest, '.standalone_migrations')) end build_initializer(File.join(dest, 'config', 'initializers')) build_config(File.join(dest, 'config')) append_to_file(File.join(dest, 'Rakefile'), rakefile) append_to_file(File.join(dest, 'Gemfile'), gemfile) prepare_for_migrations(File.join(dest, 'db')) end |
.config ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/starter/orms.rb', line 32 def config <<-FILE.strip_heredoc # ActiveRecord Database Configuration development: adapter: #{adapter} encoding: unicode timeout: 5000 database: #{@name}_development test: adapter: #{adapter} encoding: unicode timeout: 5000 database: #{@name}_test production: adapter: #{adapter} encoding: unicode timeout: 5000 database: #{@name}_production FILE end |
.load_orm(orm: ::Starter::Config.read[:orm]) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/starter/orms.rb', line 64 def load_orm(orm: ::Starter::Config.read[:orm]) @orm = orm case @orm when 'sequel' extend(Starter::Builder::Sequel) when 'activerecord', 'ar' extend(Starter::Builder::ActiveRecord) else @orm = nil end end |
.standalone_migrations ⇒ Object
25 26 27 28 29 30 |
# File 'lib/starter/orms.rb', line 25 def standalone_migrations <<-FILE.strip_heredoc config: database: config/database.yml FILE end |