lib/periscope_rails/config.rb in periscope_rails-0.0.8 vs lib/periscope_rails/config.rb in periscope_rails-0.0.9

- old
+ new

@@ -1,58 +1,58 @@ -module PeriscopeRails - class Config - VALID_MATCHTYPES = ['fuzzy', 'exact'] - - @@password = nil - @@filter = nil - @@filter_matchtype = 'fuzzy' - @@active_record = nil - @@db_username = nil - @@db_password = nil - - @@block_expensive_queries = true - @@max_rows = 500 - @@max_size = @@max_rows * 500 - - def self.set_password(password) - @@password = password - end - - def self.set_filter(options) - @@filter = options[:filter] if options[:filter] and options[:filter].class == Array - @@filter_matchtype = options[:matchtype] if options.has_key?(:matchtype) and VALID_MATCHTYPES.include?(options[:matchtype]) - end - - def self.use_db_credentials(options) - @@db_username = options[:username] if options[:username] and options[:username].class == String - @@db_password = options[:password] if options[:password] and options[:password].class == String - end - - def self.check_password(password) - return @@password == password - end - - def self.matches_filter(text) - filter = @@filter || Rails.application.config.filter_parameters - filter.each do |filtered_word| - if (@@filter_matchtype == 'fuzzy' and text.include?(filtered_word.to_s)) or - (@@filter_matchtype == 'exact' and text == filtered_word.to_s) - return true - end - end - return false - end - - def self.get_active_record - return ActiveRecord::Base if @@db_username.nil? - return @@active_record unless @@active_record.nil? - @@active_record = Class.new(ActiveRecord::Base) - config = ActiveRecord::Base.connection_config.merge({:username => @@db_username, :password => @@db_password}) - @@active_record.establish_connection(config) - return @@active_record - end - - def self.block_expensive_queries?; return @@block_expensive_queries; end - def self.max_rows; return @@max_rows; end - def self.max_size; return @@max_size; end - end -end +module PeriscopeRails + class Config + VALID_MATCHTYPES = ['fuzzy', 'exact'] + + @@password = nil + @@filter = nil + @@filter_matchtype = 'fuzzy' + @@active_record = nil + @@db_username = nil + @@db_password = nil + + @@block_expensive_queries = true + @@max_rows = 500 + @@max_size = @@max_rows * 500 + + def self.set_password(password) + @@password = password + end + + def self.set_filter(options) + @@filter = options[:filter] if options[:filter] and options[:filter].class == Array + @@filter_matchtype = options[:matchtype] if options.has_key?(:matchtype) and VALID_MATCHTYPES.include?(options[:matchtype]) + end + + def self.use_db_credentials(options) + @@db_username = options[:username] if options[:username] and options[:username].class == String + @@db_password = options[:password] if options[:password] and options[:password].class == String + end + + def self.check_password(password) + return @@password == password + end + + def self.matches_filter(text) + filter = @@filter || Rails.application.config.filter_parameters + filter.each do |filtered_word| + if (@@filter_matchtype == 'fuzzy' and text.include?(filtered_word.to_s)) or + (@@filter_matchtype == 'exact' and text == filtered_word.to_s) + return true + end + end + return false + end + + def self.get_active_record + return ActiveRecord::Base if @@db_username.nil? + return @@active_record unless @@active_record.nil? + @@active_record = Class.new(ActiveRecord::Base) + config = ActiveRecord::Base.connection_config.merge({:username => @@db_username, :password => @@db_password}) + @@active_record.establish_connection(config) + return @@active_record + end + + def self.block_expensive_queries?; return @@block_expensive_queries; end + def self.max_rows; return @@max_rows; end + def self.max_size; return @@max_size; end + end +end