Class: HeliosTracker::Configuration
- Inherits:
-
Object
- Object
- HeliosTracker::Configuration
- Defined in:
- lib/helios_tracker/configuration.rb
Instance Attribute Summary collapse
-
#blocked_email_class_name ⇒ Object
Optional: the class name for blocked emails, e.g.
-
#blocked_email_fields ⇒ Object
Optional blocked email fields — map API field names to model attributes or lambdas.
-
#blocked_email_scope ⇒ Object
Optional: a lambda that receives (query_start, params) and returns an ActiveRecord relation of blocked email records.
-
#user_class_name ⇒ Object
Required: the User class name as a string, e.g.
-
#user_fields ⇒ Object
Optional user fields — map API field names to model attributes or lambdas.
-
#user_scope ⇒ Object
Required: a lambda that receives (query_start, params) and returns an ActiveRecord relation of user records to expose via the API.
-
#visit_fields ⇒ Object
Optional visit fields — map API field names to model attributes or lambdas.
-
#visit_scope ⇒ Object
Optional: a lambda that receives (query_start, params) and returns an ActiveRecord relation of visit records.
Instance Method Summary collapse
- #blocked_email_class ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#serialize_record(record, fields) ⇒ Object
Serialize a single record using a fields hash.
- #user_class ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/helios_tracker/configuration.rb', line 78 def initialize @user_class_name = "User" @blocked_email_class_name = nil @user_fields = { email: :email, created_at: :created_at, } @visit_fields = { hmid: :hmid, } @blocked_email_fields = { email: :email, source: :source, created_at: :created_at, } # Default scopes @user_scope = nil @visit_scope = nil @blocked_email_scope = nil end |
Instance Attribute Details
#blocked_email_class_name ⇒ Object
Optional: the class name for blocked emails, e.g. “BlockedEmail”
75 76 77 |
# File 'lib/helios_tracker/configuration.rb', line 75 def blocked_email_class_name @blocked_email_class_name end |
#blocked_email_fields ⇒ Object
Optional blocked email fields — map API field names to model attributes or lambdas. :email and :source are always required and included automatically.
Example:
config.blocked_email_fields = {
email: :email,
source: :source,
created_at: :created_at,
}
72 73 74 |
# File 'lib/helios_tracker/configuration.rb', line 72 def blocked_email_fields @blocked_email_fields end |
#blocked_email_scope ⇒ Object
Optional: a lambda that receives (query_start, params) and returns an ActiveRecord relation of blocked email records.
Example:
config.blocked_email_scope = ->(query_start, params) {
BlockedEmail.where("created_at > ?", query_start)
}
33 34 35 |
# File 'lib/helios_tracker/configuration.rb', line 33 def blocked_email_scope @blocked_email_scope end |
#user_class_name ⇒ Object
Required: the User class name as a string, e.g. “User”
4 5 6 |
# File 'lib/helios_tracker/configuration.rb', line 4 def user_class_name @user_class_name end |
#user_fields ⇒ Object
Optional user fields — map API field names to model attributes or lambdas. :email is always required and included automatically.
Example:
config.user_fields = {
email: :email,
created_at: :created_at,
source_ip: ->(user) { user.try(:source_ip) },
first_unconfirmed_visit_id: :first_unconfirmed_visit_id,
login_attempt_count: :login_attempt_count,
login_count: :login_count,
accounts_owned_count: ->(user) { user.accounts_owned_count },
free_accounts_count: ->(user) { user.free_accounts_count },
unsubscribe_nonce: :unsubscribe_nonce,
app_open_days_count: :app_open_days_count,
}
51 52 53 |
# File 'lib/helios_tracker/configuration.rb', line 51 def user_fields @user_fields end |
#user_scope ⇒ Object
Required: a lambda that receives (query_start, params) and returns an ActiveRecord relation of user records to expose via the API.
Example:
config.user_scope = ->(query_start, params) {
User.where.not(email: "")
.where("updated_at > ?", query_start)
}
14 15 16 |
# File 'lib/helios_tracker/configuration.rb', line 14 def user_scope @user_scope end |
#visit_fields ⇒ Object
Optional visit fields — map API field names to model attributes or lambdas. :hmid is always required and included automatically.
Example:
config.visit_fields = {
hmid: :hmid,
visited_download_page: ->(visit) { visit.visited_download_page? },
}
61 62 63 |
# File 'lib/helios_tracker/configuration.rb', line 61 def visit_fields @visit_fields end |
#visit_scope ⇒ Object
Optional: a lambda that receives (query_start, params) and returns an ActiveRecord relation of visit records. Defaults to UTM visits with hmid.
Example:
config.visit_scope = ->(query_start, params) {
UniversalTrackManager::Visit.where.not(hmid: nil)
.where("updated_at > ?", query_start)
}
24 25 26 |
# File 'lib/helios_tracker/configuration.rb', line 24 def visit_scope @visit_scope end |
Instance Method Details
#blocked_email_class ⇒ Object
107 108 109 110 |
# File 'lib/helios_tracker/configuration.rb', line 107 def blocked_email_class return nil unless @blocked_email_class_name @blocked_email_class_name.constantize end |
#serialize_record(record, fields) ⇒ Object
Serialize a single record using a fields hash. Fields can be symbols (attribute names) or lambdas.
114 115 116 117 118 119 120 121 122 |
# File 'lib/helios_tracker/configuration.rb', line 114 def serialize_record(record, fields) fields.each_with_object({}) do |(key, mapping), hash| hash[key] = if mapping.respond_to?(:call) mapping.call(record) else record.public_send(mapping) end end end |
#user_class ⇒ Object
103 104 105 |
# File 'lib/helios_tracker/configuration.rb', line 103 def user_class @user_class_name.constantize end |