Skip to content

Commit

Permalink
Renamed Adapter#nonview_tables to #base_tables with an alias to the o…
Browse files Browse the repository at this point in the history
…lder name.
  • Loading branch information
mschuerig committed Apr 7, 2009
1 parent 1ca832c commit 923e1d2
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 12 deletions.
1 change: 0 additions & 1 deletion TODO
@@ -1,3 +1,2 @@

- Use pre-existing Adapter#supports_views? where possible
- Rename #nonview_tables to #base_tables
5 changes: 3 additions & 2 deletions lib/rails_sql_views/connection_adapters/mysql_adapter.rb
Expand Up @@ -12,11 +12,12 @@ def supports_views?
true
end

def nonview_tables(name = nil) #:nodoc:
def base_tables(name = nil) #:nodoc:
tables = []
execute("SHOW FULL TABLES WHERE TABLE_TYPE='BASE TABLE'").each{|row| tables << row[0]}
tables
end
alias nonview_tables base_tables

def views(name = nil) #:nodoc:
views = []
Expand All @@ -26,7 +27,7 @@ def views(name = nil) #:nodoc:

def structure_dump
structure = ""
nonview_tables.each do |table|
base_tables.each do |table|
structure += select_one("SHOW CREATE TABLE #{quote_table_name(table)}")["Create Table"] + ";\n\n"
end

Expand Down
3 changes: 2 additions & 1 deletion lib/rails_sql_views/connection_adapters/oci_adapter.rb
Expand Up @@ -6,11 +6,12 @@ def supports_views?
true
end

def nonview_tables(name = nil) #:nodoc:
def base_tables(name = nil) #:nodoc:
tables = []
execute("SELECT TABLE_NAME FROM USER_TABLES", name).each { |row| tables << row[0] }
tables
end
alias nonview_tables base_tables

def views(name = nil) #:nodoc:
views = []
Expand Down
3 changes: 2 additions & 1 deletion lib/rails_sql_views/connection_adapters/oracle_adapter.rb
Expand Up @@ -6,11 +6,12 @@ def supports_views?
true
end

def nonview_tables(name = nil) #:nodoc:
def base_tables(name = nil) #:nodoc:
tables = []
execute("SELECT TABLE_NAME FROM USER_TABLES", name).each { |row| tables << row[0] }
tables
end
alias nonview_tables base_tables

def views(name = nil) #:nodoc:
views = []
Expand Down
Expand Up @@ -20,7 +20,7 @@ def tables_with_views_included(name = nil)
query(q, name).map { |row| row[0] }
end

def nonview_tables(name = nil)
def base_tables(name = nil)
q = <<-SQL
SELECT table_name, table_type
FROM information_schema.tables
Expand All @@ -30,6 +30,7 @@ def nonview_tables(name = nil)

query(q, name).map { |row| row[0] }
end
alias nonview_tables base_tables

def views(name = nil) #:nodoc:
q = <<-SQL
Expand Down
3 changes: 2 additions & 1 deletion lib/rails_sql_views/connection_adapters/sqlite_adapter.rb
Expand Up @@ -17,7 +17,7 @@ def tables(name = nil) #:nodoc:
end
end

def nonview_tables(name = nil)
def base_tables(name = nil)
sql = <<-SQL
SELECT name
FROM sqlite_master
Expand All @@ -28,6 +28,7 @@ def nonview_tables(name = nil)
row[0]
end
end
alias nonview_tables base_tables

def views(name = nil)
sql = <<-SQL
Expand Down
3 changes: 2 additions & 1 deletion lib/rails_sql_views/connection_adapters/sqlserver_adapter.rb
Expand Up @@ -7,10 +7,11 @@ def supports_views?
end

# Get all of the non-view tables from the currently connected schema
def nonview_tables(name = nil)
def base_tables(name = nil)
# this is untested
select_values("SELECT table_name FROM information_schema.tables", name)
end
alias nonview_tables base_tables

# Returns all the view names from the currently connected schema.
def views(name = nil)
Expand Down
2 changes: 1 addition & 1 deletion lib/rails_sql_views/schema_dumper.rb
Expand Up @@ -81,7 +81,7 @@ def view(view, stream)
end

def tables_with_views_excluded(stream)
@connection.nonview_tables.sort.each do |tbl|
@connection.base_tables.sort.each do |tbl|
next if [ActiveRecord::Migrator.schema_migrations_table_name, ignore_tables].flatten.any? do |ignored|
case ignored
when String then tbl == ignored
Expand Down
2 changes: 1 addition & 1 deletion test/README
Expand Up @@ -25,7 +25,7 @@ If you would like to implement an adapter, it should go in lib/rails_sql_views/c
of the other adapters currently implemented. Every adapter must implement the following methods:

supports_views?
nonview_tables(name = nil)
base_tables(name = nil)
views(name = nil)
view_select_statement(view, name=nil)

Expand Down
4 changes: 2 additions & 2 deletions test/adapter_test.rb
Expand Up @@ -12,9 +12,9 @@ def test_tables
found.delete(ActiveRecord::Migrator.schema_migrations_table_name)
assert_equal ["people", "people2", "places", "v_person"], found
end
def test_nonview_tables
def test_base_tables
create_view
found = ActiveRecord::Base.connection.nonview_tables.sort
found = ActiveRecord::Base.connection.base_tables.sort
found.delete(ActiveRecord::Migrator.schema_migrations_table_name)
assert_equal ["people", "people2", "places"], found
end
Expand Down

0 comments on commit 923e1d2

Please sign in to comment.