Module: MixTape::Builder

Extended by:
Builder
Included in:
Builder
Defined in:
lib/mix_tape/builder.rb

Constant Summary collapse

@@mix_tape =

Store definitions in array, so we can generate documenation.

[]

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(key, *arguments, &block) ⇒ Object



33
34
35
# File 'lib/mix_tape/builder.rb', line 33

def method_missing(key, *arguments, &block)
  define(key, arguments.first, &block)
end

Instance Method Details

#define(name, desc = '', &block) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/mix_tape/builder.rb', line 16

def define(name, desc = '', &block)
  @@mix_tape << [name, desc]

  MixTape.define_singleton_method("track_#{name}") do |*args|
    data = yield(*args)
    distinct_id = data.delete(:distinct_id)
    MixTape.client.track distinct_id, name.to_s, data
  end

  MixTape.define_singleton_method("set_#{name}") do |id, *args|
    args = yield(*args)
    ip = args['$ip'] || args[:$ip] || args[:ip]

    MixTape.client.people.set id, args, ip
  end
end

#definition(&block) ⇒ Object



12
13
14
# File 'lib/mix_tape/builder.rb', line 12

def definition(&block)
  block.arity < 1 ? self.instance_eval(&block) : block.call(self) if block_given?
end

#mix_tapeObject



8
9
10
# File 'lib/mix_tape/builder.rb', line 8

def mix_tape
  @@mix_tape
end