Class: Neo4j::Shared::TypeConverters::EnumConverter
- Inherits:
-
Object
- Object
- Neo4j::Shared::TypeConverters::EnumConverter
- Defined in:
- lib/neo4j/shared/type_converters.rb
Instance Method Summary collapse
- #convert_type ⇒ Object
- #converted?(value) ⇒ Boolean
- #db_type ⇒ Object
-
#initialize(enum_keys, options) ⇒ EnumConverter
constructor
A new instance of EnumConverter.
- #supports_array? ⇒ Boolean
- #to_db(value) ⇒ Object
- #to_ruby(value) ⇒ Object (also: #call)
Constructor Details
#initialize(enum_keys, options) ⇒ EnumConverter
Returns a new instance of EnumConverter.
274 275 276 277 278 279 280 281 |
# File 'lib/neo4j/shared/type_converters.rb', line 274 def initialize(enum_keys, ) @enum_keys = enum_keys @options = return unless @options[:case_sensitive].nil? @options[:case_sensitive] = Neo4j::Config.enums_case_sensitive end |
Instance Method Details
#convert_type ⇒ Object
295 296 297 |
# File 'lib/neo4j/shared/type_converters.rb', line 295 def convert_type Symbol end |
#converted?(value) ⇒ Boolean
283 284 285 |
# File 'lib/neo4j/shared/type_converters.rb', line 283 def converted?(value) value.is_a?(db_type) end |
#db_type ⇒ Object
291 292 293 |
# File 'lib/neo4j/shared/type_converters.rb', line 291 def db_type Integer end |
#supports_array? ⇒ Boolean
287 288 289 |
# File 'lib/neo4j/shared/type_converters.rb', line 287 def supports_array? true end |
#to_db(value) ⇒ Object
305 306 307 308 309 310 311 312 313 314 315 |
# File 'lib/neo4j/shared/type_converters.rb', line 305 def to_db(value) if value.is_a?(Array) value.map(&method(:to_db)) elsif @options[:case_sensitive] @enum_keys[value.to_s.to_sym] || fail(Neo4j::Shared::Enum::InvalidEnumValueError, 'Value passed to an enum property must match one of the enum keys') else @enum_keys[value.to_s.downcase.to_sym] || fail(Neo4j::Shared::Enum::InvalidEnumValueError, 'Case-insensitive (downcased) value passed to an enum property must match one of the enum keys') end end |
#to_ruby(value) ⇒ Object Also known as: call
299 300 301 |
# File 'lib/neo4j/shared/type_converters.rb', line 299 def to_ruby(value) @enum_keys.key(value) unless value.nil? end |