Class: Spree::LogEntry

Inherits:
Base
  • Object
show all
Defined in:
app/models/spree/log_entry.rb

Defined Under Namespace

Classes: BadAlias, DisallowedClass, SerializationError

Constant Summary collapse

CORE_PERMITTED_CLASSES =

Classes used in core that can be present in serialized details

Users can add their own classes in ‘Spree::Config#log_entry_permitted_classes`.

[
  ActiveMerchant::Billing::Response,
  ActiveSupport::TimeWithZone,
  Time,
  ActiveSupport::TimeZone
].freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

display_includes

Methods included from Core::Permalinks

#generate_permalink, #save_permalink

Class Method Details

.permitted_classesObject



61
62
63
# File 'app/models/spree/log_entry.rb', line 61

def self.permitted_classes
  CORE_PERMITTED_CLASSES + Spree::Config.log_entry_permitted_classes.map(&:constantize)
end

Instance Method Details

#parsed_detailsObject



67
68
69
70
71
72
73
74
75
# File 'app/models/spree/log_entry.rb', line 67

def parsed_details
  handle_psych_serialization_errors do
    @details ||= YAML.safe_load(
      details,
      permitted_classes: self.class.permitted_classes,
      aliases: Spree::Config.log_entry_allow_aliases,
    )
  end
end

#parsed_details=(value) ⇒ Object



77
78
79
80
81
82
83
84
85
# File 'app/models/spree/log_entry.rb', line 77

def parsed_details=(value)
  handle_psych_serialization_errors do
    self.details = YAML.safe_dump(
      value,
      permitted_classes: self.class.permitted_classes,
      aliases: Spree::Config.log_entry_allow_aliases,
    )
  end
end

#parsed_payment_response_details_with_fallback=(response) ⇒ Object



87
88
89
90
91
92
93
94
95
96
# File 'app/models/spree/log_entry.rb', line 87

def parsed_payment_response_details_with_fallback=(response)
  self.parsed_details = response
rescue SerializationError, YAML::Exception => e
  # Fall back on wrapping the response and signaling the error to the end user.
  self.parsed_details = ActiveMerchant::Billing::Response.new(
    response.success?,
    "[WARNING: An error occurred while trying to serialize the payment response] #{response.message}",
    { 'data' => response.inspect, 'error' => e.message.to_s },
  )
end