-
Notifications
You must be signed in to change notification settings - Fork 204
Expand file tree
/
Copy pathdocument.rb
More file actions
84 lines (66 loc) · 1.47 KB
/
document.rb
File metadata and controls
84 lines (66 loc) · 1.47 KB
1
2
3
4
5
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
require 'delegate'
module ActiveAdmin::Mongoid::Document
extend ActiveSupport::Concern
# PROXY CLASSES
class ColumnWrapper < SimpleDelegator
def type
_super = super
case _super
when BSON::ObjectId, Object
:string
else
_super.name.underscore.to_sym
end
end
end
class Connection
def initialize model
@model = model
end
def quote_column_name name
name
end
end
# CLASS METHODS
included do
unless respond_to? :primary_key
class << self
attr_accessor :primary_key
end
end
self.primary_key ||= :id
def column_for_attribute(name)
self.class.fields[name.to_sym]
end
end
module ClassMethods
def content_columns
# cannot cache this, since changes in time (while defining fields)
fields.map(&:second).reject! do |f|
f.name =~ /(^_|^(created|updated)_at)/ or Mongoid::Fields::ForeignKey === f
end
end
def connection
@connection ||= Connection.new(self)
end
def find_by_id id
find_by(_id: id)
end
def quoted_table_name
collection_name.to_s.inspect
end
def associations
@associations ||= new.associations
end
def reflections *a
relations *a
end
def ransackable_scopes_skip_sanitize_args
[]
end
def self.ransackable_scopes(auth_object = nil)
[]
end
end
end
Mongoid::Document.send :include, ActiveAdmin::Mongoid::Document