davidtrogers-steamer 0.1.3.0 → 0.1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +11 -0
- data/lib/steamer.rb +33 -9
- data/steamer.gemspec +1 -1
- metadata +1 -1
data/README
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
ToDo:
|
|
2
2
|
- Done - get it working with sqlite3
|
|
3
|
+
- read in all models
|
|
4
|
+
- record attribute information
|
|
5
|
+
- record association information
|
|
6
|
+
|
|
7
|
+
Discussion:
|
|
8
|
+
There are definitely a couple of different ways I can go with this:
|
|
9
|
+
one, I can create the factory files via meta programming, and have them loaded as usual using begin-end block in env.rb (slow but db agnostic)
|
|
10
|
+
two, I can create the database from scratch and roll it back somehow whenever you tell it to roll back (faster but need to know the database)
|
|
11
|
+
three, I can somehow get into the model instances that are created in the development environment...not sure how to do this from 'RAILS_ENV=test'
|
|
12
|
+
four, I can use ActiveRecord::Base class methods to record attributes and associations of the db tables (i.e. reflect_on_association), and then create the test database on the fly whenever needed. (this sounds like the best solution, so I can completely forget about factory_girl, and I am not reinventing the activerecord wheel by trying to parse model files, yet I am properly recording my associations, creating the test database correctly, and reusing it as many times as I want) (maybe there's a formal rollback method for the test database connection, I think I saw one...) (lets just hope I can use all of the AR class methods from the test env when needed. Update: yes!!! Even without tables created and filled out w/AR, I can use class methods to study/use associations and attributes...fantastic)
|
|
13
|
+
|
|
3
14
|
- May want to read from the models... that way, we can stay db agnostic...
|
|
4
15
|
- can we use reflect_on_association??? is this too hard?
|
|
5
16
|
- how can we structure this so that it makes sense? are we replicating effort?
|
data/lib/steamer.rb
CHANGED
|
@@ -4,12 +4,11 @@ require 'sqlite3'
|
|
|
4
4
|
class Steamer
|
|
5
5
|
|
|
6
6
|
attr_accessor :source_db_connection,
|
|
7
|
-
:source_db,
|
|
8
|
-
|
|
7
|
+
:source_db, :models,
|
|
8
|
+
:model_files
|
|
9
9
|
|
|
10
10
|
def initialize
|
|
11
11
|
connect
|
|
12
|
-
@magic = "hello"
|
|
13
12
|
end
|
|
14
13
|
|
|
15
14
|
def connect # assuming sqlite3 db at the moment
|
|
@@ -22,10 +21,25 @@ class Steamer
|
|
|
22
21
|
@source_db.connected?
|
|
23
22
|
end
|
|
24
23
|
|
|
25
|
-
def
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
def setup_models
|
|
25
|
+
# get all of the models, store in an Array
|
|
26
|
+
@models = []
|
|
27
|
+
@model_files = get_model_files #Dir[File.join(RAILS_ROOT + "/app/models/*/*")]
|
|
28
|
+
|
|
29
|
+
# for each one, get file name
|
|
30
|
+
#@models.push File.basename(file,"*.rb").camelize
|
|
31
|
+
@model_files.each do |file|
|
|
32
|
+
file.sub!("./app/models/","")
|
|
33
|
+
if file.split("/").size>1
|
|
34
|
+
@models.push "#{file.split('/')[0].camelize}::#{file.split('/')[1].camelize.chomp(".rb")}"
|
|
35
|
+
else
|
|
36
|
+
@models.push file.camelize.chomp(".rb")
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# now I have all the models by name... construct a datastructure to hold them all
|
|
41
|
+
# once that is done, I can write them to the database...
|
|
42
|
+
|
|
29
43
|
# This shows the columns for a particular table
|
|
30
44
|
# >> puts s.source_db_connection.columns("work_efforts").each {|a| puts a.inspect}
|
|
31
45
|
|
|
@@ -36,7 +50,17 @@ class Steamer
|
|
|
36
50
|
# >> puts s.source_db_connection.table_structure("work_efforts")
|
|
37
51
|
end
|
|
38
52
|
|
|
39
|
-
|
|
40
|
-
|
|
53
|
+
def get_model_files(root_dir = "./app/models/*")
|
|
54
|
+
temp_arr = []
|
|
55
|
+
Dir[File.join(root_dir)].each do |tok|
|
|
56
|
+
if File.directory?(tok)
|
|
57
|
+
temp_arr = temp_arr + get_model_files(tok.concat("/*"))
|
|
58
|
+
else
|
|
59
|
+
temp_arr.push tok
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
return temp_arr
|
|
63
|
+
end
|
|
64
|
+
|
|
41
65
|
end
|
|
42
66
|
|
data/steamer.gemspec
CHANGED