BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
9a9aaa56
Commit
9a9aaa56
authored
Jul 06, 2017
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement ayufan validator2
parent
1acaf75d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
0 deletions
+13
-0
variable_duplicates_validator.rb
app/validators/variable_duplicates_validator.rb
+13
-0
No files found.
app/validators/variable_duplicates_validator.rb
0 → 100644
View file @
9a9aaa56
# VariableDuplicatesValidator
#
# This validtor is designed for especially the following condition
# - Use `accepts_nested_attributes_for :xxx` in a parent model
# - Use `validates :xxx, uniqueness: { scope: :xxx_id }` in a child model
class
VariableDuplicatesValidator
<
ActiveModel
::
EachValidator
def
validate_each
(
record
,
attribute
,
value
)
duplicates
=
value
.
reject
(
&
:marked_for_destruction?
).
group_by
(
&
:key
).
select
{
|
_
,
v
|
v
.
many?
}.
map
(
&
:first
)
if
duplicates
.
any?
record
.
errors
.
add
(
attribute
,
"Duplicate variables:
#{
duplicates
.
join
(
", "
)
}
"
)
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment