Class: Deli::Adapters::Mongoid::Model

Inherits:
Model
  • Object
show all
Defined in:
lib/deli/adapters/mongoid.rb

Instance Attribute Summary

Attributes inherited from Model

#name

Instance Method Summary collapse

Methods inherited from Model

#initialize, #model_class

Constructor Details

This class inherits a constructor from Deli::Model

Instance Method Details

#model_type(key, options = {}) ⇒ Object

Raises:

  • (::ArgumentError)


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/deli/adapters/mongoid.rb', line 6

def model_type(key, options = {})
  default = options[:type]
  
  if default.present?
    value = default.to_sym
  else
    value = model_class.fields[key.to_s]
    value = value.present? ? value.type.to_s.underscore.to_sym : nil
  end
  
  raise ::ArgumentError.new("Must specify type, such as: `match :#{key}, :type => :string`") if value.blank?
  
  case value
  when :datetime, :time
    :time
  when :date
    :date
  when :integer, :float, :decimal, :count
    :number
  when :sort, :order
    :order
  when :string, :text
    :string
  else
    value
  end
end