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.
-
#disabled ⇒ Object
Default option settings.
-
#host ⇒ Object
Returns the value of attribute host.
-
#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
-
#initialize(defaults = {}) ⇒ Configuration
constructor
A new instance of Configuration.
- #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.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/preact/configuration.rb', line 28 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 @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.
26 27 28 |
# File 'lib/preact/configuration.rb', line 26 def base_path @base_path end |
#code ⇒ Object
Preact credentials
7 8 9 |
# File 'lib/preact/configuration.rb', line 7 def code @code 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.
25 26 27 |
# File 'lib/preact/configuration.rb', line 25 def host @host end |
#logger ⇒ Object
Logger settings
21 22 23 |
# File 'lib/preact/configuration.rb', line 21 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
24 25 26 |
# File 'lib/preact/configuration.rb', line 24 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
71 72 73 |
# File 'lib/preact/configuration.rb', line 71 def autolog_enabled? autolog == true end |
#autolog_should_log?(controller, action) ⇒ Boolean
75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/preact/configuration.rb', line 75 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
67 68 69 |
# File 'lib/preact/configuration.rb', line 67 def base_uri "#{scheme}://#{code}:#{secret}@#{host}#{base_path}" end |
#convert_to_account(account) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/preact/configuration.rb', line 108 def convert_to_account(account) 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
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/preact/configuration.rb', line 90 def convert_to_person(user) 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
59 60 61 |
# File 'lib/preact/configuration.rb', line 59 def disabled? disabled == true end |
#enabled? ⇒ Boolean
55 56 57 |
# File 'lib/preact/configuration.rb', line 55 def enabled? !disabled end |
#prepare_account_hash(account) ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/preact/configuration.rb', line 145 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
160 161 162 163 |
# File 'lib/preact/configuration.rb', line 160 def prepare_event_hash(event) event[:source] = Preact.configuration.user_agent event end |
#prepare_person_hash(person) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/preact/configuration.rb', line 126 def prepare_person_hash(person) 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
63 64 65 |
# File 'lib/preact/configuration.rb', line 63 def user_agent @user_agent end |
#valid? ⇒ Boolean
51 52 53 |
# File 'lib/preact/configuration.rb', line 51 def valid? code && secret end |