Class: RailsAdmin::Adapters::Mongoid::Property

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_admin/adapters/mongoid/property.rb

Constant Summary collapse

STRING_TYPE_COLUMN_NAMES =
[:name, :title, :subject].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(property, model) ⇒ Property

Returns a new instance of Property.



8
9
10
11
# File 'lib/rails_admin/adapters/mongoid/property.rb', line 8

def initialize(property, model)
  @property = property
  @model = model
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



6
7
8
# File 'lib/rails_admin/adapters/mongoid/property.rb', line 6

def model
  @model
end

#propertyObject (readonly)

Returns the value of attribute property.



6
7
8
# File 'lib/rails_admin/adapters/mongoid/property.rb', line 6

def property
  @property
end

Instance Method Details

#association?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/rails_admin/adapters/mongoid/property.rb', line 62

def association?
  false
end

#lengthObject



50
51
52
# File 'lib/rails_admin/adapters/mongoid/property.rb', line 50

def length
  (length_validation_lookup || 255) if type == :string
end

#nameObject



13
14
15
# File 'lib/rails_admin/adapters/mongoid/property.rb', line 13

def name
  property.name.to_sym
end

#nullable?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/rails_admin/adapters/mongoid/property.rb', line 54

def nullable?
  true
end

#pretty_nameObject



17
18
19
# File 'lib/rails_admin/adapters/mongoid/property.rb', line 17

def pretty_name
  property.name.to_s.tr('_', ' ').capitalize
end

#read_only?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/rails_admin/adapters/mongoid/property.rb', line 66

def read_only?
  false
end

#serial?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/rails_admin/adapters/mongoid/property.rb', line 58

def serial?
  name == :_id
end

#typeObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/rails_admin/adapters/mongoid/property.rb', line 21

def type
  case property.type.to_s
  when 'Array', 'Hash', 'Money'
    :serialized
  when 'BigDecimal'
    :decimal
  when 'Boolean', 'Mongoid::Boolean'
    :boolean
  when 'BSON::ObjectId', 'Moped::BSON::ObjectId'
    :bson_object_id
  when 'Date'
    :date
  when 'ActiveSupport::TimeWithZone', 'DateTime', 'Time'
    :datetime
  when 'Float'
    :float
  when 'Integer'
    :integer
  when 'Object'
    object_field_type
  when 'String'
    string_field_type
  when 'Symbol'
    :string
  else
    :string
  end
end