Module: Vero::Trackable::Base

Included in:
Vero::Trackable
Defined in:
lib/vero/trackable/base.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



6
7
8
9
# File 'lib/vero/trackable/base.rb', line 6

def self.included(base)
  @vero_trackable_map = []
  base.extend(ClassMethods)
end

Instance Method Details

#to_veroObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/vero/trackable/base.rb', line 29

def to_vero
  klass = self.class
  symbols, other = klass.trackable_map.partition { |i| i.is_a?(Symbol) }

  result = symbols.each_with_object({}) do |symbol, hash|
    t = respond_to?(symbol) ? send(symbol) : nil
    hash[symbol] = t unless t.nil?
  end

  if other.is_a?(Array) && !other.empty?
    other.select! { |i| (i.is_a?(Hash) && i.key?(:extras)) }
    other.each do |h|
      symbol = h[:extras]
      t = respond_to?(symbol, true) ? send(symbol) : nil
      result.merge!(t) if t.is_a?(Hash)
    end
  end

  result[:email] = result.delete(:email_address) if result.key?(:email_address)
  result[:_user_type] = self.class.name
  result
end

#with_default_vero_contextObject



58
59
60
# File 'lib/vero/trackable/base.rb', line 58

def with_default_vero_context
  with_vero_context(Vero::App.default_context)
end

#with_vero_context(context = {}) ⇒ Object



52
53
54
55
56
# File 'lib/vero/trackable/base.rb', line 52

def with_vero_context(context = {})
  context = Vero::Context.new(context)
  context.subject = self
  context
end