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
44c3fb6e
Commit
44c3fb6e
authored
Nov 13, 2017
by
Ahmad Sherif
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add an attributes bag class as a GitalyClient helper
parent
f31fb4cd
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
39 additions
and
32 deletions
+39
-32
lib/gitlab/gitaly_client/attributes_bag.rb
lib/gitlab/gitaly_client/attributes_bag.rb
+31
-0
lib/gitlab/gitaly_client/diff.rb
lib/gitlab/gitaly_client/diff.rb
+2
-14
lib/gitlab/gitaly_client/diff_stitcher.rb
lib/gitlab/gitaly_client/diff_stitcher.rb
+1
-1
lib/gitlab/gitaly_client/wiki_file.rb
lib/gitlab/gitaly_client/wiki_file.rb
+2
-10
lib/gitlab/gitaly_client/wiki_page.rb
lib/gitlab/gitaly_client/wiki_page.rb
+3
-7
No files found.
lib/gitlab/gitaly_client/attributes_bag.rb
0 → 100644
View file @
44c3fb6e
module
Gitlab
module
GitalyClient
# This module expects an `ATTRS` const to be defined on the subclass
# See GitalyClient::WikiFile for an example
module
AttributesBag
extend
ActiveSupport
::
Concern
included
do
attr_accessor
(
*
const_get
(
:ATTRS
))
end
def
initialize
(
params
)
params
=
params
.
with_indifferent_access
attributes
.
each
do
|
attr
|
instance_variable_set
(
"@
#{
attr
}
"
,
params
[
attr
])
end
end
def
==
(
other
)
attributes
.
all?
do
|
field
|
instance_variable_get
(
"@
#{
field
}
"
)
==
other
.
instance_variable_get
(
"@
#{
field
}
"
)
end
end
def
attributes
self
.
class
.
const_get
(
:ATTRS
)
end
end
end
end
lib/gitlab/gitaly_client/diff.rb
View file @
44c3fb6e
module
Gitlab
module
Gitlab
module
GitalyClient
module
GitalyClient
class
Diff
class
Diff
FIELD
S
=
%i(from_path to_path old_mode new_mode from_id to_id patch overflow_marker collapsed)
.
freeze
ATTR
S
=
%i(from_path to_path old_mode new_mode from_id to_id patch overflow_marker collapsed)
.
freeze
attr_accessor
(
*
FIELDS
)
include
AttributesBag
def
initialize
(
params
)
params
.
each
do
|
key
,
val
|
public_send
(
:"
#{
key
}
="
,
val
)
# rubocop:disable GitlabSecurity/PublicSend
end
end
def
==
(
other
)
FIELDS
.
all?
do
|
field
|
public_send
(
field
)
==
other
.
public_send
(
field
)
# rubocop:disable GitlabSecurity/PublicSend
end
end
end
end
end
end
end
end
lib/gitlab/gitaly_client/diff_stitcher.rb
View file @
44c3fb6e
...
@@ -12,7 +12,7 @@ module Gitlab
...
@@ -12,7 +12,7 @@ module Gitlab
@rpc_response
.
each
do
|
diff_msg
|
@rpc_response
.
each
do
|
diff_msg
|
if
current_diff
.
nil?
if
current_diff
.
nil?
diff_params
=
diff_msg
.
to_h
.
slice
(
*
GitalyClient
::
Diff
::
FIELD
S
)
diff_params
=
diff_msg
.
to_h
.
slice
(
*
GitalyClient
::
Diff
::
ATTR
S
)
# gRPC uses frozen strings by default, and we need to have an unfrozen string as it
# gRPC uses frozen strings by default, and we need to have an unfrozen string as it
# gets processed further down the line. So we unfreeze the first chunk of the patch
# gets processed further down the line. So we unfreeze the first chunk of the patch
# in case it's the only chunk we receive for this diff.
# in case it's the only chunk we receive for this diff.
...
...
lib/gitlab/gitaly_client/wiki_file.rb
View file @
44c3fb6e
module
Gitlab
module
Gitlab
module
GitalyClient
module
GitalyClient
class
WikiFile
class
WikiFile
FIELD
S
=
%i(name mime_type path raw_data)
.
freeze
ATTR
S
=
%i(name mime_type path raw_data)
.
freeze
attr_accessor
(
*
FIELDS
)
include
AttributesBag
def
initialize
(
params
)
params
=
params
.
with_indifferent_access
FIELDS
.
each
do
|
field
|
instance_variable_set
(
"@
#{
field
}
"
,
params
[
field
])
end
end
end
end
end
end
end
end
lib/gitlab/gitaly_client/wiki_page.rb
View file @
44c3fb6e
module
Gitlab
module
Gitlab
module
GitalyClient
module
GitalyClient
class
WikiPage
class
WikiPage
FIELD
S
=
%i(title format url_path path name historical raw_data)
.
freeze
ATTR
S
=
%i(title format url_path path name historical raw_data)
.
freeze
attr_accessor
(
*
FIELDS
)
include
AttributesBag
def
initialize
(
params
)
def
initialize
(
params
)
params
=
params
.
with_indifferent_access
super
FIELDS
.
each
do
|
field
|
instance_variable_set
(
"@
#{
field
}
"
,
params
[
field
])
end
# All gRPC strings in a response are frozen, so we get an unfrozen
# All gRPC strings in a response are frozen, so we get an unfrozen
# version here so appending to `raw_data` doesn't blow up.
# version here so appending to `raw_data` doesn't blow up.
...
...
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