Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
2690332c
Commit
2690332c
authored
Nov 12, 2019
by
Mario de la Ossa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make GraphQL enums a little bit nicer
parent
a658e852
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
0 deletions
+37
-0
app/graphql/types/base_enum.rb
app/graphql/types/base_enum.rb
+13
-0
spec/graphql/types/base_enum_spec.rb
spec/graphql/types/base_enum_spec.rb
+24
-0
No files found.
app/graphql/types/base_enum.rb
View file @
2690332c
...
...
@@ -2,5 +2,18 @@
module
Types
class
BaseEnum
<
GraphQL
::
Schema
::
Enum
class
<<
self
def
value
(
*
args
,
**
kwargs
,
&
block
)
enum
[
args
[
0
].
downcase
]
=
kwargs
[
:value
]
||
args
[
0
]
super
(
*
args
,
**
kwargs
,
&
block
)
end
# Returns an indifferent access hash with the key being the downcased name of the attribute
# and the value being the Ruby value (either the explicit `value` passed or the same as the value attr).
def
enum
@enum_values
||=
{}.
with_indifferent_access
end
end
end
end
spec/graphql/types/base_enum_spec.rb
0 → 100644
View file @
2690332c
# frozen_string_literal: true
require
'spec_helper'
describe
Types
::
BaseEnum
do
describe
'#enum'
do
let
(
:enum
)
do
Class
.
new
(
described_class
)
do
value
'TEST'
,
value:
3
value
'other'
value
'NORMAL'
end
end
it
'adds all enum values to #enum'
do
expect
(
enum
.
enum
.
keys
).
to
contain_exactly
(
'test'
,
'other'
,
'normal'
)
expect
(
enum
.
enum
.
values
).
to
contain_exactly
(
3
,
'other'
,
'NORMAL'
)
end
it
'is a HashWithIndefferentAccess'
do
expect
(
enum
.
enum
).
to
be_a
(
HashWithIndifferentAccess
)
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