6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/constant_table_saver.rb', line 6
def constant_table(options = {})
options.assert_valid_keys(:name, :name_prefix, :name_suffix)
class_attribute :constant_table_options, :instance_writer => false
self.constant_table_options = options
if ActiveRecord::VERSION::MAJOR == 3
extend ActiveRecord3ClassMethods
else
extend ActiveRecord4ClassMethods
end
extend ClassMethods
extend NameClassMethods if constant_table_options[:name]
klass = defined?(ActiveRecord::FixtureSet) ? ActiveRecord::FixtureSet : ActiveRecord::Fixtures
class <<klass
def create_fixtures_with_constant_tables(*args)
create_fixtures_without_constant_tables(*args).tap { ConstantTableSaver.reset_all_caches }
end
def reset_cache_with_constant_tables(*args)
reset_cache_without_constant_tables(*args).tap { ConstantTableSaver.reset_all_caches }
end
alias_method_chain :create_fixtures, :constant_tables
alias_method_chain :reset_cache, :constant_tables
end unless klass.respond_to?(:create_fixtures_with_constant_tables)
end
|