Sha256: d76c178a19c34f97d7196fb57b9522983bf5c4c76754ca63c29ed9fc1d677bd5
Contents?: true
Size: 1.58 KB
Versions: 1
Compression:
Stored size: 1.58 KB
Contents
require 'rails/generators' require 'rails/generators/migration' # require 'rails/version' STORES = %w(active_record redis) class SocializationGenerator < Rails::Generators::Base include Rails::Generators::Migration source_root File.expand_path(File.join('templates'), File.dirname(__FILE__)) class_option :store, :type => :string, :default => 'active_record', :description => "Type of datastore" def self.next_migration_number(dirname) if ActiveRecord::Base.try(:timestamped_migrations) || ActiveRecord.try(:timestamped_migrations) Time.now.utc.strftime("%Y%m%d%H%M%S") else "%.3d" % (current_migration_number(dirname) + 1) end end def create_migration_file options[:store].downcase! unless STORES.include?(options[:store]) puts "Invalid store '#{options[:store]}'. The following stores are valid: #{STORES.join(', ')}." exit 1 end copy_file "#{options[:store]}/model_follow.rb", 'app/models/follow.rb' copy_file "#{options[:store]}/model_like.rb", 'app/models/like.rb' copy_file "#{options[:store]}/model_mention.rb", 'app/models/mention.rb' if options[:store] == 'active_record' migration_template "#{options[:store]}/migration_follows.rb", 'db/migrate/create_follows.rb' sleep 1 # wait a second to have a unique migration timestamp migration_template "#{options[:store]}/migration_likes.rb", 'db/migrate/create_likes.rb' sleep 1 # wait a second to have a unique migration timestamp migration_template "#{options[:store]}/migration_mentions.rb", 'db/migrate/create_mentions.rb' end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
socialization-2.0.2 | lib/generators/socialization/socialization_generator.rb |