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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
9ac0c76b
Commit
9ac0c76b
authored
Nov 17, 2017
by
Lin Jen-Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use StrongMemoize and enable/disable cops properly
parent
0af35d7e
Changes
48
Show whitespace changes
Inline
Side-by-side
Showing
48 changed files
with
193 additions
and
169 deletions
+193
-169
app/controllers/concerns/creates_commit.rb
app/controllers/concerns/creates_commit.rb
+11
-5
app/controllers/concerns/group_tree.rb
app/controllers/concerns/group_tree.rb
+2
-0
app/controllers/concerns/issuable_actions.rb
app/controllers/concerns/issuable_actions.rb
+3
-1
app/controllers/concerns/issuable_collections.rb
app/controllers/concerns/issuable_collections.rb
+6
-5
app/controllers/concerns/notes_actions.rb
app/controllers/concerns/notes_actions.rb
+19
-14
app/controllers/concerns/preview_markdown.rb
app/controllers/concerns/preview_markdown.rb
+2
-0
app/controllers/concerns/renders_commits.rb
app/controllers/concerns/renders_commits.rb
+1
-2
app/controllers/concerns/renders_notes.rb
app/controllers/concerns/renders_notes.rb
+1
-0
app/controllers/concerns/service_params.rb
app/controllers/concerns/service_params.rb
+1
-2
app/controllers/concerns/snippets_actions.rb
app/controllers/concerns/snippets_actions.rb
+1
-0
app/controllers/concerns/spammable_actions.rb
app/controllers/concerns/spammable_actions.rb
+4
-4
app/controllers/concerns/toggle_subscription_action.rb
app/controllers/concerns/toggle_subscription_action.rb
+1
-2
app/models/concerns/mentionable.rb
app/models/concerns/mentionable.rb
+6
-5
app/models/concerns/milestoneish.rb
app/models/concerns/milestoneish.rb
+5
-4
app/models/concerns/noteable.rb
app/models/concerns/noteable.rb
+1
-0
app/models/concerns/relative_positioning.rb
app/models/concerns/relative_positioning.rb
+4
-6
app/models/concerns/resolvable_discussion.rb
app/models/concerns/resolvable_discussion.rb
+0
-1
app/models/concerns/routable.rb
app/models/concerns/routable.rb
+5
-8
app/models/concerns/taskable.rb
app/models/concerns/taskable.rb
+1
-2
app/models/concerns/time_trackable.rb
app/models/concerns/time_trackable.rb
+11
-8
app/serializers/concerns/with_pagination.rb
app/serializers/concerns/with_pagination.rb
+1
-1
app/services/concerns/issues/resolve_discussions.rb
app/services/concerns/issues/resolve_discussions.rb
+9
-8
app/services/spam_check_service.rb
app/services/spam_check_service.rb
+2
-0
app/workers/concerns/new_issuable.rb
app/workers/concerns/new_issuable.rb
+4
-6
config/initializers/fix_local_cache_middleware.rb
config/initializers/fix_local_cache_middleware.rb
+1
-2
config/initializers/rspec_profiling.rb
config/initializers/rspec_profiling.rb
+2
-3
config/initializers/rugged_use_gitlab_git_attributes.rb
config/initializers/rugged_use_gitlab_git_attributes.rb
+4
-2
lib/api/helpers.rb
lib/api/helpers.rb
+8
-2
lib/api/helpers/internal_helpers.rb
lib/api/helpers/internal_helpers.rb
+5
-6
lib/extracts_path.rb
lib/extracts_path.rb
+5
-7
lib/gitlab/cache/request_cache.rb
lib/gitlab/cache/request_cache.rb
+4
-3
lib/gitlab/ci/charts.rb
lib/gitlab/ci/charts.rb
+1
-2
lib/gitlab/ci/config/entry/configurable.rb
lib/gitlab/ci/config/entry/configurable.rb
+3
-4
lib/gitlab/ci/config/entry/node.rb
lib/gitlab/ci/config/entry/node.rb
+6
-0
lib/gitlab/ci/config/entry/validatable.rb
lib/gitlab/ci/config/entry/validatable.rb
+1
-2
lib/gitlab/ci/pipeline/chain/helpers.rb
lib/gitlab/ci/pipeline/chain/helpers.rb
+8
-10
lib/gitlab/current_settings.rb
lib/gitlab/current_settings.rb
+1
-2
lib/gitlab/cycle_analytics/base_query.rb
lib/gitlab/cycle_analytics/base_query.rb
+2
-3
lib/gitlab/cycle_analytics/production_helper.rb
lib/gitlab/cycle_analytics/production_helper.rb
+3
-2
lib/gitlab/database/rename_reserved_paths_migration/v1/migration_classes.rb
...e/rename_reserved_paths_migration/v1/migration_classes.rb
+2
-3
lib/gitlab/import_export/command_line_util.rb
lib/gitlab/import_export/command_line_util.rb
+1
-2
lib/gitlab/metrics/influx_db.rb
lib/gitlab/metrics/influx_db.rb
+1
-0
lib/gitlab/metrics/prometheus.rb
lib/gitlab/metrics/prometheus.rb
+10
-8
lib/gitlab/path_regex.rb
lib/gitlab/path_regex.rb
+0
-1
lib/gitlab/slash_commands/presenters/issue_base.rb
lib/gitlab/slash_commands/presenters/issue_base.rb
+9
-8
lib/tasks/gettext.rake
lib/tasks/gettext.rake
+1
-0
lib/tasks/gitlab/task_helpers.rb
lib/tasks/gitlab/task_helpers.rb
+9
-10
qa/qa/runtime/scenario.rb
qa/qa/runtime/scenario.rb
+5
-3
No files found.
app/controllers/concerns/creates_commit.rb
View file @
9ac0c76b
module
CreatesCommit
extend
ActiveSupport
::
Concern
include
Gitlab
::
Utils
::
StrongMemoize
# rubocop:disable Cop/ModuleWithInstanceVariables
def
create_commit
(
service
,
success_path
:,
failure_path
:,
failure_view:
nil
,
success_notice:
nil
)
...
...
@@ -94,15 +95,20 @@ module CreatesCommit
# rubocop:enable Cop/ModuleWithInstanceVariables
def
existing_merge_request_path
project_merge_request_path
(
@project
,
@merge_request
)
project_merge_request_path
(
@project
,
@merge_request
)
# rubocop:disable Cop/ModuleWithInstanceVariables
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
merge_request_exists?
return
@merge_request
if
defined?
(
@merge_request
)
@merge_request
=
MergeRequestsFinder
.
new
(
current_user
,
project_id:
@project
.
id
).
execute
.
opened
.
find_by
(
source_project_id:
@project_to_commit_into
,
source_branch:
@branch_name
,
target_branch:
@start_branch
)
strong_memoize
(
:merge_request
)
do
MergeRequestsFinder
.
new
(
current_user
,
project_id:
@project
.
id
)
.
execute
.
opened
.
find_by
(
source_project_id:
@project_to_commit_into
,
source_branch:
@branch_name
,
target_branch:
@start_branch
)
end
end
# rubocop:enable Cop/ModuleWithInstanceVariables
...
...
app/controllers/concerns/group_tree.rb
View file @
9ac0c76b
module
GroupTree
# rubocop:disable Cop/ModuleWithInstanceVariables
def
render_group_tree
(
groups
)
@groups
=
if
params
[
:filter
].
present?
Gitlab
::
GroupHierarchy
.
new
(
groups
.
search
(
params
[
:filter
]))
...
...
@@ -20,5 +21,6 @@ module GroupTree
render
json:
serializer
.
represent
(
@groups
)
end
end
# rubocop:enable Cop/ModuleWithInstanceVariables
end
end
app/controllers/concerns/issuable_actions.rb
View file @
9ac0c76b
...
...
@@ -142,6 +142,7 @@ module IssuableActions
@resource_name
||=
controller_name
.
singularize
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
render_entity_json
if
@issuable
.
valid?
render
json:
serializer
.
represent
(
@issuable
)
...
...
@@ -149,6 +150,7 @@ module IssuableActions
render
json:
{
errors:
@issuable
.
errors
.
full_messages
},
status: :unprocessable_entity
end
end
# rubocop:enable Cop/ModuleWithInstanceVariables
def
serializer
raise
NotImplementedError
...
...
@@ -159,6 +161,6 @@ module IssuableActions
end
def
parent
@project
||
@group
@project
||
@group
# rubocop:disable Cop/ModuleWithInstanceVariables
end
end
app/controllers/concerns/issuable_collections.rb
View file @
9ac0c76b
...
...
@@ -2,6 +2,7 @@ module IssuableCollections
extend
ActiveSupport
::
Concern
include
SortingHelper
include
Gitlab
::
IssuableMetadata
include
Gitlab
::
Utils
::
StrongMemoize
included
do
helper_method
:finder
...
...
@@ -43,7 +44,7 @@ module IssuableCollections
def
redirect_out_of_range
(
total_pages
)
return
false
if
total_pages
.
zero?
out_of_range
=
@issuables
.
current_page
>
total_pages
out_of_range
=
@issuables
.
current_page
>
total_pages
# rubocop:disable Cop/ModuleWithInstanceVariables
if
out_of_range
redirect_to
(
url_for
(
params
.
merge
(
page:
total_pages
,
only_path:
true
)))
...
...
@@ -53,7 +54,7 @@ module IssuableCollections
end
def
issuable_page_count
page_count_for_relation
(
@issuables
,
finder
.
row_count
)
page_count_for_relation
(
@issuables
,
finder
.
row_count
)
# rubocop:disable Cop/ModuleWithInstanceVariables
end
def
page_count_for_relation
(
relation
,
row_count
)
...
...
@@ -133,9 +134,9 @@ module IssuableCollections
end
def
finder
return
@finder
if
defined?
(
@finder
)
@finder
=
issuable_finder_for
(
@finder_type
)
strong_memoize
(
:finder
)
do
issuable_finder_for
(
@finder_type
)
# rubocop:disable Cop/ModuleWithInstanceVariables
end
end
def
collection_type
...
...
app/controllers/concerns/notes_actions.rb
View file @
9ac0c76b
# rubocop:disable Cop/ModuleWithInstanceVariables
module
NotesActions
include
RendersNotes
include
Gitlab
::
Utils
::
StrongMemoize
extend
ActiveSupport
::
Concern
included
do
...
...
@@ -31,6 +31,7 @@ module NotesActions
render
json:
notes_json
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
create
create_params
=
note_params
.
merge
(
merge_request_diff_head_sha:
params
[
:merge_request_diff_head_sha
],
...
...
@@ -48,7 +49,9 @@ module NotesActions
format
.
html
{
redirect_back_or_default
}
end
end
# rubocop:enable Cop/ModuleWithInstanceVariables
# rubocop:disable Cop/ModuleWithInstanceVariables
def
update
@note
=
Notes
::
UpdateService
.
new
(
project
,
current_user
,
note_params
).
execute
(
note
)
...
...
@@ -61,6 +64,7 @@ module NotesActions
format
.
html
{
redirect_back_or_default
}
end
end
# rubocop:enable Cop/ModuleWithInstanceVariables
def
destroy
if
note
.
editable?
...
...
@@ -139,7 +143,7 @@ module NotesActions
end
else
template
=
"discussions/_diff_discussion"
@fresh_discussion
=
true
@fresh_discussion
=
true
# rubocop:disable Cop/ModuleWithInstanceVariables
locals
=
{
discussions:
[
discussion
],
on_image:
on_image
}
end
...
...
@@ -192,7 +196,7 @@ module NotesActions
end
def
noteable
@noteable
||=
notes_finder
.
target
||
@note
&
.
noteable
@noteable
||=
notes_finder
.
target
||
@note
&
.
noteable
# rubocop:disable Cop/ModuleWithInstanceVariables
end
def
require_noteable!
...
...
@@ -212,20 +216,21 @@ module NotesActions
end
def
note_project
return
@note_project
if
defined?
(
@note_project
)
strong_memoize
(
:note_project
)
do
return
nil
unless
project
note_project_id
=
params
[
:note_project_id
]
@not
e_project
=
th
e_project
=
if
note_project_id
.
present?
Project
.
find
(
note_project_id
)
else
project
end
return
access_denied!
unless
can?
(
current_user
,
:create_note
,
@not
e_project
)
return
access_denied!
unless
can?
(
current_user
,
:create_note
,
th
e_project
)
@note_project
the_project
end
end
end
app/controllers/concerns/preview_markdown.rb
View file @
9ac0c76b
module
PreviewMarkdown
extend
ActiveSupport
::
Concern
# rubocop:disable Cop/ModuleWithInstanceVariables
def
preview_markdown
result
=
PreviewMarkdownService
.
new
(
@project
,
current_user
,
params
).
execute
...
...
@@ -19,4 +20,5 @@ module PreviewMarkdown
}
}
end
# rubocop:enable Cop/ModuleWithInstanceVariables
end
app/controllers/concerns/renders_commits.rb
View file @
9ac0c76b
module
RendersCommits
# rubocop:disable Cop/ModuleWithInstanceVariables
def
prepare_commits_for_rendering
(
commits
)
Banzai
::
CommitRenderer
.
render
(
commits
,
@project
,
current_user
)
Banzai
::
CommitRenderer
.
render
(
commits
,
@project
,
current_user
)
# rubocop:disable Cop/ModuleWithInstanceVariables
commits
end
...
...
app/controllers/concerns/renders_notes.rb
View file @
9ac0c76b
...
...
@@ -8,6 +8,7 @@ module RendersNotes
notes
end
# rubocop:enable Cop/ModuleWithInstanceVariables
private
...
...
app/controllers/concerns/service_params.rb
View file @
9ac0c76b
...
...
@@ -65,9 +65,8 @@ module ServiceParams
# Parameters to ignore if no value is specified
FILTER_BLANK_PARAMS
=
[
:password
].
freeze
# rubocop:disable Cop/ModuleWithInstanceVariables
def
service_params
dynamic_params
=
@service
.
event_channel_names
+
@service
.
event_names
dynamic_params
=
@service
.
event_channel_names
+
@service
.
event_names
# rubocop:disable Cop/ModuleWithInstanceVariables
service_params
=
params
.
permit
(
:id
,
service:
ALLOWED_PARAMS_CE
+
dynamic_params
)
if
service_params
[
:service
].
is_a?
(
Hash
)
...
...
app/controllers/concerns/snippets_actions.rb
View file @
9ac0c76b
...
...
@@ -15,6 +15,7 @@ module SnippetsActions
filename:
@snippet
.
sanitized_file_name
)
end
# rubocop:enable Cop/ModuleWithInstanceVariables
private
...
...
app/controllers/concerns/spammable_actions.rb
View file @
9ac0c76b
...
...
@@ -2,6 +2,7 @@ module SpammableActions
extend
ActiveSupport
::
Concern
include
Recaptcha
::
Verify
include
Gitlab
::
Utils
::
StrongMemoize
included
do
before_action
:authorize_submit_spammable!
,
only: :mark_as_spam
...
...
@@ -17,11 +18,10 @@ module SpammableActions
private
# rubocop:disable Cop/ModuleWithInstanceVariables
def
ensure_spam_config_loaded!
return
@spam_config_loaded
if
defined?
(
@spam_config_loaded
)
@spam_config_loaded
=
Gitlab
::
Recaptcha
.
load_configurations!
strong_memoize
(
:spam_config_loaded
)
do
Gitlab
::
Recaptcha
.
load_configurations!
end
end
def
recaptcha_check_with_fallback
(
&
fallback
)
...
...
app/controllers/concerns/toggle_subscription_action.rb
View file @
9ac0c76b
...
...
@@ -11,9 +11,8 @@ module ToggleSubscriptionAction
private
# rubocop:disable Cop/ModuleWithInstanceVariables
def
subscribable_project
@project
||
raise
(
NotImplementedError
)
@project
||
=
raise
(
NotImplementedError
)
end
def
subscribable_resource
...
...
app/models/concerns/mentionable.rb
View file @
9ac0c76b
...
...
@@ -43,15 +43,12 @@ module Mentionable
self
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
all_references
(
current_user
=
nil
,
extractor:
nil
)
@extractors
||=
{}
# Use custom extractor if it's passed in the function parameters.
if
extractor
@
extractors
[
current_user
]
=
extractor
extractors
[
current_user
]
=
extractor
else
extractor
=
@
extractors
[
current_user
]
||=
Gitlab
::
ReferenceExtractor
.
new
(
project
,
current_user
)
extractor
=
extractors
[
current_user
]
||=
Gitlab
::
ReferenceExtractor
.
new
(
project
,
current_user
)
extractor
.
reset_memoized_values
end
...
...
@@ -70,6 +67,10 @@ module Mentionable
extractor
end
def
extractors
@extractors
||=
{}
end
def
mentioned_users
(
current_user
=
nil
)
all_references
(
current_user
).
users
end
...
...
app/models/concerns/milestoneish.rb
View file @
9ac0c76b
...
...
@@ -102,11 +102,12 @@ module Milestoneish
end
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
memoize_per_user
(
user
,
method_name
)
@memoized
||=
{}
@memoized
[
method_name
]
||=
{}
@memoized
[
method_name
][
user
&
.
id
]
||=
yield
memoized_users
[
method_name
][
user
&
.
id
]
||=
yield
end
def
memoized_users
@memoized_users
||=
Hash
.
new
{
|
h
,
k
|
h
[
k
]
=
{}
}
end
# override in a class that includes this module to get a faster query
...
...
app/models/concerns/noteable.rb
View file @
9ac0c76b
...
...
@@ -55,6 +55,7 @@ module Noteable
discussion_notes
.
resolvable
.
discussions
(
self
)
end
end
# rubocop:enable Cop/ModuleWithInstanceVariables
def
discussions_resolvable?
resolvable_discussions
.
any?
(
&
:resolvable?
)
...
...
app/models/concerns/relative_positioning.rb
View file @
9ac0c76b
...
...
@@ -44,7 +44,6 @@ module RelativePositioning
next_pos
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
move_between
(
before
,
after
)
return
move_after
(
before
)
unless
after
return
move_before
(
after
)
unless
before
...
...
@@ -53,13 +52,12 @@ module RelativePositioning
# to its predecessor. This process will recursively move all the predecessors until we have a place
if
(
after
.
relative_position
-
before
.
relative_position
)
<
2
before
.
move_before
@positionable_neighbours
=
[
before
]
@positionable_neighbours
=
[
before
]
# rubocop:disable Cop/ModuleWithInstanceVariables
end
self
.
relative_position
=
position_between
(
before
.
relative_position
,
after
.
relative_position
)
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
move_after
(
before
=
self
)
pos_before
=
before
.
relative_position
pos_after
=
before
.
next_relative_position
...
...
@@ -67,7 +65,7 @@ module RelativePositioning
if
before
.
shift_after?
issue_to_move
=
self
.
class
.
in_projects
(
project_ids
).
find_by!
(
relative_position:
pos_after
)
issue_to_move
.
move_after
@positionable_neighbours
=
[
issue_to_move
]
@positionable_neighbours
=
[
issue_to_move
]
# rubocop:disable Cop/ModuleWithInstanceVariables
pos_after
=
issue_to_move
.
relative_position
end
...
...
@@ -75,7 +73,6 @@ module RelativePositioning
self
.
relative_position
=
position_between
(
pos_before
,
pos_after
)
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
move_before
(
after
=
self
)
pos_after
=
after
.
relative_position
pos_before
=
after
.
prev_relative_position
...
...
@@ -83,7 +80,7 @@ module RelativePositioning
if
after
.
shift_before?
issue_to_move
=
self
.
class
.
in_projects
(
project_ids
).
find_by!
(
relative_position:
pos_before
)
issue_to_move
.
move_before
@positionable_neighbours
=
[
issue_to_move
]
@positionable_neighbours
=
[
issue_to_move
]
# rubocop:disable Cop/ModuleWithInstanceVariables
pos_before
=
issue_to_move
.
relative_position
end
...
...
@@ -144,4 +141,5 @@ module RelativePositioning
status
end
# rubocop:enable Cop/ModuleWithInstanceVariables
end
app/models/concerns/resolvable_discussion.rb
View file @
9ac0c76b
...
...
@@ -84,7 +84,6 @@ module ResolvableDiscussion
private
# rubocop:disable Cop/ModuleWithInstanceVariables
def
update
# Do not select `Note.resolvable`, so that system notes remain in the collection
notes_relation
=
Note
.
where
(
id:
notes
.
map
(
&
:id
))
...
...
app/models/concerns/routable.rb
View file @
9ac0c76b
...
...
@@ -86,10 +86,9 @@ module Routable
end
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
full_name
if
route
&&
route
.
name
.
present?
@full_name
||=
route
.
name
@full_name
||=
route
.
name
# rubocop:disable Cop/ModuleWithInstanceVariables
else
update_route
if
persisted?
...
...
@@ -113,7 +112,7 @@ module Routable
def
expires_full_path_cache
RequestStore
.
delete
(
full_path_key
)
if
RequestStore
.
active?
@full_path
=
nil
@full_path
=
nil
# rubocop:disable Cop/ModuleWithInstanceVariables
end
def
build_full_path
...
...
@@ -126,10 +125,9 @@ module Routable
private
# rubocop:disable Cop/ModuleWithInstanceVariables
def
uncached_full_path
if
route
&&
route
.
path
.
present?
@full_path
||=
route
.
path
@full_path
||=
route
.
path
# rubocop:disable Cop/ModuleWithInstanceVariables
else
update_route
if
persisted?
...
...
@@ -164,12 +162,11 @@ module Routable
route
.
save
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
prepare_route
route
||
build_route
(
source:
self
)
route
.
path
=
build_full_path
route
.
name
=
build_full_name
@full_path
=
nil
@full_name
=
nil
@full_path
=
nil
# rubocop:disable Cop/ModuleWithInstanceVariables
@full_name
=
nil
# rubocop:disable Cop/ModuleWithInstanceVariables
end
end
app/models/concerns/taskable.rb
View file @
9ac0c76b
...
...
@@ -36,11 +36,10 @@ module Taskable
end
# Called by `TaskList::Summary`
# rubocop:disable Cop/ModuleWithInstanceVariables
def
task_list_items
return
[]
if
description
.
blank?
@task_list_items
||=
Taskable
.
get_tasks
(
description
)
@task_list_items
||=
Taskable
.
get_tasks
(
description
)
# rubocop:disable Cop/ModuleWithInstanceVariables
end
def
tasks
...
...
app/models/concerns/time_trackable.rb
View file @
9ac0c76b
...
...
@@ -36,6 +36,7 @@ module TimeTrackable
end
end
alias_method
:spend_time
=
,
:spend_time
# rubocop:enable Cop/ModuleWithInstanceVariables
def
total_time_spent
timelogs
.
sum
(
:time_spent
)
...
...
@@ -51,11 +52,11 @@ module TimeTrackable
private
# rubocop:disable Cop/ModuleWithInstanceVariables
def
reset_spent_time
timelogs
.
new
(
time_spent:
total_time_spent
*
-
1
,
user:
@time_spent_user
)
timelogs
.
new
(
time_spent:
total_time_spent
*
-
1
,
user:
@time_spent_user
)
# rubocop:disable Cop/ModuleWithInstanceVariables
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
add_or_subtract_spent_time
timelogs
.
new
(
time_spent:
time_spent
,
...
...
@@ -63,17 +64,19 @@ module TimeTrackable
spent_at:
@spent_at
)
end
# rubocop:enable Cop/ModuleWithInstanceVariables
# rubocop:disable Cop/ModuleWithInstanceVariables
def
check_negative_time_spent
return
if
time_spent
.
nil?
||
time_spent
==
:reset
if
time_spent
<
0
&&
(
time_spent
.
abs
>
original_total_time_spent
)
errors
.
add
(
:time_spent
,
'Time to subtract exceeds the total time spent'
)
end
end
# we need to cache the total time spent so multiple calls to #valid?
# doesn't give a false error
def
original_total_time_spent
@original_total_time_spent
||=
total_time_spent
if
time_spent
<
0
&&
(
time_spent
.
abs
>
@original_total_time_spent
)
errors
.
add
(
:time_spent
,
'Time to subtract exceeds the total time spent'
)
end
end
end
app/serializers/concerns/with_pagination.rb
View file @
9ac0c76b
...
...
@@ -14,7 +14,7 @@ module WithPagination
# we shouldn't try to paginate single resources
def
represent
(
resource
,
opts
=
{})
if
paginated?
&&
resource
.
respond_to?
(
:page
)
super
(
@
paginator
.
paginate
(
resource
),
opts
)
super
(
paginator
.
paginate
(
resource
),
opts
)
else
super
(
resource
,
opts
)
end
...
...
app/services/concerns/issues/resolve_discussions.rb
View file @
9ac0c76b
module
Issues
module
ResolveDiscussions
include
Gitlab
::
Utils
::
StrongMemoize
attr_reader
:merge_request_to_resolve_discussions_of_iid
,
:discussion_to_resolve_id
# rubocop:disable Cop/ModuleWithInstanceVariables
...
...
@@ -7,21 +9,20 @@ module Issues
@merge_request_to_resolve_discussions_of_iid
||=
params
.
delete
(
:merge_request_to_resolve_discussions_of
)
@discussion_to_resolve_id
||=
params
.
delete
(
:discussion_to_resolve
)
end
# rubocop:enable Cop/ModuleWithInstanceVariables
# rubocop:disable Cop/ModuleWithInstanceVariables
def
merge_request_to_resolve_discussions_of
return
@merge_request_to_resolve_discussions_of
if
defined?
(
@merge_request_to_resolve_discussions_of
)
@merge_request_to_resolve_discussions_of
=
MergeRequestsFinder
.
new
(
current_user
,
project_id:
project
.
id
)
strong_memoize
(
:merge_request_to_resolve_discussions_of
)
do
MergeRequestsFinder
.
new
(
current_user
,
project_id:
project
.
id
)
.
execute
.
find_by
(
iid:
merge_request_to_resolve_discussions_of_iid
)
end
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
discussions_to_resolve
return
[]
unless
merge_request_to_resolve_discussions_of
@discussions_to_resolve
||=
@discussions_to_resolve
||=
# rubocop:disable Cop/ModuleWithInstanceVariables
if
discussion_to_resolve_id
discussion_or_nil
=
merge_request_to_resolve_discussions_of
.
find_discussion
(
discussion_to_resolve_id
)
...
...
app/services/spam_check_service.rb
View file @
9ac0c76b
...
...
@@ -14,6 +14,7 @@ module SpamCheckService
@recaptcha_verified
=
params
.
delete
(
:recaptcha_verified
)
@spam_log_id
=
params
.
delete
(
:spam_log_id
)
end
# rubocop:enable Cop/ModuleWithInstanceVariables
# In order to be proceed to the spam check process, @spammable has to be
# a dirty instance, which means it should be already assigned with the new
...
...
@@ -26,4 +27,5 @@ module SpamCheckService
user
.
spam_logs
.
find_by
(
id:
@spam_log_id
)
&
.
update!
(
recaptcha_verified:
true
)
end
end
# rubocop:enable Cop/ModuleWithInstanceVariables
end
app/workers/concerns/new_issuable.rb
View file @
9ac0c76b
...
...
@@ -8,18 +8,16 @@ module NewIssuable
user
&&
issuable
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
set_user
(
user_id
)
@user
=
User
.
find_by
(
id:
user_id
)
@user
=
User
.
find_by
(
id:
user_id
)
# rubocop:disable Cop/ModuleWithInstanceVariables
log_error
(
User
,
user_id
)
unless
@user
log_error
(
User
,
user_id
)
unless
@user
# rubocop:disable Cop/ModuleWithInstanceVariables
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
set_issuable
(
issuable_id
)
@issuable
=
issuable_class
.
find_by
(
id:
issuable_id
)
@issuable
=
issuable_class
.
find_by
(
id:
issuable_id
)
# rubocop:disable Cop/ModuleWithInstanceVariables
log_error
(
issuable_class
,
issuable_id
)
unless
@issuable
log_error
(
issuable_class
,
issuable_id
)
unless
@issuable
# rubocop:disable Cop/ModuleWithInstanceVariables
end
def
log_error
(
record_class
,
record_id
)
...
...
config/initializers/fix_local_cache_middleware.rb
View file @
9ac0c76b
...
...
@@ -4,10 +4,9 @@ module LocalCacheRegistryCleanupWithEnsure
LocalStore
=
ActiveSupport
::
Cache
::
Strategy
::
LocalCache
::
LocalStore
# rubocop:disable Cop/ModuleWithInstanceVariables
def
call
(
env
)
LocalCacheRegistry
.
set_cache_for
(
local_cache_key
,
LocalStore
.
new
)
response
=
@app
.
call
(
env
)
response
=
@app
.
call
(
env
)
# rubocop:disable Cop/ModuleWithInstanceVariables
response
[
2
]
=
::
Rack
::
BodyProxy
.
new
(
response
[
2
])
do
LocalCacheRegistry
.
set_cache_for
(
local_cache_key
,
nil
)
end
...
...
config/initializers/rspec_profiling.rb
View file @
9ac0c76b
...
...
@@ -16,14 +16,13 @@ module RspecProfilingExt
end
module
Run
# rubocop:disable Cop/ModuleWithInstanceVariables
def
example_finished
(
*
args
)
super
rescue
=>
err
return
if
@already_logged_example_finished_error
return
if
@already_logged_example_finished_error
# rubocop:disable Cop/ModuleWithInstanceVariables
$stderr
.
puts
"rspec_profiling couldn't collect an example:
#{
err
}
. Further warnings suppressed."
@already_logged_example_finished_error
=
true
@already_logged_example_finished_error
=
true
# rubocop:disable Cop/ModuleWithInstanceVariables
end
alias_method
:example_passed
,
:example_finished
...
...
config/initializers/rugged_use_gitlab_git_attributes.rb
View file @
9ac0c76b
...
...
@@ -14,10 +14,12 @@
module
Rugged
class
Repository
module
UseGitlabGitAttributes
# rubocop:disable Cop/ModuleWithInstanceVariables
def
fetch_attributes
(
name
,
*
)
attributes
.
attributes
(
name
)
end
def
attributes
@attributes
||=
Gitlab
::
Git
::
Attributes
.
new
(
path
)
@attributes
.
attributes
(
name
)
end
end
...
...
lib/api/helpers.rb
View file @
9ac0c76b
...
...
@@ -33,6 +33,10 @@ module API
end
# rubocop:disable Cop/ModuleWithInstanceVariables
# We can't rewrite this with StrongMemoize because `sudo!` would
# actually write to `@current_user`, and `sudo?` would immediately
# call `current_user` again which reads from `@current_user`.
# We should rewrite this in a way that using StrongMemoize is possible
def
current_user
return
@current_user
if
defined?
(
@current_user
)
...
...
@@ -46,6 +50,7 @@ module API
@current_user
end
# rubocop:enable Cop/ModuleWithInstanceVariables
def
sudo?
initial_current_user
!=
current_user
...
...
@@ -394,6 +399,7 @@ module API
private
# rubocop:disable Cop/ModuleWithInstanceVariables
def
initial_current_user
return
@initial_current_user
if
defined?
(
@initial_current_user
)
...
...
@@ -403,8 +409,8 @@ module API
unauthorized!
end
end
# rubocop:enable Cop/ModuleWithInstanceVariables
# rubocop:disable Cop/ModuleWithInstanceVariables
def
sudo!
return
unless
sudo_identifier
...
...
@@ -423,7 +429,7 @@ module API
sudoed_user
=
find_user
(
sudo_identifier
)
not_found!
(
"User with ID or username '
#{
sudo_identifier
}
'"
)
unless
sudoed_user
@current_user
=
sudoed_user
@current_user
=
sudoed_user
# rubocop:disable Cop/ModuleWithInstanceVariables
end
def
sudo_identifier
...
...
lib/api/helpers/internal_helpers.rb
View file @
9ac0c76b
...
...
@@ -8,16 +8,14 @@ module API
attr_reader
:redirected_path
# rubocop:disable Cop/ModuleWithInstanceVariables
def
wiki?
set_project
unless
defined?
(
@wiki
)
@wiki
set_project
unless
defined?
(
@wiki
)
# rubocop:disable Cop/ModuleWithInstanceVariables
@wiki
# rubocop:disable Cop/ModuleWithInstanceVariables
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
project
set_project
unless
defined?
(
@project
)
@project
set_project
unless
defined?
(
@project
)
# rubocop:disable Cop/ModuleWithInstanceVariables
@project
# rubocop:disable Cop/ModuleWithInstanceVariables
end
def
ssh_authentication_abilities
...
...
@@ -78,6 +76,7 @@ module API
@project
,
@wiki
,
@redirected_path
=
Gitlab
::
RepoPath
.
parse
(
params
[
:project
])
end
end
# rubocop:enable Cop/ModuleWithInstanceVariables
# Project id to pass between components that don't share/don't have
# access to the same filesystem mounts
...
...
lib/extracts_path.rb
View file @
9ac0c76b
...
...
@@ -37,11 +37,10 @@ module ExtractsPath
#
# Returns an Array where the first value is the tree-ish and the second is the
# path
# rubocop:disable Cop/ModuleWithInstanceVariables
def
extract_ref
(
id
)
pair
=
[
''
,
''
]
return
pair
unless
@project
return
pair
unless
@project
# rubocop:disable Cop/ModuleWithInstanceVariables
if
id
=~
/^(\h{40})(.+)/
# If the ref appears to be a SHA, we're done, just split the string
...
...
@@ -133,10 +132,10 @@ module ExtractsPath
rescue
RuntimeError
,
NoMethodError
,
InvalidPathError
render_404
end
# rubocop:enable Cop/ModuleWithInstanceVariables
# rubocop:disable Cop/ModuleWithInstanceVariables
def
tree
@tree
||=
@repo
.
tree
(
@commit
.
id
,
@path
)
@tree
||=
@repo
.
tree
(
@commit
.
id
,
@path
)
# rubocop:disable Cop/ModuleWithInstanceVariables
end
private
...
...
@@ -148,10 +147,9 @@ module ExtractsPath
id
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
ref_names
return
[]
unless
@project
return
[]
unless
@project
# rubocop:disable Cop/ModuleWithInstanceVariables
@ref_names
||=
@project
.
repository
.
ref_names
@ref_names
||=
@project
.
repository
.
ref_names
# rubocop:disable Cop/ModuleWithInstanceVariables
end
end
lib/gitlab/cache/request_cache.rb
View file @
9ac0c76b
...
...
@@ -45,12 +45,13 @@ module Gitlab
klass
.
prepend
(
extension
)
end
# rubocop:disable Cop/ModuleWithInstanceVariables
attr_accessor
:request_cache_key_block
def
request_cache_key
(
&
block
)
if
block_given?
@request_cache_key
=
block
self
.
request_cache_key_block
=
block
else
@request_cache_key
request_cache_key_block
end
end
...
...
lib/gitlab/ci/charts.rb
View file @
9ac0c76b
...
...
@@ -2,12 +2,11 @@ module Gitlab
module
Ci
module
Charts
module
DailyInterval
# rubocop:disable Cop/ModuleWithInstanceVariables
def
grouped_count
(
query
)
query
.
group
(
"DATE(
#{
::
Ci
::
Pipeline
.
table_name
}
.created_at)"
)
.
count
(
:created_at
)
.
transform_keys
{
|
date
|
date
.
strftime
(
@format
)
}
.
transform_keys
{
|
date
|
date
.
strftime
(
@format
)
}
# rubocop:disable Cop/ModuleWithInstanceVariables
end
def
interval_step
...
...
lib/gitlab/ci/config/entry/configurable.rb
View file @
9ac0c76b
...
...
@@ -24,21 +24,20 @@ module Gitlab
end
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
compose!
(
deps
=
nil
)
return
unless
valid?
self
.
class
.
nodes
.
each
do
|
key
,
factory
|
factory
.
value
(
@
config
[
key
])
.
value
(
config
[
key
])
.
with
(
key:
key
,
parent:
self
)
@
entries
[
key
]
=
factory
.
create!
entries
[
key
]
=
factory
.
create!
end
yield
if
block_given?
@
entries
.
each_value
do
|
entry
|
entries
.
each_value
do
|
entry
|
entry
.
compose!
(
deps
)
end
end
...
...
lib/gitlab/ci/config/entry/node.rb
View file @
9ac0c76b
...
...
@@ -90,6 +90,12 @@ module Gitlab
def
self
.
aspects
@aspects
||=
[]
end
private
def
entries
@entries
end
end
end
end
...
...
lib/gitlab/ci/config/entry/validatable.rb
View file @
9ac0c76b
...
...
@@ -12,9 +12,8 @@ module Gitlab
end
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
errors
@validator
.
messages
+
descendants
.
flat_map
(
&
:errors
)
@validator
.
messages
+
descendants
.
flat_map
(
&
:errors
)
# rubocop:disable Cop/ModuleWithInstanceVariables
end
class_methods
do
...
...
lib/gitlab/ci/pipeline/chain/helpers.rb
View file @
9ac0c76b
...
...
@@ -3,21 +3,19 @@ module Gitlab
module
Pipeline
module
Chain
module
Helpers
# rubocop:disable Cop/ModuleWithInstanceVariables
def
branch_exists?
return
@is_branch
if
defined?
(
@is_branch
)
include
Gitlab
::
Utils
::
StrongMemoize
@is_branch
=
project
.
repository
.
branch_exists?
(
pipeline
.
ref
)
def
branch_exists?
strong_memoize
(
:is_branch
)
do
project
.
repository
.
branch_exists?
(
pipeline
.
ref
)
end
end
# rubocop:enable Cop/ModuleWithInstanceVariables
# rubocop:disable Cop/ModuleWithInstanceVariables
def
tag_exists?
return
@is_tag
if
defined?
(
@is_tag
)
@is_tag
=
project
.
repository
.
tag_exists?
(
pipeline
.
ref
)
strong_memoize
(
:is_tag
)
do
project
.
repository
.
tag_exists?
(
pipeline
.
ref
)
end
end
# rubocop:enable Cop/ModuleWithInstanceVariables
def
error
(
message
)
pipeline
.
errors
.
add
(
:base
,
message
)
...
...
lib/gitlab/current_settings.rb
View file @
9ac0c76b
...
...
@@ -52,9 +52,8 @@ module Gitlab
::
ApplicationSetting
.
create_from_defaults
||
in_memory_application_settings
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
in_memory_application_settings
@in_memory_application_settings
||=
::
ApplicationSetting
.
new
(
::
ApplicationSetting
.
defaults
)
@in_memory_application_settings
||=
::
ApplicationSetting
.
new
(
::
ApplicationSetting
.
defaults
)
# rubocop:disable Cop/ModuleWithInstanceVariables
rescue
ActiveRecord
::
StatementInvalid
,
ActiveRecord
::
UnknownAttributeError
# In case migrations the application_settings table is not created yet,
# we fallback to a simple OpenStruct
...
...
lib/gitlab/cycle_analytics/base_query.rb
View file @
9ac0c76b
...
...
@@ -11,13 +11,12 @@ module Gitlab
@base_query
||=
stage_query
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
stage_query
query
=
mr_closing_issues_table
.
join
(
issue_table
).
on
(
issue_table
[
:id
].
eq
(
mr_closing_issues_table
[
:issue_id
]))
.
join
(
issue_metrics_table
).
on
(
issue_table
[
:id
].
eq
(
issue_metrics_table
[
:issue_id
]))
.
where
(
issue_table
[
:project_id
].
eq
(
@project
.
id
))
.
where
(
issue_table
[
:project_id
].
eq
(
@project
.
id
))
# rubocop:disable Cop/ModuleWithInstanceVariables
.
where
(
issue_table
[
:deleted_at
].
eq
(
nil
))
.
where
(
issue_table
[
:created_at
].
gteq
(
@options
[
:from
]))
.
where
(
issue_table
[
:created_at
].
gteq
(
@options
[
:from
]))
# rubocop:disable Cop/ModuleWithInstanceVariables
# Load merge_requests
query
=
query
.
join
(
mr_table
,
Arel
::
Nodes
::
OuterJoin
)
...
...
lib/gitlab/cycle_analytics/production_helper.rb
View file @
9ac0c76b
module
Gitlab
module
CycleAnalytics
module
ProductionHelper
# rubocop:disable Cop/ModuleWithInstanceVariables
def
stage_query
super
.
where
(
mr_metrics_table
[
:first_deployed_to_production_at
].
gteq
(
@options
[
:from
]))
super
.
where
(
mr_metrics_table
[
:first_deployed_to_production_at
]
.
gteq
(
@options
[
:from
]))
# rubocop:disable Cop/ModuleWithInstanceVariables
end
end
end
...
...
lib/gitlab/database/rename_reserved_paths_migration/v1/migration_classes.rb
View file @
9ac0c76b
...
...
@@ -3,11 +3,10 @@ module Gitlab
module
RenameReservedPathsMigration
module
V1
module
MigrationClasses
# rubocop:disable Cop/ModuleWithInstanceVariables
module
Routable
def
full_path
if
route
&&
route
.
path
.
present?
@full_path
||=
route
.
path
@full_path
||=
route
.
path
# rubocop:disable Cop/ModuleWithInstanceVariables
else
update_route
if
persisted?
...
...
@@ -31,7 +30,7 @@ module Gitlab
def
prepare_route
route
||
build_route
(
source:
self
)
route
.
path
=
build_full_path
@full_path
=
nil
@full_path
=
nil
# rubocop:disable Cop/ModuleWithInstanceVariables
end
end
...
...
lib/gitlab/import_export/command_line_util.rb
View file @
9ac0c76b
...
...
@@ -30,10 +30,9 @@ module Gitlab
execute
(
%W(tar -
#{
options
}
#{
archive
}
-C
#{
dir
}
)
)
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
execute
(
cmd
)
output
,
status
=
Gitlab
::
Popen
.
popen
(
cmd
)
@shared
.
error
(
Gitlab
::
ImportExport
::
Error
.
new
(
output
.
to_s
))
unless
status
.
zero?
@shared
.
error
(
Gitlab
::
ImportExport
::
Error
.
new
(
output
.
to_s
))
unless
status
.
zero?
# rubocop:disable Cop/ModuleWithInstanceVariables
status
.
zero?
end
...
...
lib/gitlab/metrics/influx_db.rb
View file @
9ac0c76b
...
...
@@ -171,6 +171,7 @@ module Gitlab
@pool
end
end
# rubocop:enable Cop/ModuleWithInstanceVariables
end
end
end
lib/gitlab/metrics/prometheus.rb
View file @
9ac0c76b
...
...
@@ -4,6 +4,7 @@ module Gitlab
module
Metrics
module
Prometheus
include
Gitlab
::
CurrentSettings
include
Gitlab
::
Utils
::
StrongMemoize
REGISTRY_MUTEX
=
Mutex
.
new
PROVIDER_MUTEX
=
Mutex
.
new
...
...
@@ -16,18 +17,19 @@ module Gitlab
::
File
.
writable?
(
multiprocess_files_dir
)
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
prometheus_metrics_enabled?
return
@prometheus_metrics_enabled
if
defined?
(
@prometheus_metrics_enabled
)
@prometheus_metrics_enabled
=
prometheus_metrics_enabled_unmemoize
d
strong_memoize
(
:prometheus_metrics_enabled
)
do
prometheus_metrics_enabled_unmemoized
en
d
end
def
registry
return
@registry
if
@registry
strong_memoize
(
:registry
)
do
REGISTRY_MUTEX
.
synchronize
do
@registry
||=
::
Prometheus
::
Client
.
registry
strong_memoize
(
:registry
)
do
::
Prometheus
::
Client
.
registry
end
end
end
end
...
...
lib/gitlab/path_regex.rb
View file @
9ac0c76b
# rubocop:disable Cop/ModuleWithInstanceVariables
module
Gitlab
module
PathRegex
extend
self
...
...
lib/gitlab/slash_commands/presenters/issue_base.rb
View file @
9ac0c76b
...
...
@@ -10,36 +10,37 @@ module Gitlab
issuable
.
open?
?
'Open'
:
'Closed'
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
project
@
resource
.
project
resource
.
project
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
author
@
resource
.
author
resource
.
author
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
fields
[
{
title:
"Assignee"
,
value:
@resource
.
assignees
.
any?
?
@
resource
.
assignees
.
first
.
name
:
"_None_"
,
value:
resource
.
assignees
.
any?
?
resource
.
assignees
.
first
.
name
:
"_None_"
,
short:
true
},
{
title:
"Milestone"
,
value:
@resource
.
milestone
?
@
resource
.
milestone
.
title
:
"_None_"
,
value:
resource
.
milestone
?
resource
.
milestone
.
title
:
"_None_"
,
short:
true
},
{
title:
"Labels"
,
value:
@resource
.
labels
.
any?
?
@
resource
.
label_names
.
join
(
', '
)
:
"_None_"
,
value:
resource
.
labels
.
any?
?
resource
.
label_names
.
join
(
', '
)
:
"_None_"
,
short:
true
}
]
end
private
attr_reader
:resource
end
end
end
...
...
lib/tasks/gettext.rake
View file @
9ac0c76b
...
...
@@ -23,6 +23,7 @@ namespace :gettext do
desc
'Lint all po files in `locale/'
task
lint: :environment
do
require
'simple_po_parser'
require
'gitlab/utils'
FastGettext
.
silence_errors
files
=
Dir
.
glob
(
Rails
.
root
.
join
(
'locale/*/gitlab.po'
))
...
...
lib/tasks/gitlab/task_helpers.rb
View file @
9ac0c76b
require
'rainbow/ext/string'
require
'gitlab/utils/strong_memoize'
module
Gitlab
TaskFailedError
=
Class
.
new
(
StandardError
)
TaskAbortedByUserError
=
Class
.
new
(
StandardError
)
module
TaskHelpers
include
Gitlab
::
Utils
::
StrongMemoize
extend
self
# Ask if the user wants to continue
...
...
@@ -104,19 +107,17 @@ module Gitlab
Gitlab
.
config
.
gitlab
.
user
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
gitlab_user?
return
@is_gitlab_user
unless
@is_gitlab_user
.
nil?
strong_memoize
(
:is_gitlab_user
)
do
current_user
=
run_command
(
%w(whoami)
).
chomp
@is_gitlab_user
=
current_user
==
gitlab_user
current_user
==
gitlab_user
end
end
# rubocop:disable Cop/ModuleWithInstanceVariables
def
warn_user_is_not_gitlab
return
if
@warned_user_not_gitlab
return
if
gitlab_user?
unless
gitlab_user?
strong_memoize
(
:warned_user_not_gitlab
)
do
current_user
=
run_command
(
%w(whoami)
).
chomp
puts
" Warning "
.
color
(
:black
).
background
(
:yellow
)
...
...
@@ -124,8 +125,6 @@ module Gitlab
puts
" Things may work
\/
fail for the wrong reasons."
puts
" For correct results you should run this as user
#{
gitlab_user
.
color
(
:magenta
)
}
."
puts
""
@warned_user_not_gitlab
=
true
end
end
...
...
qa/qa/runtime/scenario.rb
View file @
9ac0c76b
...
...
@@ -6,13 +6,15 @@ module QA
module
Scenario
extend
self
attr_reader
:attributes
def
attributes
@attributes
||=
{}
end
def
define
(
attribute
,
value
)
(
@attributes
||=
{})
.
store
(
attribute
.
to_sym
,
value
)
attributes
.
store
(
attribute
.
to_sym
,
value
)
define_singleton_method
(
attribute
)
do
@
attributes
[
attribute
.
to_sym
].
tap
do
|
value
|
attributes
[
attribute
.
to_sym
].
tap
do
|
value
|
if
value
.
to_s
.
empty?
raise
ArgumentError
,
"Empty `
#{
attribute
}
` attribute!"
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