active_table 0.0.6 → 0.1.0
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/Rakefile +1 -1
- data/lib/active_table/base.rb +9 -0
- data/lib/active_table/railtie.rb +5 -0
- data/lib/active_table/version.rb +1 -1
- data/spec/active_table_spec.rb +10 -0
- metadata +1 -1
data/Rakefile
CHANGED
@@ -22,7 +22,7 @@ autotest_styles = {
|
|
22
22
|
|
23
23
|
desc "Run all specs against Rspec 1 and 2"
|
24
24
|
task "spec" do
|
25
|
-
in_environment.call('rspec1', 'spec spec')
|
25
|
+
in_environment.call('rspec1', 'spec spec')
|
26
26
|
in_environment.call('rspec2', 'rspec spec')
|
27
27
|
end
|
28
28
|
|
data/lib/active_table/base.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
module ActiveTable
|
2
2
|
class Base < ActiveRecord::Base
|
3
|
+
@@detected_files = []
|
3
4
|
@@insert_statements = []
|
4
5
|
@@table_list = []
|
5
6
|
|
@@ -26,6 +27,14 @@ module ActiveTable
|
|
26
27
|
@@table_list
|
27
28
|
end
|
28
29
|
|
30
|
+
def self.add_detected_file(file)
|
31
|
+
@@detected_files << file
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.detected_files
|
35
|
+
@@detected_files
|
36
|
+
end
|
37
|
+
|
29
38
|
def self.create_table!
|
30
39
|
connection = ActiveRecord::Base.connection
|
31
40
|
connection.execute "DROP TABLE IF EXISTS #{connection.quote_table_name(@table[:name])}"
|
data/lib/active_table/railtie.rb
CHANGED
@@ -1,9 +1,14 @@
|
|
1
|
+
require "pathname"
|
2
|
+
|
1
3
|
module ActiveTable
|
2
4
|
class Railtie < Rails::Railtie
|
3
5
|
initializer "active_table", :after => "casebook2_extensions" do
|
6
|
+
model_path = Pathname.new("#{Rails.root}/app/models")
|
4
7
|
Dir.glob("#{Rails.root}/app/models/**/*.rb").each do |file|
|
5
8
|
File.open(file).readlines.each do |line|
|
6
9
|
if (line =~ /ActiveTable::Base/)
|
10
|
+
file_path = Pathname.new(file)
|
11
|
+
ActiveTable::Base.add_detected_file(file_path.relative_path_from(model_path).to_s)
|
7
12
|
require file if Rails.env.dev?
|
8
13
|
next
|
9
14
|
end
|
data/lib/active_table/version.rb
CHANGED
data/spec/active_table_spec.rb
CHANGED
@@ -70,6 +70,16 @@ describe "a model created with active_table" do
|
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
|
+
context "#detected_files" do
|
74
|
+
it "should return a list of model files detected during initialization" do
|
75
|
+
ActiveTable::Base.add_detected_file("awesome/model.rb")
|
76
|
+
ActiveTable::Base.add_detected_file("foo/bar.rb")
|
77
|
+
|
78
|
+
ActiveTable::Base.detected_files.size.should == 2
|
79
|
+
ActiveTable::Base.detected_files.should include("awesome/model.rb", "foo/bar.rb")
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
73
83
|
context "#seed!" do
|
74
84
|
it "should attempt to re-insert all rows" do
|
75
85
|
class AwesomeModel < ActiveTable::Base
|