class Mongify::Mongoid::Model::Field
Constants
- ACCEPTED_TYPES
List of accepted types
- TRANSLATION_TYPES
Hash of translations for different types
Attributes
name[RW]
options[RW]
type[RW]
Public Class Methods
new(name, type, options={})
click to toggle source
# File lib/mongify/mongoid/model/field.rb, line 53 def initialize(name, type, options={}) @name = name @options = options @type = translate_type(type) check_field_type(@type) end
Private Instance Methods
check_field_type(name)
click to toggle source
Raises InvalidField
if field type is unknown @param [String] name Name of type @raise InvalidField
if name is not an accepted type
# File lib/mongify/mongoid/model/field.rb, line 74 def check_field_type (name) raise InvalidField, "Unknown field type #{name}" unless ACCEPTED_TYPES.map(&:downcase).include? name.to_s.downcase end
translate_type(name)
click to toggle source
Tries to find a translation for a SQL type to a Mongoid
Type @param [String] name Name of type @return [String] Translated field name or the same name if no translation is found
# File lib/mongify/mongoid/model/field.rb, line 67 def translate_type(name) TRANSLATION_TYPES[name.to_s.downcase.to_sym] || name end