Class: Steamer
- Inherits:
-
Object
- Object
- Steamer
- Defined in:
- lib/steamer.rb
Instance Attribute Summary collapse
-
#model_files ⇒ Object
Returns the value of attribute model_files.
-
#model_reflections ⇒ Object
Returns the value of attribute model_reflections.
-
#models ⇒ Object
Returns the value of attribute models.
-
#source_db ⇒ Object
Returns the value of attribute source_db.
-
#source_db_connection ⇒ Object
Returns the value of attribute source_db_connection.
Instance Method Summary collapse
-
#connect ⇒ Object
assuming sqlite3 db at the moment.
- #get_model_files(root_dir = "./app/models/*") ⇒ Object
-
#initialize ⇒ Steamer
constructor
A new instance of Steamer.
- #reset_tables ⇒ Object
- #setup_models ⇒ Object
- #write_all_tables ⇒ Object
-
#write_table(table) ⇒ Object
protected?.
Constructor Details
#initialize ⇒ Steamer
Returns a new instance of Steamer.
11 12 13 |
# File 'lib/steamer.rb', line 11 def initialize connect end |
Instance Attribute Details
#model_files ⇒ Object
Returns the value of attribute model_files.
6 7 8 |
# File 'lib/steamer.rb', line 6 def model_files @model_files end |
#model_reflections ⇒ Object
Returns the value of attribute model_reflections.
6 7 8 |
# File 'lib/steamer.rb', line 6 def model_reflections @model_reflections end |
#models ⇒ Object
Returns the value of attribute models.
6 7 8 |
# File 'lib/steamer.rb', line 6 def models @models end |
#source_db ⇒ Object
Returns the value of attribute source_db.
6 7 8 |
# File 'lib/steamer.rb', line 6 def source_db @source_db end |
#source_db_connection ⇒ Object
Returns the value of attribute source_db_connection.
6 7 8 |
# File 'lib/steamer.rb', line 6 def source_db_connection @source_db_connection end |
Instance Method Details
#connect ⇒ Object
assuming sqlite3 db at the moment
15 16 17 18 19 20 21 22 23 |
# File 'lib/steamer.rb', line 15 def connect # assuming sqlite3 db at the moment @source_db_name = Dir[File.join("./*/development.sqlite3")].first @destination_db_name = Dir[File.join("./*/test.sqlite3")].first # read from sqlite3 db @source_db= ActiveRecord::Base.establish_connection({:adapter => "sqlite3", :database => @source_db_name}) @source_db_connection = @source_db.connection @source_db.connected? end |
#get_model_files(root_dir = "./app/models/*") ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/steamer.rb', line 69 def get_model_files(root_dir = "./app/models/*") temp_arr = [] Dir[File.join(root_dir)].each do |tok| if File.directory?(tok) temp_arr = temp_arr + get_model_files(tok.concat("/*")) else temp_arr.push tok end end return temp_arr end |
#reset_tables ⇒ Object
63 64 65 66 67 |
# File 'lib/steamer.rb', line 63 def reset_tables # drop all tables, # write_all_tables end |
#setup_models ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/steamer.rb', line 25 def setup_models # get all of the models, store in an Array @models = [] Kernel.subclasses_of(ActiveRecord::Base).each do |cl| if !cl.to_s.include?('ActiveRecord') @models.push cl end end ## now I have all the models by name... construct a datastructure to hold them all ## once that is done, I can write them to the database... @model_reflections = {} begin @models.each do |model| # if (Kernel.subclasses_of(ActiveRecord::Base).member?(model)) @model_reflections[:model] = eval("#{model}.reflections") # end end rescue NameError => msg puts "sorry, #{msg}" end end |
#write_all_tables ⇒ Object
49 50 51 52 53 |
# File 'lib/steamer.rb', line 49 def write_all_tables # for each table write_table(table) # write associations to the tables (i.e. the foreign keys) end |
#write_table(table) ⇒ Object
protected?
55 56 57 58 59 60 61 |
# File 'lib/steamer.rb', line 55 def write_table(table) # protected? # locate the model in @models # get a connection to the table # write to the table based on its types end |