Module: Symbol::NoBrainerExtensions

Included in:
Symbol
Defined in:
lib/no_brainer/document/types/symbol.rb

Constant Summary collapse

InvalidType =
NoBrainer::Error::InvalidType

Instance Method Summary collapse

Instance Method Details

#nobrainer_cast_db_to_model(value) ⇒ Object



16
17
18
# File 'lib/no_brainer/document/types/symbol.rb', line 16

def nobrainer_cast_db_to_model(value)
  value.to_sym rescue (value.to_s.to_sym rescue value)
end

#nobrainer_cast_user_to_model(value) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/no_brainer/document/types/symbol.rb', line 5

def nobrainer_cast_user_to_model(value)
  case value
  when Symbol then value
  when String
    value = value.strip
    raise InvalidType if value.empty?
    value.to_sym
  else raise InvalidType
  end
end