lib/hypershield.rb in hypershield-0.1.0 vs lib/hypershield.rb in hypershield-0.1.1
- old
+ new
@@ -1,21 +1,26 @@
+# dependencies
require "active_support"
+# modules
require "hypershield/migration"
-require "hypershield/railtie" if defined?(Rails)
require "hypershield/version"
+# integrations
+require "hypershield/engine" if defined?(Rails)
+
module Hypershield
class << self
- attr_accessor :schemas
+ attr_accessor :schemas, :log_sql
end
self.schemas = {
hypershield: {
hide: %w(encrypted password token secret),
show: []
}
}
+ self.log_sql = false
class << self
def drop_view(view)
schemas.each do |schema, _|
execute("DROP VIEW IF EXISTS #{quote_ident(schema)}.#{quote_ident(view)}")
@@ -65,11 +70,11 @@
end
private
def quiet_logging
- if ActiveRecord::Base.logger
+ if ActiveRecord::Base.logger && !log_sql
previous_level = ActiveRecord::Base.logger.level
begin
ActiveRecord::Base.logger.level = Logger::INFO
yield
ensure
@@ -111,14 +116,14 @@
information_schema.columns
WHERE
table_schema = #{schema}
SQL
- Hash[
- select_all(query)
- .group_by { |c| c["table_name"] }
- .map { |t, cs| [t, cs.sort_by { |c| c["ordinal_position"].to_i }.map { |c| c["column_name"] }] }
- ]
+ select_all(query.squish)
+ .map { |c| c.transform_keys(&:downcase) }
+ .group_by { |c| c["table_name"] }
+ .map { |t, cs| [t, cs.sort_by { |c| c["ordinal_position"].to_i }.map { |c| c["column_name"] }] }
+ .to_h
end
def select_all(sql)
connection.select_all(sql).to_a
end