Module: FnordMetric::AppHelpers
- Included in:
- App
- Defined in:
- lib/fnordmetric/web/app_helpers.rb
Instance Method Summary collapse
- #current_namespace ⇒ Object
- #h(*args) ⇒ Object
- #namespaces ⇒ Object
- #parse_param(object) ⇒ Object
- #parse_params(hash) ⇒ Object
- #path_prefix ⇒ Object
- #track_event(event_id, event_data) ⇒ Object
Instance Method Details
#current_namespace ⇒ Object
15 16 17 18 19 |
# File 'lib/fnordmetric/web/app_helpers.rb', line 15 def current_namespace @namespaces[@namespaces.keys.detect{ |k| k.to_s == params[:namespace] }.try(:intern)] end |
#h(*args) ⇒ Object
3 4 5 |
# File 'lib/fnordmetric/web/app_helpers.rb', line 3 def h(*args) escape_html(*args) end |
#namespaces ⇒ Object
11 12 13 |
# File 'lib/fnordmetric/web/app_helpers.rb', line 11 def namespaces @namespaces end |
#parse_param(object) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/fnordmetric/web/app_helpers.rb', line 27 def parse_param(object) return object unless object.is_a?(String) return object.to_f if object.match(/^[0-9]+[,\.][0-9]+$/) return object.to_i if object.match(/^[0-9]+$/) object end |
#parse_params(hash) ⇒ Object
21 22 23 24 25 |
# File 'lib/fnordmetric/web/app_helpers.rb', line 21 def parse_params(hash) hash.tap do |h| h.keys.each{ |k| h[k] = parse_param(h[k]) } end end |
#path_prefix ⇒ Object
7 8 9 |
# File 'lib/fnordmetric/web/app_helpers.rb', line 7 def path_prefix request.env["SCRIPT_NAME"] end |
#track_event(event_id, event_data) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/fnordmetric/web/app_helpers.rb', line 34 def track_event(event_id, event_data) # FIXPAUL: use api @redis.hincrby "#{@opts[:redis_prefix]}-stats", "events_received", 1 @redis.set "#{@opts[:redis_prefix]}-event-#{event_id}", event_data.to_json @redis.lpush "#{@opts[:redis_prefix]}-queue", event_id @redis.expire "#{@opts[:redis_prefix]}-event-#{event_id}", @opts[:event_queue_ttl] end |