mirror of
https://github.com/internetee/registry.git
synced 2025-07-03 01:33:36 +02:00
Add EppSession for custom session management
This commit is contained in:
parent
3a57126e69
commit
e9f23ba348
9 changed files with 92 additions and 2 deletions
31
app/models/epp_session.rb
Normal file
31
app/models/epp_session.rb
Normal file
|
@ -0,0 +1,31 @@
|
|||
class EppSession < ActiveRecord::Base
|
||||
before_save :marshal_data!
|
||||
|
||||
def data
|
||||
@data ||= self.class.unmarshal(read_attribute(:data)) || {}
|
||||
end
|
||||
|
||||
def [](key)
|
||||
data[key.to_sym]
|
||||
end
|
||||
|
||||
def []=(key, value)
|
||||
data[key.to_sym] = value
|
||||
save!
|
||||
end
|
||||
|
||||
def marshal_data!
|
||||
self.data = self.class.marshal(data)
|
||||
end
|
||||
|
||||
class << self
|
||||
def marshal(data)
|
||||
::Base64.encode64(Marshal.dump(data)) if data
|
||||
end
|
||||
|
||||
def unmarshal(data)
|
||||
return data unless data.is_a? String
|
||||
Marshal.load(::Base64.decode64(data)) if data
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue