Module: MigrationComments::ActiveRecord::ConnectionAdapters::AbstractSQLiteAdapter
- Included in:
- SQLite3Adapter, SQLiteAdapter
- Defined in:
- lib/migration_comments/active_record/connection_adapters/abstract_sqlite_adapter.rb
Instance Method Summary collapse
- #add_column_options!(sql, options) ⇒ Object
-
#change_column_with_migration_comments(table_name, column_name, type, options = {}) ⇒ Object
:nodoc:.
- #column_for(table_name, column_name) ⇒ Object
- #comment_sql(comment_definition) ⇒ Object
- #comments_supported? ⇒ Boolean
- #inline_comments? ⇒ Boolean
- #retrieve_column_comments(table_name, *column_names) ⇒ Object
- #retrieve_table_comment(table_name) ⇒ Object
- #set_column_comment(table_name, column_name, comment_text) ⇒ Object
- #set_table_comment(table_name, comment_text) ⇒ Object
Instance Method Details
#add_column_options!(sql, options) ⇒ Object
69 70 71 72 73 74 |
# File 'lib/migration_comments/active_record/connection_adapters/abstract_sqlite_adapter.rb', line 69 def (sql, ) super(sql, ) if .keys.include?(:comment) sql << CommentDefinition.new(self, nil, nil, [:comment]).to_sql end end |
#change_column_with_migration_comments(table_name, column_name, type, options = {}) ⇒ Object
:nodoc:
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/migration_comments/active_record/connection_adapters/abstract_sqlite_adapter.rb', line 40 def change_column_with_migration_comments(table_name, column_name, type, = {}) #:nodoc: adapter = self alter_table(table_name) do |definition| include_default = () definition[column_name].instance_eval do self.type = type self.limit = [:limit] if .include?(:limit) self.default = [:default] if include_default self.null = [:null] if .include?(:null) self.precision = [:precision] if .include?(:precision) self.scale = [:scale] if .include?(:scale) self.comment = CommentDefinition.new(adapter, table_name, column_name, [:comment]) if .include?(:comment) end end end |
#column_for(table_name, column_name) ⇒ Object
56 57 58 |
# File 'lib/migration_comments/active_record/connection_adapters/abstract_sqlite_adapter.rb', line 56 def column_for(table_name, column_name) columns(table_name).detect{|col| col.name == column_name.to_s} end |
#comment_sql(comment_definition) ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/migration_comments/active_record/connection_adapters/abstract_sqlite_adapter.rb', line 60 def comment_sql(comment_definition) if comment_definition.nil? || comment_definition.comment_text.blank? "" else " /*#{escaped_comment(comment_definition.comment_text)}*/" end end |
#comments_supported? ⇒ Boolean
3 4 5 |
# File 'lib/migration_comments/active_record/connection_adapters/abstract_sqlite_adapter.rb', line 3 def comments_supported? true end |
#inline_comments? ⇒ Boolean
7 8 9 |
# File 'lib/migration_comments/active_record/connection_adapters/abstract_sqlite_adapter.rb', line 7 def inline_comments? true end |
#retrieve_column_comments(table_name, *column_names) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/migration_comments/active_record/connection_adapters/abstract_sqlite_adapter.rb', line 29 def retrieve_column_comments(table_name, *column_names) if column_names.empty? return columns(table_name).inject({}) { |m, v| m[v.name.to_sym] = v.comment if v.comment.present?; m } end result = select_rows(lookup_comment_sql(table_name)) result[0][0] =~ /^CREATE (?:TEMPORARY )?TABLE "\w*" [^\(]*(?:\/\*.*\*\/ )?\((.*)\)[^\)]*$/ col_defs = $1 comment_matches = col_defs.scan(/"([^",]+)"[^,]*\/\*(.+?)\*\//) comment_matches.inject({}){|m, row| m[row.first.to_sym] = row.last; m} end |
#retrieve_table_comment(table_name) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/migration_comments/active_record/connection_adapters/abstract_sqlite_adapter.rb', line 22 def retrieve_table_comment(table_name) result = select_rows(lookup_comment_sql(table_name)) if result[0][0] =~ /CREATE (?:TEMPORARY )?TABLE #{quote_table_name table_name} [^\(]*\/\*(.*)\*\/ \(/ $1 end end |
#set_column_comment(table_name, column_name, comment_text) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/migration_comments/active_record/connection_adapters/abstract_sqlite_adapter.rb', line 15 def set_column_comment(table_name, column_name, comment_text) sql_type = primary_key(table_name) == column_name.to_s ? :primary_key : column_for(table_name, column_name).sql_type change_column table_name, column_name, sql_type, :comment => comment_text end |
#set_table_comment(table_name, comment_text) ⇒ Object
11 12 13 |
# File 'lib/migration_comments/active_record/connection_adapters/abstract_sqlite_adapter.rb', line 11 def set_table_comment(table_name, comment_text) alter_table(table_name, :comment => comment_text) end |