Class: Preact::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/preact/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_builderObject

Returns the value of attribute account_builder.



13
14
15
# File 'lib/preact/configuration.rb', line 13

def 
  @account_builder
end

#autologObject

Returns the value of attribute autolog.



14
15
16
# File 'lib/preact/configuration.rb', line 14

def autolog
  @autolog
end

#autolog_ignored_actionsObject

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_pathObject

Returns the value of attribute base_path.



26
27
28
# File 'lib/preact/configuration.rb', line 26

def base_path
  @base_path
end

#codeObject

Preact credentials



7
8
9
# File 'lib/preact/configuration.rb', line 7

def code
  @code
end

#disabledObject

Default option settings



11
12
13
# File 'lib/preact/configuration.rb', line 11

def disabled
  @disabled
end

#hostObject

Returns the value of attribute host.



25
26
27
# File 'lib/preact/configuration.rb', line 25

def host
  @host
end

#loggerObject

Logger settings



21
22
23
# File 'lib/preact/configuration.rb', line 21

def logger
  @logger
end

#logging_modeObject

Returns the value of attribute logging_mode.



18
19
20
# File 'lib/preact/configuration.rb', line 18

def logging_mode
  @logging_mode
end

#person_builderObject

Returns the value of attribute person_builder.



12
13
14
# File 'lib/preact/configuration.rb', line 12

def person_builder
  @person_builder
end

#request_timeoutObject

Returns the value of attribute request_timeout.



17
18
19
# File 'lib/preact/configuration.rb', line 17

def request_timeout
  @request_timeout
end

#schemeObject

The URL of the API server



24
25
26
# File 'lib/preact/configuration.rb', line 24

def scheme
  @scheme
end

#secretObject

Returns the value of attribute secret.



8
9
10
# File 'lib/preact/configuration.rb', line 8

def secret
  @secret
end

#sidekiq_queueObject

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

Returns:



71
72
73
# File 'lib/preact/configuration.rb', line 71

def autolog_enabled?
  autolog == true
end

#autolog_should_log?(controller, action) ⇒ Boolean

Returns:



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_uriObject



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 ()
  if 
    if .respond_to?(:call)
      hash = .call()
    else
      raise "account_builder must be callable"
    end
  elsif .respond_to?(:to_preact)
    hash = .to_preact
  elsif .is_a? Hash
    hash = 
  else
    hash = ()
  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

Returns:



59
60
61
# File 'lib/preact/configuration.rb', line 59

def disabled?
  disabled == true
end

#enabled?Boolean

Returns:



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 ()
  # id for account should actually be passed as external_identifier
  # make that correction here before sending (LEGACY SUPPORT)
  external_id = [:external_identifier] || ["external_identifier"]
  if  = [:id] || ["id"]
    if external_id.nil?
      [:external_identifier] = 
      .delete(:id)
      .delete("id")
    end
  end

  
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_agentObject



63
64
65
# File 'lib/preact/configuration.rb', line 63

def user_agent
  @user_agent
end

#valid?Boolean

Returns:



51
52
53
# File 'lib/preact/configuration.rb', line 51

def valid?
  code && secret
end