Module: Preact
- Defined in:
- lib/preact.rb,
lib/preact/client.rb,
lib/preact/version.rb,
lib/preact/configuration.rb,
lib/preact/background_logger.rb,
lib/preact/objects/action_link.rb,
lib/preact/rails/controllers/helpers.rb
Defined Under Namespace
Modules: Controllers, Rails, Sidekiq, Warden Classes: ActionLink, ApiObject, BackgroundLogger, Client, Configuration, Event
Constant Summary collapse
- VERSION =
"1.1.1"
Class Attribute Summary collapse
-
.configuration ⇒ Object
A Preact configuration object.
-
.default_client ⇒ Object
Returns the value of attribute default_client.
-
.logger ⇒ Object
Returns the value of attribute logger.
Class Method Summary collapse
- .client ⇒ Object
-
.configure {|configuration| ... } ⇒ Object
Call this method to modify the configuration in your initializers.
- .log_account_event(event, account) ⇒ Object
- .log_event(user, event, account = nil) ⇒ Object
- .update_account(account) ⇒ Object
- .update_person(user) ⇒ Object
Class Attribute Details
.configuration ⇒ Object
A Preact configuration object. Must like a hash and return sensible values for all Preact configuration options. See Preact::Configuration
13 14 15 |
# File 'lib/preact.rb', line 13 def configuration @configuration end |
.default_client ⇒ Object
Returns the value of attribute default_client.
15 16 17 |
# File 'lib/preact.rb', line 15 def default_client @default_client end |
.logger ⇒ Object
Returns the value of attribute logger.
17 18 19 |
# File 'lib/preact.rb', line 17 def logger @logger end |
Class Method Details
.client ⇒ Object
155 156 157 |
# File 'lib/preact.rb', line 155 def client self.default_client ||= Client.new end |
.configure {|configuration| ... } ⇒ Object
Call this method to modify the configuration in your initializers
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/preact.rb', line 20 def configure defaults = {} # try to use the yml config if we're on rails and it exists if defined? ::Rails config_yml = File.join(::Rails.root.to_s,"config","preact.yml") if File.exists?(config_yml) defaults = YAML::load_file(config_yml)[::Rails.env] end end self.configuration ||= Configuration.new(defaults) yield(configuration) if block_given? # Configure logger. Default to use Rails self.logger ||= configuration.logger || (defined?(::Rails) ? ::Rails.logger : Logger.new(STDOUT)) if defined? ::Rails # load the rails extensions require 'preact/rails' # never log things if we're in Rails test environment configuration.disabled = true if ::Rails.env.test? end if defined? ::Warden # if we're using Warden (Devise), load those extensions require 'preact/warden' end if defined? ::Preact::Sidekiq # set up the default queue for the sidekiq job ::Preact::Sidekiq::PreactLoggingWorker.(:queue => self.configuration.sidekiq_queue) end end |
.log_account_event(event, account) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/preact.rb', line 94 def log_account_event(event, account) # Don't send requests when disabled if configuration.nil? || configuration.disabled? || !configuration.valid? logger.info "[Preact] Logging is disabled, not logging event" return nil elsif account.nil? logger.error "[Preact] No account specified, not logging event" return nil elsif event.nil? logger.error "[Preact] No event specified, not logging event" return nil end if event.is_a?(String) preact_event = { :name => event, :timestamp => Time.now.to_f } elsif event.is_a?(Hash) preact_event = event else raise StandardError.new "Unknown event class, must pass a string event name or event hash." end # attach the account info to the event preact_event[:account] = configuration.convert_to_account(account) preact_event[:klass] = "accountevent" send_log(nil, preact_event) end |
.log_event(user, event, account = nil) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/preact.rb', line 58 def log_event(user, event, account = nil) # Don't send requests when disabled if configuration.nil? || configuration.disabled? || !configuration.valid? logger.info "[Preact] Logging is disabled, not logging event" return nil elsif user.nil? logger.error "[Preact] No person specified, not logging event" return nil elsif event.nil? logger.error "[Preact] No event specified, not logging event" return nil end if event.is_a?(String) preact_event = { :name => event, :timestamp => Time.now.to_f } elsif event.is_a?(Hash) preact_event = event else raise StandardError.new "Unknown event class, must pass a string event name or event hash." end if account # attach the account info to the event preact_event[:account] = configuration.convert_to_account(account) end person = configuration.convert_to_person(user) preact_event[:klass] = "actionevent" send_log(person, preact_event) end |
.update_account(account) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/preact.rb', line 140 def update_account(account) # Don't send requests when disabled if configuration.nil? || configuration.disabled? || !configuration.valid? logger.info "[Preact] Logging is disabled, not updating account" return nil elsif account.nil? logger.info "[Preact] No account specified, not updating account" return nil end account = configuration.convert_to_account(account) client.update_account(account) end |
.update_person(user) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/preact.rb', line 125 def update_person(user) # Don't send requests when disabled if configuration.nil? || configuration.disabled? || !configuration.valid? logger.info "[Preact] Logging is disabled, not logging event" return nil elsif user.nil? logger.info "[Preact] No person specified, not logging event" return nil end person = configuration.convert_to_person(user) client.update_person(person) end |