module PubSubTie::Events
Public Instance Methods
configure(config)
click to toggle source
# 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)
click to toggle source
Full event name from symbol protecting from typos Raises KeyError if bad symbol
# File lib/pubsub_tie/events.rb, line 20 def full_name(sym) "#{@prefix}-#{name(sym)}" end
name(sym)
click to toggle source
# File lib/pubsub_tie/events.rb, line 24 def name(sym) value(sym, 'name') end
optional(sym)
click to toggle source
# File lib/pubsub_tie/events.rb, line 32 def optional(sym) field_names(sym, 'optional') + repeated(sym) end
repeated(sym)
click to toggle source
# File lib/pubsub_tie/events.rb, line 36 def repeated(sym) field_names(sym, 'repeated') end
required(sym)
click to toggle source
# File lib/pubsub_tie/events.rb, line 28 def required(sym) field_names(sym, 'required') end
types(sym)
click to toggle source
# File lib/pubsub_tie/events.rb, line 40 def types(sym) value(sym, 'fields') end
Private Instance Methods
field_names(sym, mode)
click to toggle source
# File lib/pubsub_tie/events.rb, line 49 def field_names(sym, mode) (value(sym, mode) || []).map {|field| field['name'].to_sym} end
value(sym, key)
click to toggle source
# File lib/pubsub_tie/events.rb, line 45 def value(sym, key) @events.fetch(sym)[key] end