Class: PgGnostic::TableDesc
- Inherits:
-
Object
- Object
- PgGnostic::TableDesc
- Defined in:
- lib/pg_gnostic/view_definition.rb
Instance Method Summary collapse
- #*(opts = {}) ⇒ Object
- #column_names ⇒ Object
-
#initialize(name) ⇒ TableDesc
constructor
A new instance of TableDesc.
- #quote_table_name(table) ⇒ Object
Constructor Details
#initialize(name) ⇒ TableDesc
Returns a new instance of TableDesc.
10 11 12 |
# File 'lib/pg_gnostic/view_definition.rb', line 10 def initialize(name) @name = quote_table_name(name) end |
Instance Method Details
#*(opts = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/pg_gnostic/view_definition.rb', line 18 def *(opts={}) table_name = opts[:table_name] || @name aliases = opts[:aliases] fields = column_names fields = fields - opts[:exclude].flatten if opts[:exclude] fields.map do |f| line="#{table_name}.#{f}" line<< " AS #{aliases[f]}" if aliases && aliases[f] line end.join("\n,") end |
#column_names ⇒ Object
6 7 8 9 |
# File 'lib/pg_gnostic/view_definition.rb', line 6 def column_names @columns || @columns = ActiveRecord::Base.connection.columns(@name).map{|c| c.name} @columns end |
#quote_table_name(table) ⇒ Object
14 15 16 |
# File 'lib/pg_gnostic/view_definition.rb', line 14 def quote_table_name(table) ActiveRecord::Base.connection.quote_table_name(table) end |