Class: AwesomeExplain::Config
- Inherits:
-
Object
- Object
- AwesomeExplain::Config
- Includes:
- Singleton
- Defined in:
- lib/awesome_explain/config.rb
Constant Summary collapse
- DEFAULT_DB_NAME =
:awesome_explain
- POSTGRES_DEV_DBNAME =
'awesome_explain_development'
- POSTGRES_DEFAULT_HOST =
'localhost'
- POSTGRES_DEFAULT_USERNAME =
'postgres'
- POSTGRES_DEFAULT_PASSWORD =
'postgres'
- DEFAULT_DB_PATH =
'./log'
Instance Attribute Summary collapse
-
#active_record_enabled ⇒ Object
(also: #active_record_enabled?)
Returns the value of attribute active_record_enabled.
-
#adapter ⇒ Object
Returns the value of attribute adapter.
-
#app_name ⇒ Object
Returns the value of attribute app_name.
-
#db_name ⇒ Object
Returns the value of attribute db_name.
-
#db_path ⇒ Object
Returns the value of attribute db_path.
-
#enabled ⇒ Object
(also: #enabled?)
Returns the value of attribute enabled.
-
#include_full_plan ⇒ Object
Returns the value of attribute include_full_plan.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#logs ⇒ Object
readonly
Returns the value of attribute logs.
-
#max_limit ⇒ Object
Returns the value of attribute max_limit.
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
-
#rails_path ⇒ Object
Returns the value of attribute rails_path.
Class Method Summary collapse
Instance Method Summary collapse
- #connection ⇒ Object
- #db_config ⇒ Object
- #init ⇒ Object
- #postgres_config ⇒ Object
- #postgres_host ⇒ Object
- #postgres_host=(value = 'localhost') ⇒ Object
- #postgres_password ⇒ Object
- #postgres_password=(value = 'postgres') ⇒ Object
- #postgres_username ⇒ Object
- #postgres_username=(value = 'postgres') ⇒ Object
- #sqlite3_config ⇒ Object
Instance Attribute Details
#active_record_enabled ⇒ Object Also known as: active_record_enabled?
Returns the value of attribute active_record_enabled.
4 5 6 |
# File 'lib/awesome_explain/config.rb', line 4 def active_record_enabled @active_record_enabled end |
#adapter ⇒ Object
Returns the value of attribute adapter.
4 5 6 |
# File 'lib/awesome_explain/config.rb', line 4 def adapter @adapter end |
#app_name ⇒ Object
Returns the value of attribute app_name.
4 5 6 |
# File 'lib/awesome_explain/config.rb', line 4 def app_name @app_name end |
#db_name ⇒ Object
Returns the value of attribute db_name.
4 5 6 |
# File 'lib/awesome_explain/config.rb', line 4 def db_name @db_name end |
#db_path ⇒ Object
Returns the value of attribute db_path.
4 5 6 |
# File 'lib/awesome_explain/config.rb', line 4 def db_path @db_path end |
#enabled ⇒ Object Also known as: enabled?
Returns the value of attribute enabled.
4 5 6 |
# File 'lib/awesome_explain/config.rb', line 4 def enabled @enabled end |
#include_full_plan ⇒ Object
Returns the value of attribute include_full_plan.
4 5 6 |
# File 'lib/awesome_explain/config.rb', line 4 def include_full_plan @include_full_plan end |
#logger ⇒ Object
Returns the value of attribute logger.
4 5 6 |
# File 'lib/awesome_explain/config.rb', line 4 def logger @logger end |
#logs ⇒ Object (readonly)
Returns the value of attribute logs.
4 5 6 |
# File 'lib/awesome_explain/config.rb', line 4 def logs @logs end |
#max_limit ⇒ Object
Returns the value of attribute max_limit.
4 5 6 |
# File 'lib/awesome_explain/config.rb', line 4 def max_limit @max_limit end |
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
4 5 6 |
# File 'lib/awesome_explain/config.rb', line 4 def queue @queue end |
#rails_path ⇒ Object
Returns the value of attribute rails_path.
4 5 6 |
# File 'lib/awesome_explain/config.rb', line 4 def rails_path @rails_path end |
Class Method Details
.configure(&block) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/awesome_explain/config.rb', line 27 def self.configure(&block) raise NoBlockGivenException unless block_given? instance = Config.instance instance.instance_eval(&block) instance.init instance end |
.rails4? ⇒ Boolean
128 129 130 |
# File 'lib/awesome_explain/config.rb', line 128 def self.rails4? Rails.version.start_with? '4' end |
Instance Method Details
#connection ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/awesome_explain/config.rb', line 75 def connection # TODO: Improve this condition if AwesomeExplain::Config.rails4? connection = ::ActiveRecord::Base.connection_handler.connection_pools.first.last.connection else connection = ::ActiveRecord::Base.connection_handler.connection_pools.select do |cp| !cp.connection.current_database.match(/awesome_explain/) end.first.connection end connection end |
#db_config ⇒ Object
88 89 90 |
# File 'lib/awesome_explain/config.rb', line 88 def db_config adapter == :postgres ? postgres_config : sqlite3_config end |
#init ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/awesome_explain/config.rb', line 37 def init return unless enabled @logs = [] if Rails.env.development? # Misc ActiveSupport::Notifications.subscribe 'start_processing.action_controller' do |*args| data = args. unless data[:controller] =~ /AwesomeExplain/ || data[:controller] =~ /ErrorsController/ || data[:path] =~ /awesome_explain/ Thread.current[:ae_controller_data] = data end Thread.current[:ae_session_id] = SecureRandom.uuid end ActiveSupport::Notifications.subscribe 'process_action.action_controller' do |*args| Thread.current[:ae_session_id] = nil end # Mongoid if Rails.const_defined?('Mongo') && Rails.const_defined?('Mongoid') command_subscribers = Mongo::Monitoring::Global.subscribers.dig('Command') if command_subscribers.nil? || !command_subscribers.collect(&:class).include?(AwesomeExplain::Subscribers::CommandSubscriber) command_subscriber = AwesomeExplain::Subscribers::CommandSubscriber.new begin Mongoid.default_client.subscribe(Mongo::Monitoring::COMMAND, command_subscriber) rescue => exception Mongo::Monitoring::Global.subscribe(Mongo::Monitoring::COMMAND, command_subscriber) end end end # ActiveRecord if active_record_enabled ::AwesomeExplain::Subscribers::ActiveRecordSubscriber.attach_to :active_record end end end |
#postgres_config ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/awesome_explain/config.rb', line 92 def postgres_config { ae_development: { adapter: 'postgresql', encoding: 'utf8', host: postgres_host || POSTGRES_DEFAULT_HOST, database: POSTGRES_DEV_DBNAME, username: postgres_username || POSTGRES_DEFAULT_USERNAME, password: postgres_password || POSTGRES_DEFAULT_PASSWORD, pool: 5, timeout: 5000, }, ae_staging: { adapter: 'postgresql', encoding: 'utf8', host: postgres_host || POSTGRES_DEFAULT_HOST, database: POSTGRES_DEV_DBNAME, username: postgres_username || POSTGRES_DEFAULT_USERNAME, password: postgres_password || POSTGRES_DEFAULT_PASSWORD, pool: 5, timeout: 5000, } }.with_indifferent_access["ae_#{Rails.env}"] end |
#postgres_host ⇒ Object
176 177 178 |
# File 'lib/awesome_explain/config.rb', line 176 def postgres_host @postgres_host || 'localhost' end |
#postgres_host=(value = 'localhost') ⇒ Object
172 173 174 |
# File 'lib/awesome_explain/config.rb', line 172 def postgres_host=(value = 'localhost') @postgres_host = value end |
#postgres_password ⇒ Object
192 193 194 |
# File 'lib/awesome_explain/config.rb', line 192 def postgres_password @postgres_password || 'postgres' end |
#postgres_password=(value = 'postgres') ⇒ Object
188 189 190 |
# File 'lib/awesome_explain/config.rb', line 188 def postgres_password=(value = 'postgres') @postgres_password = value end |
#postgres_username ⇒ Object
184 185 186 |
# File 'lib/awesome_explain/config.rb', line 184 def postgres_username @postgres_username || 'postgres' end |
#postgres_username=(value = 'postgres') ⇒ Object
180 181 182 |
# File 'lib/awesome_explain/config.rb', line 180 def postgres_username=(value = 'postgres') @postgres_username = value end |
#sqlite3_config ⇒ Object
117 118 119 120 121 122 123 124 125 126 |
# File 'lib/awesome_explain/config.rb', line 117 def sqlite3_config { ae_development: { adapter: 'sqlite3', database: "#{db_path || './log'}/ae.db", pool: 5, timeout: 5000, } }.with_indifferent_access["ae_#{Rails.env}"] end |