Class: UniversalTrackManager::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- UniversalTrackManager::InstallGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/generators/universal_track_manager/install_generator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #create_universal_track_manager_initializer ⇒ Object
- #create_universal_track_manager_migration ⇒ Object
- #migration_version ⇒ Object
Class Method Details
.next_migration_number(path) ⇒ Object
23 24 25 |
# File 'lib/generators/universal_track_manager/install_generator.rb', line 23 def self.next_migration_number(path) Time.now.utc.strftime("%Y%m%d%H%M%S") end |
Instance Method Details
#create_universal_track_manager_initializer ⇒ Object
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/generators/universal_track_manager/install_generator.rb', line 74 def create_universal_track_manager_initializer @table_prefix_value = ['table_prefix'] column_config = "config.campaign_columns = '#{@default_params.join(',')}'" table_prefix_config = ['table_prefix'].present? ? "\n config.table_prefix = '#{['table_prefix']}'" : "" copy_file "universal_track_manager.rb", "#{self.class.source_root}/universal_track_manager.rb-staged" gsub_file "#{self.class.source_root}/universal_track_manager.rb-staged", "#GENERATOR INSERTS CAMPAIGN COLUMN CONFIG HERE", "#{column_config}#{table_prefix_config}" copy_file 'universal_track_manager.rb-staged', 'config/initializers/universal_track_manager.rb' remove_file "#{self.class.source_root}/universal_track_manager.rb-staged" end |
#create_universal_track_manager_migration ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/generators/universal_track_manager/install_generator.rb', line 28 def create_universal_track_manager_migration # guard against pre-0.7.3 sytnax if ['param_list'] puts "Oops (FATAL): param_list is removed; use 'add' to augment the default list of fields or use 'only' to replace it" exit end # guard against using both 'add' and 'only' if ['add'] && ['only'] puts "Oops (FATAL): You specified both 'add' and 'only'; use 'add' to augment the default list of fields OR use 'only' to replace it" exit end @default_params = %w{utm_source utm_medium utm_campaign utm_content utm_term} if ['add'] ['add'].split(",").each do |p| if !@default_params.include?(p) @default_params << p end end end if ['only'] @default_params = [] ['only'].split(",").each do |p| @default_params << p end end @table_prefix = ['table_prefix'].present? ? "#{['table_prefix']}_" : "" column_defs = "" @default_params.each do |p| column_defs += " t.string :#{p}, limit:256\n" end copy_file "create_universal_track_manager_tables.rb", "#{self.class.source_root}/create_universal_track_manager_tables.rb-staged" gsub_file "#{self.class.source_root}/create_universal_track_manager_tables.rb-staged", "#GENERATOR INSERTS CAMPAIGN COLUMNS HERE", column_defs gsub_file "#{self.class.source_root}/create_universal_track_manager_tables.rb-staged", "<%= @table_prefix %>", @table_prefix gsub_file "#{self.class.source_root}/create_universal_track_manager_tables.rb-staged", "<%= migration_version %>", migration_version.to_s migration_template "create_universal_track_manager_tables.rb-staged", "db/migrate/create_universal_track_manager_tables.rb" remove_file "#{self.class.source_root}/create_universal_track_manager_tables.rb-staged" end |
#migration_version ⇒ Object
85 86 87 |
# File 'lib/generators/universal_track_manager/install_generator.rb', line 85 def migration_version "[#{ActiveRecord::Migration.current_version}]" if ActiveRecord::Migration.respond_to?(:current_version) end |