pboling / seed_migration

Seed Migration

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Configuration variables can conflict with other modules

zaccari opened this issue · comments

The current configuration logic looks like this (in lib/seed_migration/engine.rb):

module SeedMigration

  class << self
    mattr_accessor :extend_native_migration_task
    mattr_accessor :migration_table_name
    mattr_accessor :ignore_ids
    mattr_accessor :update_seeds_file
    mattr_accessor :migrations_path
    mattr_accessor :use_strict_create

    self.migration_table_name = 'seed_migration_data_migrations' # Hardcoded, evil!
    self.extend_native_migration_task = false
    self.ignore_ids = false
    self.update_seeds_file = true
    self.migrations_path = 'data'
    self.use_strict_create = false
  end

  # ...
end

It looks like wrapping the variables with class << self can lead to conflicts with other modules that use the same approach:

$ rails c
2.2.3 :001 > SeedMigration.migration_table_name
 => "seed_migration_data_migrations"
2.2.3 :002 > module Foo
2.2.3 :003?>   class << self
2.2.3 :004?>     mattr_accessor :migration_table_name
2.2.3 :005?>     self.migration_table_name = 'foos'
2.2.3 :006?>     end
2.2.3 :007?>   end
 => "foos"
2.2.3 :008 > Foo.migration_table_name
 => "foos"
2.2.3 :009 > SeedMigration.migration_table_name
 => "foos"
2.2.3 :010 > SeedMigration.migration_table_name = 'hello_world'
 => "hello_world"
2.2.3 :011 > Foo.migration_table_name
 => "hello_world"