FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
roadmap/app/models/application_record.rb at api-patch · DMPRoadmap/roadmap · GitHub
DMPRoadmap
roadmap
Repository navigation
Code
Issues
300
(300)
Pull requests
49
(49)
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
roadmap
/
app
/
models
/
application_record.rb
Copy path
More file actions
More file actions
Latest commit
History
History
History
41 lines (32 loc) · 1.03 KB
Breadcrumbs
roadmap
/
app
/
models
/
application_record.rb
Copy path
File metadata and controls
41 lines (32 loc) · 1.03 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
# frozen_string_literal: true
# Base ActiveRecord object
class
ApplicationRecord
<
ActiveRecord
::
Base
include
GlobalHelpers
include
ValidationValues
include
ValidationMessages
self
.
abstract_class
=
true
class
<<
self
# Indicates whether the underlying DB is MySQL
def
mysql_db?
connection
.
adapter_name
==
'Mysql2'
end
def
postgres_db?
connection
.
adapter_name
==
'PostgreSQL'
end
# Generates the appropriate where clause for a JSON field based on the DB type
def
safe_json_where_clause
(
column
:
,
hash_key
:
)
return
"(
#{
column
}
->>'
#{
hash_key
}
' LIKE ?)"
unless
mysql_db?
"(
#{
column
}
->>'$.
#{
hash_key
}
' LIKE ?)"
end
# Generates the appropriate where clause for a regular expression based on the DB type
def
safe_regexp_where_clause
(
column
:
)
return
"
#{
column
}
~* ?"
unless
mysql_db?
"
#{
column
}
REGEXP ?"
end
end
def
sanitize_fields
(
*
attrs
)
attrs
.
each
do
|
attr
|
send
(
:"
#{
attr
}
="
,
ActionController
::
Base
.
helpers
.
sanitize
(
send
(
attr
)
)
)
end
end
end
Back
|
FazBrowse Home
|
New Git URL