Module: ScoutApm::AttributeArranger
- Defined in:
- lib/scout_apm/attribute_arranger.rb
Class Method Summary collapse
-
.call(subject, attributes_list) ⇒ Object
pass in an array of symbols to return as hash keys if the symbol doesn’t match the name of the method, pass an array: [:key, :method_name].
Class Method Details
.call(subject, attributes_list) ⇒ Object
pass in an array of symbols to return as hash keys if the symbol doesn’t match the name of the method, pass an array: [:key, :method_name]
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/scout_apm/attribute_arranger.rb', line 5 def self.call(subject, attributes_list) attributes_list.inject({}) do |attribute_hash, attribute| case attribute when Array attribute_hash[attribute[0]] = subject.send(attribute[1]) when :bucket attribute_hash[attribute] = subject.bucket_type when :name attribute_hash[attribute] = subject.bucket_name when Symbol data = subject.send(attribute) # Never try to `as_json` a time object, since it'll break if the # app has the Oj gem set to mimic_JSON, and there's never # anything interesting nested inside of a Time obj. We just want # the ISO8601 string (which happens later in the payload # serializing process) if data.is_a?(Time) attribute_hash[attribute] = data elsif data.respond_to?(:as_json) attribute_hash[attribute] = data.as_json else attribute_hash[attribute] = data end end attribute_hash end end |