Sha256: b8ad0bd8a4d859b14c68b58bbc093eccbdce55881317fb5d34b616395a743f66
Contents?: true
Size: 1.02 KB
Versions: 4
Compression:
Stored size: 1.02 KB
Contents
module PandaPal class Session < PandaPalRecord belongs_to :panda_pal_organization, class_name: 'PandaPal::Organization', optional: true after_initialize do self.session_key ||= SecureRandom.urlsafe_base64(60) end def lti_platform return nil unless data[:lti_platform].present? @lti_platform ||= Platform.from_serialized(data[:lti_platform]) end class DataSerializer def self.load(str) return {} unless str.present? begin parsed = JSON.parse(str) rescue JSON::ParserError parsed = yaml_load(str) end parsed.is_a?(Hash) ? HashWithIndifferentAccess.new(parsed) : parsed end def self.dump(obj) JSON.dump(obj) end private if YAML.respond_to?(:unsafe_load) def self.yaml_load(payload) YAML.unsafe_load(payload) end else def self.yaml_load(payload) YAML.load(payload) end end end serialize :data, DataSerializer end end
Version data entries
4 entries across 4 versions & 1 rubygems