Module: PubSubTie::Events

Extended by:
Events
Included in:
Events
Defined in:
lib/pubsub_tie/events.rb

Instance Method Summary collapse

Instance Method Details

#configure(config) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/pubsub_tie/events.rb', line 5

def configure(config)
  @prefix = config['app_prefix']

  evs = config['events'].map{|e| e['name']}
  @events = Hash[evs.map(&:to_sym).zip(config['events'])]
  @events.each do |k, evt|
    fields = (evt['required'] || []) + 
        (evt['optional'] || []) +
        (evt['repeated'] || [])
    evt['fields'] = Hash[ fields.map {|f| [f['name'], f['type']]} ]
  end
end

#full_name(sym) ⇒ Object

Full event name from symbol protecting from typos Raises KeyError if bad symbol



20
21
22
# File 'lib/pubsub_tie/events.rb', line 20

def full_name(sym)
  "#{@prefix}-#{name(sym)}"
end

#name(sym) ⇒ Object



24
25
26
# File 'lib/pubsub_tie/events.rb', line 24

def name(sym)
  value(sym, 'name')
end

#optional(sym) ⇒ Object



32
33
34
# File 'lib/pubsub_tie/events.rb', line 32

def optional(sym)
  field_names(sym, 'optional') + repeated(sym)
end

#repeated(sym) ⇒ Object



36
37
38
# File 'lib/pubsub_tie/events.rb', line 36

def repeated(sym)
  field_names(sym, 'repeated')
end

#required(sym) ⇒ Object



28
29
30
# File 'lib/pubsub_tie/events.rb', line 28

def required(sym)
  field_names(sym, 'required')
end

#types(sym) ⇒ Object



40
41
42
# File 'lib/pubsub_tie/events.rb', line 40

def types(sym)
  value(sym, 'fields')
end