Class: Netfira::WebConnect::Models::Setting

Inherits:
Netfira::WebConnect::Model::Support show all
Defined in:
lib/netfira/web_connect/models/support/setting.rb

Instance Method Summary collapse

Methods inherited from Netfira::WebConnect::Model::Support

table_name

Methods inherited from Netfira::WebConnect::Model

#dispatch_event, plural_name, single_name, table_name

Instance Method Details

#typed_valueObject



11
12
13
# File 'lib/netfira/web_connect/models/support/setting.rb', line 11

def typed_value
  cast_by_content_type value, content_type
end

#typed_value=(value) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/netfira/web_connect/models/support/setting.rb', line 15

def typed_value=(value)
  if String === value
    if value.encoding.name == 'ASCII-8BIT'
      self.value = value.b
      self.content_type = 'application/octet-stream'
    else
      self.value = value.force_encoding('UTF-8')
      self.content_type = 'text/plain;charset=UTF-8'
    end
  else
    self.value = JSON.generate(value, quirks_mode: true)
    self.content_type = 'application/json'
  end
end