Module: ApplicationInsights::Channel::Contracts::JsonSerializable
- Included in:
- Application, Cloud, Data, DataPoint, Device, Envelope, EventData, ExceptionData, ExceptionDetails, Internal, Location, MessageData, MetricData, Operation, PageViewData, RemoteDependencyData, RequestData, Session, StackFrame, User
- Defined in:
- lib/application_insights/channel/contracts/json_serializable.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(klass) ⇒ Object
15 16 17 |
# File 'lib/application_insights/channel/contracts/json_serializable.rb', line 15 def self.included(klass) klass.extend JsonSerializable::ClassMethods end |
Instance Method Details
#initialize(attributes = {}) ⇒ Object
19 20 21 |
# File 'lib/application_insights/channel/contracts/json_serializable.rb', line 19 def initialize(attributes = {}) attributes.each { |k, v| send(:"#{k}=", v) } end |
#to_h ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/application_insights/channel/contracts/json_serializable.rb', line 23 def to_h output = {} klass = self.class klass.json_mappings.each do |attr, name| value = visit self.send(attr) is_empty = value.respond_to?(:empty?) && value.empty? output[name] = value unless value.nil? || is_empty end output end |
#to_json(args = {}) ⇒ Object
37 38 39 |
# File 'lib/application_insights/channel/contracts/json_serializable.rb', line 37 def to_json(args = {}) JSON.generate self.to_h, args end |