module PARENT
base configurations
Constants
- Factory
Flextures
FactoryFilter is program to translateActiveRecord
data- VERSION
Private Class Methods
create_model(table_name)
click to toggle source
guessing ActiveRecord
Model name by table_name and create @params [String|Symbol] table_name @params [ActiveRecord::Base] model class
# File lib/flextures/flextures.rb, line 8 def self.create_model(table_name) # when Model is defined in FactoryFilter a = -> do f = Factory::FACTORIES[table_name.to_sym] f && f[:model] end # when program can guess Model name by table_name b = -> do begin table_name.singularize.camelize.constantize rescue => e nil end end # when cannot guess Model name c = -> do Class.new(ActiveRecord::Base){ |o| o.table_name=table_name } end a.call || b.call || c.call end
deletable_tables()
click to toggle source
@return [Array] flextures useable table names
# File lib/flextures/flextures.rb, line 39 def self.deletable_tables tables = ActiveRecord::Base.connection.data_sources Flextures::Configuration.ignore_tables.each { |name| tables.delete(name.to_s) } tables end
delete_tables(*tables)
click to toggle source
# File lib/flextures/flextures.rb, line 57 def self.delete_tables(*tables) tables.each do |name| # if 'name' variable is 'database view', raise error begin Class.new(ActiveRecord::Base){ |o| o.table_name= name }.delete_all rescue StandaraError => e end end end
init_tables()
click to toggle source
initialize table data
# File lib/flextures/flextures.rb, line 46 def self.init_tables tables = Flextures::deletable_tables tables.each do |name| # if 'name' variable is 'database view', raise error begin Class.new(ActiveRecord::Base){ |o| o.table_name= name }.delete_all rescue => e end end end
load_configurations()
click to toggle source
load configuration file, if file is exist
# File lib/flextures/flextures.rb, line 30 def self.load_configurations if defined?(Rails) and Rails.root [ File.join(Rails.root.to_path, "/config/flextures.factory.rb"), ].each { |fn| File.exist?(fn) && load(fn) } end end
table_tap(&dumper)
click to toggle source
It is debug method to use like 'tab' method @params [Proc] dumper write dump information
# File lib/flextures/flextures.rb, line 69 def self.table_tap(&dumper) tables = Flextures::deletable_tables tables.each do |name| # if 'name' variable is 'database view', raise error begin klass = Class.new(ActiveRecord::Base){ |o| o.table_name= name; } dumper.call klass rescue StandaraError => e end end end