Class: RailsSettingsUi::ValueTypes::Hash

Inherits:
Base
  • Object
show all
Defined in:
lib/rails-settings-ui/value_types/hash.rb

Instance Attribute Summary

Attributes inherited from Base

#errors, #value

Instance Method Summary collapse

Methods inherited from Base

#initialize, #valid?, #value_numeric?

Constructor Details

This class inherits a constructor from RailsSettingsUi::ValueTypes::Base

Instance Method Details

#castObject



6
7
8
# File 'lib/rails-settings-ui/value_types/hash.rb', line 6

def cast
  value
end

#validateObject



10
11
12
13
14
15
16
# File 'lib/rails-settings-ui/value_types/hash.rb', line 10

def validate
  begin
    self.value = JSON.parse(value.gsub(/\=\>/, ':'))
  rescue JSON::ParserError => e
    self.errors << I18n.t('errors.invalid_hash', default: 'Invalid')
  end
end