Class: RailsLiveDashboard::Types::Content

Inherits:
ActiveRecord::Type::Value
  • Object
show all
Defined in:
app/models/rails_live_dashboard/types/content.rb

Defined Under Namespace

Classes: CONTENT_STRUCT

Instance Method Summary collapse

Instance Method Details

#cast(value) ⇒ Object



10
11
12
13
# File 'app/models/rails_live_dashboard/types/content.rb', line 10

def cast(value)
  sanitized = sanitize_input(value)
  CONTENT_STRUCT.new(**sanitized)
end

#deserialize(value) ⇒ Object



15
16
17
18
19
# File 'app/models/rails_live_dashboard/types/content.rb', line 15

def deserialize(value)
  decoded = ActiveSupport::JSON.decode(value)
  sanitized = sanitize_input(decoded)
  CONTENT_STRUCT.new(**sanitized)
end

#serialize(value) ⇒ Object



21
22
23
# File 'app/models/rails_live_dashboard/types/content.rb', line 21

def serialize(value)
  ActiveSupport::JSON.encode(value)
end

#typeObject



6
7
8
# File 'app/models/rails_live_dashboard/types/content.rb', line 6

def type
  :jsonb
end