Class: Vero::Context

Inherits:
Object show all
Includes:
APIContext
Defined in:
lib/vero/context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from APIContext

#identify!, #reidentify!, #track!, #unsubscribe!, #update_user!, #update_user_tags!

Constructor Details

#initialize(object = {}) ⇒ Context

Returns a new instance of Context.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/vero/context.rb', line 8

def initialize(object = {})
  case object
  when Hash
    # stub
  when Vero::Context
    @config = object.config
    @subject = object.subject
  else
    object = Vero::Config.available_attributes.each_with_object({}) do |symbol, hash|
      hash[symbol] = object.respond_to?(symbol) ? object.send(symbol) : nil
    end
  end
  return unless object.is_a?(Hash)

  @config = Vero::Config.new
  configure(object)
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



6
7
8
# File 'lib/vero/context.rb', line 6

def config
  @config
end

#subjectObject

Returns the value of attribute subject.



6
7
8
# File 'lib/vero/context.rb', line 6

def subject
  @subject
end

Instance Method Details

#configure(hash = {}, &block) ⇒ Object



26
27
28
29
30
# File 'lib/vero/context.rb', line 26

def configure(hash = {}, &block)
  @config.update_attributes(hash) if hash.is_a?(Hash) && hash.any?

  block.call(@config) if block_given?
end

#configured?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/vero/context.rb', line 40

def configured?
  @config.configured?
end

#disable_requests!Object



36
37
38
# File 'lib/vero/context.rb', line 36

def disable_requests!
  @config.disable_requests!
end

#reset!Object



32
33
34
# File 'lib/vero/context.rb', line 32

def reset!
  @config.reset!
end