FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
documentcloud/app/models/docdata.rb at gm_processing · documentcloud/documentcloud · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
This repository was archived by the owner on Mar 11, 2021. It is now read-only.
documentcloud
/
documentcloud
Public archive
Notifications
You must be signed in to change notification settings
Fork
157
Star
425
Code
Issues
194
Pull requests
16
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
documentcloud
/
app
/
models
/
docdata.rb
Copy path
More file actions
More file actions
Latest commit
History
History
History
35 lines (28 loc) · 775 Bytes
Breadcrumbs
documentcloud
/
app
/
models
/
docdata.rb
Copy path
File metadata and controls
35 lines (28 loc) · 775 Bytes
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
class
Docdata
<
ActiveRecord
::
Base
belongs_to
:document
before_validation
:convert_data_to_hash
validates
:document_id
,
:uniqueness
=>
{
:allow_nil
=>
true
}
validate
:ensure_keys_are_not_forbidden
validates
:data
,
:presence
=>
true
after_save
:index_document
private
def
convert_data_to_hash
return
if
self
.
data
.
is_a?
(
Hash
)
if
self
.
data
.
blank?
self
.
data
=
{
}
else
self
.
data
=
Hash
[
(
self
.
data
)
.
scan
(
/"(.*?[^
\\
]|)"=>"(.*?[^
\\
]|)"/
)
]
end
end
def
ensure_keys_are_not_forbidden
if
forbidden
=
self
.
data
.
keys
.
detect
{
|
key
|
DC
::
ALL_SEARCHES
.
include?
(
key
.
to_sym
)
}
errors
.
add
(
:base
,
"Invalid data key:
#{
forbidden
}
"
)
false
else
true
end
end
def
index_document
self
.
document
.
index
end
end
Back
|
FazBrowse Home
|
New Git URL