Class: PeriscopeRails::Config
- Inherits:
-
Object
- Object
- PeriscopeRails::Config
- Defined in:
- lib/periscope_rails/config.rb
Constant Summary collapse
- 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 =
2000- @@max_size =
@@max_rows * 500
Class Method Summary collapse
- .block_expensive_queries? ⇒ Boolean
- .check_password(password) ⇒ Object
- .get_active_record ⇒ Object
- .matches_filter(text) ⇒ Object
- .max_rows ⇒ Object
- .max_size ⇒ Object
- .set_filter(options) ⇒ Object
- .set_password(password) ⇒ Object
- .use_db_credentials(options) ⇒ Object
Class Method Details
.block_expensive_queries? ⇒ Boolean
54 |
# File 'lib/periscope_rails/config.rb', line 54 def self.block_expensive_queries?; return @@block_expensive_queries; end |
.check_password(password) ⇒ Object
30 31 32 |
# File 'lib/periscope_rails/config.rb', line 30 def self.check_password(password) return @@password == password end |
.get_active_record ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/periscope_rails/config.rb', line 45 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 |
.matches_filter(text) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/periscope_rails/config.rb', line 34 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 |
.max_rows ⇒ Object
55 |
# File 'lib/periscope_rails/config.rb', line 55 def self.max_rows; return @@max_rows; end |
.max_size ⇒ Object
56 |
# File 'lib/periscope_rails/config.rb', line 56 def self.max_size; return @@max_size; end |
.set_filter(options) ⇒ Object
20 21 22 23 |
# File 'lib/periscope_rails/config.rb', line 20 def self.set_filter() @@filter = [:filter] if [:filter] and [:filter].class == Array @@filter_matchtype = [:matchtype] if .has_key?(:matchtype) and VALID_MATCHTYPES.include?([:matchtype]) end |
.set_password(password) ⇒ Object
16 17 18 |
# File 'lib/periscope_rails/config.rb', line 16 def self.set_password(password) @@password = password end |
.use_db_credentials(options) ⇒ Object
25 26 27 28 |
# File 'lib/periscope_rails/config.rb', line 25 def self.use_db_credentials() @@db_username = [:username] if [:username] and [:username].class == String @@db_password = [:password] if [:password] and [:password].class == String end |