Class: Preact::Configuration
- Inherits:
-
Object
- Object
- Preact::Configuration
- Defined in:
- lib/preact/configuration.rb
Instance Attribute Summary collapse
-
#account_builder ⇒ Object
Returns the value of attribute account_builder.
-
#autolog ⇒ Object
Returns the value of attribute autolog.
-
#autolog_ignored_actions ⇒ Object
Returns the value of attribute autolog_ignored_actions.
-
#base_path ⇒ Object
Returns the value of attribute base_path.
-
#code ⇒ Object
Preact credentials.
-
#current_account_getter ⇒ Object
Returns the value of attribute current_account_getter.
-
#current_user_getter ⇒ Object
Returns the value of attribute current_user_getter.
-
#disabled ⇒ Object
Default option settings.
-
#host ⇒ Object
Returns the value of attribute host.
-
#inject_javascript ⇒ Object
Returns the value of attribute inject_javascript.
-
#logger ⇒ Object
Logger settings.
-
#logging_mode ⇒ Object
Returns the value of attribute logging_mode.
-
#person_builder ⇒ Object
Returns the value of attribute person_builder.
-
#request_timeout ⇒ Object
Returns the value of attribute request_timeout.
-
#scheme ⇒ Object
The URL of the API server.
-
#secret ⇒ Object
Returns the value of attribute secret.
-
#sidekiq_queue ⇒ Object
Returns the value of attribute sidekiq_queue.
Instance Method Summary collapse
- #autolog_enabled? ⇒ Boolean
- #autolog_should_log?(controller, action) ⇒ Boolean
- #base_uri ⇒ Object
- #convert_to_account(account) ⇒ Object
- #convert_to_person(user) ⇒ Object
- #disabled? ⇒ Boolean
- #enabled? ⇒ Boolean
- #get_current_account(target) ⇒ Object
- #get_current_user(target) ⇒ Object
-
#initialize(defaults = {}) ⇒ Configuration
constructor
A new instance of Configuration.
- #inject_javascript? ⇒ Boolean
- #prepare_account_hash(account) ⇒ Object
- #prepare_event_hash(event) ⇒ Object
- #prepare_person_hash(person) ⇒ Object
- #user_agent ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(defaults = {}) ⇒ Configuration
Returns a new instance of Configuration.
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 57 58 |
# File 'lib/preact/configuration.rb', line 32 def initialize(defaults={}) @scheme = 'https' @host = 'api.preact.io' @base_path = '/api/v2' @autolog = false @autolog_ignored_actions = [] @disabled = false @person_builder = nil @logging_mode = nil @sidekiq_queue = :default @request_timeout = 5 @inject_javascript = false @current_user_getter = :current_user @current_account_getter = nil @user_agent = "ruby-preact:#{Preact::VERSION}" if defaults && defaults.is_a?(Hash) defaults.each do |k,v| instance_variable_set("@#{k}", v) unless v.nil? end end end |
Instance Attribute Details
#account_builder ⇒ Object
Returns the value of attribute account_builder.
13 14 15 |
# File 'lib/preact/configuration.rb', line 13 def account_builder @account_builder end |
#autolog ⇒ Object
Returns the value of attribute autolog.
14 15 16 |
# File 'lib/preact/configuration.rb', line 14 def autolog @autolog end |
#autolog_ignored_actions ⇒ Object
Returns the value of attribute autolog_ignored_actions.
15 16 17 |
# File 'lib/preact/configuration.rb', line 15 def autolog_ignored_actions @autolog_ignored_actions end |
#base_path ⇒ Object
Returns the value of attribute base_path.
30 31 32 |
# File 'lib/preact/configuration.rb', line 30 def base_path @base_path end |
#code ⇒ Object
Preact credentials
7 8 9 |
# File 'lib/preact/configuration.rb', line 7 def code @code end |
#current_account_getter ⇒ Object
Returns the value of attribute current_account_getter.
22 23 24 |
# File 'lib/preact/configuration.rb', line 22 def current_account_getter @current_account_getter end |
#current_user_getter ⇒ Object
Returns the value of attribute current_user_getter.
21 22 23 |
# File 'lib/preact/configuration.rb', line 21 def current_user_getter @current_user_getter end |
#disabled ⇒ Object
Default option settings
11 12 13 |
# File 'lib/preact/configuration.rb', line 11 def disabled @disabled end |
#host ⇒ Object
Returns the value of attribute host.
29 30 31 |
# File 'lib/preact/configuration.rb', line 29 def host @host end |
#inject_javascript ⇒ Object
Returns the value of attribute inject_javascript.
19 20 21 |
# File 'lib/preact/configuration.rb', line 19 def inject_javascript @inject_javascript end |
#logger ⇒ Object
Logger settings
25 26 27 |
# File 'lib/preact/configuration.rb', line 25 def logger @logger end |
#logging_mode ⇒ Object
Returns the value of attribute logging_mode.
18 19 20 |
# File 'lib/preact/configuration.rb', line 18 def logging_mode @logging_mode end |
#person_builder ⇒ Object
Returns the value of attribute person_builder.
12 13 14 |
# File 'lib/preact/configuration.rb', line 12 def person_builder @person_builder end |
#request_timeout ⇒ Object
Returns the value of attribute request_timeout.
17 18 19 |
# File 'lib/preact/configuration.rb', line 17 def request_timeout @request_timeout end |
#scheme ⇒ Object
The URL of the API server
28 29 30 |
# File 'lib/preact/configuration.rb', line 28 def scheme @scheme end |
#secret ⇒ Object
Returns the value of attribute secret.
8 9 10 |
# File 'lib/preact/configuration.rb', line 8 def secret @secret end |
#sidekiq_queue ⇒ Object
Returns the value of attribute sidekiq_queue.
16 17 18 |
# File 'lib/preact/configuration.rb', line 16 def sidekiq_queue @sidekiq_queue end |
Instance Method Details
#autolog_enabled? ⇒ Boolean
85 86 87 |
# File 'lib/preact/configuration.rb', line 85 def autolog_enabled? autolog == true end |
#autolog_should_log?(controller, action) ⇒ Boolean
89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/preact/configuration.rb', line 89 def autolog_should_log?(controller, action) # check to see if we're ignoring this action if autolog_ignored_actions && autolog_ignored_actions.is_a?(Array) # check to see if we've ignored this specific action return false if autolog_ignored_actions.include?("#{controller}##{action}") # check to see if we've ignored all actions from this controller return false if autolog_ignored_actions.include?("#{controller}#*") end true end |
#base_uri ⇒ Object
77 78 79 |
# File 'lib/preact/configuration.rb', line 77 def base_uri "#{scheme}://#{code}:#{secret}@#{host}#{base_path}" end |
#convert_to_account(account) ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/preact/configuration.rb', line 146 def convert_to_account(account) return nil if account.nil? if account_builder if account_builder.respond_to?(:call) hash = account_builder.call(account) else raise "account_builder must be callable" end elsif account.respond_to?(:to_preact) hash = account.to_preact elsif account.is_a? Hash hash = account else hash = default_account_to_preact_hash(account) end hash end |
#convert_to_person(user) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/preact/configuration.rb', line 126 def convert_to_person(user) return nil if user.nil? if person_builder if person_builder.respond_to?(:call) hash = person_builder.call(user) else raise "person_builder must be callable" end elsif user.respond_to?(:to_preact) hash = user.to_preact elsif user.is_a? Hash hash = user else hash = default_user_to_preact_hash(user) end hash end |
#disabled? ⇒ Boolean
69 70 71 |
# File 'lib/preact/configuration.rb', line 69 def disabled? disabled == true end |
#enabled? ⇒ Boolean
65 66 67 |
# File 'lib/preact/configuration.rb', line 65 def enabled? !disabled end |
#get_current_account(target) ⇒ Object
115 116 117 118 119 120 121 122 123 124 |
# File 'lib/preact/configuration.rb', line 115 def get_current_account(target) return nil if current_user_getter.nil? if current_account_getter.to_s.starts_with?("@") # instance var target.instance_variable_get(current_account_getter) rescue nil else target.send(current_account_getter) rescue nil end end |
#get_current_user(target) ⇒ Object
104 105 106 107 108 109 110 111 112 113 |
# File 'lib/preact/configuration.rb', line 104 def get_current_user(target) return nil if current_user_getter.nil? if current_user_getter.to_s.starts_with?("@") # instance var target.instance_variable_get(current_user_getter) rescue nil else target.send(current_user_getter) rescue nil end end |
#inject_javascript? ⇒ Boolean
81 82 83 |
# File 'lib/preact/configuration.rb', line 81 def inject_javascript? inject_javascript == true end |
#prepare_account_hash(account) ⇒ Object
187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/preact/configuration.rb', line 187 def prepare_account_hash(account) # id for account should actually be passed as external_identifier # make that correction here before sending (LEGACY SUPPORT) external_id = account[:external_identifier] || account["external_identifier"] if account_id = account[:id] || account["id"] if external_id.nil? account[:external_identifier] = account_id account.delete(:id) account.delete("id") end end account end |
#prepare_event_hash(event) ⇒ Object
202 203 204 205 |
# File 'lib/preact/configuration.rb', line 202 def prepare_event_hash(event) event[:source] = Preact.configuration.user_agent event end |
#prepare_person_hash(person) ⇒ Object
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/preact/configuration.rb', line 166 def prepare_person_hash(person) return nil if person.nil? if external_id = person[:external_identifier] || person["external_identifier"] person[:uid] ||= external_id person.delete(:external_identifier) person.delete("external_identifier") end if created_at = person[:created_at] || person["created_at"] if created_at.respond_to?(:to_i) created_at = created_at.to_i end person[:created_at] = created_at person.delete("created_at") end person end |
#user_agent ⇒ Object
73 74 75 |
# File 'lib/preact/configuration.rb', line 73 def user_agent @user_agent end |
#valid? ⇒ Boolean
60 61 62 63 |
# File 'lib/preact/configuration.rb', line 60 def valid? # we require both the API keys code && secret end |