class ActiveGraph::Shared::TypeConverters::EnumConverter
Public Class Methods
new(enum_keys, options)
click to toggle source
# File lib/active_graph/shared/type_converters.rb 275 def initialize(enum_keys, options) 276 @enum_keys = enum_keys 277 @options = options 278 279 return unless @options[:case_sensitive].nil? 280 281 @options[:case_sensitive] = ActiveGraph::Config.enums_case_sensitive 282 end
Public Instance Methods
convert_type()
click to toggle source
# File lib/active_graph/shared/type_converters.rb 296 def convert_type 297 Symbol 298 end
converted?(value)
click to toggle source
# File lib/active_graph/shared/type_converters.rb 284 def converted?(value) 285 value.is_a?(db_type) 286 end
db_type()
click to toggle source
# File lib/active_graph/shared/type_converters.rb 292 def db_type 293 Integer 294 end
supports_array?()
click to toggle source
# File lib/active_graph/shared/type_converters.rb 288 def supports_array? 289 true 290 end
to_db(value)
click to toggle source
# File lib/active_graph/shared/type_converters.rb 306 def to_db(value) 307 if value.is_a?(Array) 308 value.map(&method(:to_db)) 309 elsif @options[:case_sensitive] 310 @enum_keys[value.to_s.to_sym] || 311 fail(ActiveGraph::Shared::Enum::InvalidEnumValueError, 'Value passed to an enum property must match one of the enum keys') 312 else 313 @enum_keys[value.to_s.downcase.to_sym] || 314 fail(ActiveGraph::Shared::Enum::InvalidEnumValueError, 'Case-insensitive (downcased) value passed to an enum property must match one of the enum keys') 315 end 316 end
to_ruby(value)
click to toggle source
# File lib/active_graph/shared/type_converters.rb 300 def to_ruby(value) 301 @enum_keys.key(value) unless value.nil? 302 end
Also aliased as: call