Class: Mongify::Mongoid::Model::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/mongify/mongoid/model/field.rb

Overview

Field for a Mongoid Model

Constant Summary collapse

ACCEPTED_TYPES =

List of accepted types

[
  "Array",
  "BigDecimal",
  "Decimal",
  "Boolean",
  "Date",
  "DateTime",
  "Float",
  "Hash",
  "Integer",
  "Moped::BSON::ObjectId",
  "Moped::BSON::Binary",
  "Range",
  "Regexp",
  "String",
  "Symbol",
  "Time",
  "TimeWithZone"
]
TRANSLATION_TYPES =

Hash of translations for different types

{
  array: "Array",
  bigdecimal: "BigDecimal",
  decimal: "String",
  boolean: "Boolean",
  date: "Date",
  datetime: "DateTime",
  float: "Float",
  hash: "Hash",
  integer: "Integer",
  objectid: "Moped::BSON::ObjectId",
  binary: "Moped::BSON::Binary",
  range: "Range",
  regexp: "Regexp",
  string: "String",
  symbol: "Symbol",
  time: "Time",
  text: "String",
  timewithzone: "TimeWithZone"
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type, options = {}) ⇒ Field

Returns a new instance of Field.



53
54
55
56
57
58
# 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

Instance Attribute Details

#nameObject

Returns the value of attribute name.



51
52
53
# File 'lib/mongify/mongoid/model/field.rb', line 51

def name
  @name
end

#optionsObject

Returns the value of attribute options.



51
52
53
# File 'lib/mongify/mongoid/model/field.rb', line 51

def options
  @options
end

#typeObject

Returns the value of attribute type.



51
52
53
# File 'lib/mongify/mongoid/model/field.rb', line 51

def type
  @type
end