Sha256: 3637f2768cda50faea2f6228d523de1202c29e554da651cb1fb5027e2ffca7ae
Contents?: true
Size: 1.32 KB
Versions: 1
Compression:
Stored size: 1.32 KB
Contents
require 'rails/generators/active_record' module Moneytree module Generators class ActiverecordGenerator < Rails::Generators::Base include ActiveRecord::Generators::Migration source_root File.join(__dir__, 'templates') class_option :database, type: :string, aliases: '-d' def copy_templates template 'moneytree_initializer.rb', 'config/initializers/moneytree.rb' # template 'active_record_visit_model.rb', 'app/models/moneytree/visit.rb' # template 'active_record_event_model.rb', 'app/models/moneytree/event.rb' migration_template 'active_record_migration.rb', 'db/migrate/create_moneytree_visits_and_events.rb', migration_version: migration_version puts "\nAlmost set! Last, run:\n\n rails db:migrate" end def properties_type # use connection_config instead of connection.adapter # so database connection isn't needed case ActiveRecord::Base.connection_config[:adapter].to_s when /postg/i # postgres, postgis 'jsonb' when /mysql/i 'json' else 'text' end end def rails52? ActiveRecord::VERSION::STRING >= '5.2' end def migration_version "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]" end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
moneytree-rails-0.1.0 | lib/generators/moneytree/activerecord_generator.rb |