Read about our upcoming Code of Conduct on this issue

Commit 75f5fa99 authored by Douwe Maan's avatar Douwe Maan
Browse files

Enable Rails/Delegate

parent e295189744bb
......@@ -763,7 +763,7 @@ Rails/Date:
# Prefer delegate method for delegations.
Rails/Delegate:
Enabled: false
Enabled: true
# Prefer `find_by` over `where.first`.
Rails/FindBy:
......
module ApplicationSettingsHelper
def gravatar_enabled?
current_application_settings.gravatar_enabled?
end
def signup_enabled?
current_application_settings.signup_enabled?
end
def signin_enabled?
current_application_settings.signin_enabled?
end
delegate :gravatar_enabled?,
:signup_enabled?,
:signin_enabled?,
:akismet_enabled?,
:koding_enabled?,
to: :current_application_settings
def user_oauth_applications?
current_application_settings.user_oauth_applications
end
def askimet_enabled?
current_application_settings.akismet_enabled?
end
def koding_enabled?
current_application_settings.koding_enabled?
end
def allowed_protocols_present?
current_application_settings.enabled_git_access_protocol.present?
end
......
......@@ -89,13 +89,9 @@ def restricted_visibility_levels(show_all = false)
current_application_settings.restricted_visibility_levels || []
end
def default_project_visibility
current_application_settings.default_project_visibility
end
def default_group_visibility
current_application_settings.default_group_visibility
end
delegate :default_project_visibility,
:default_group_visibility,
to: :current_application_settings
def skip_level?(form_model, level)
form_model.is_a?(Project) && !form_model.visibility_level_allowed?(level)
......
......@@ -233,9 +233,7 @@ def project_id
gl_project_id
end
def project_name
project.name
end
delegate :name, to: :project, prefix: true
def repo_url
auth = "gitlab-ci-token:#{ensure_token!}@"
......
......@@ -153,9 +153,7 @@ def artifacts
builds.latest.with_artifacts_not_expired.includes(project: [:namespace])
end
def project_id
project.id
end
delegate :id, to: :project, prefix: true
# For now the only user who participates is the user who triggered
def participants(_current_user = nil)
......
......@@ -838,9 +838,7 @@ def valid_repo?
false
end
def empty_repo?
repository.empty_repo?
end
delegate :empty_repo?, to: :repository
def repo
repository.raw
......@@ -1029,9 +1027,7 @@ def forked_from?(project)
forked? && project == forked_from_project
end
def forks_count
forks.count
end
delegate :count, to: :forks, prefix: true
def origin_merge_requests
merge_requests.where(source_project_id: self.id)
......
......@@ -60,9 +60,7 @@ def repository_exists?
!!repository.exists?
end
def empty?
pages.empty?
end
delegate :empty?, to: :pages
# Returns an Array of Gitlab WikiPage instances or an
# empty Array if this Wiki has no pages.
......@@ -160,9 +158,7 @@ def hook_attrs
}
end
def repository_storage_path
project.repository_storage_path
end
delegate :repository_storage_path, to: :project
private
......
......@@ -487,9 +487,7 @@ def exists?
end
cache_method :exists?
def empty?
raw_repository.empty?
end
delegate :empty?, to: :raw_repository
cache_method :empty?
# The size of this repository in megabytes.
......@@ -508,9 +506,7 @@ def branch_names
end
cache_method :branch_names, fallback: []
def tag_names
raw_repository.tag_names
end
delegate :tag_names, to: :raw_repository
cache_method :tag_names, fallback: []
def branch_count
......
......@@ -6,9 +6,7 @@ def initialize(can_set, cannot_set)
@cannot_set = cannot_set
end
def size
to_set.size
end
delegate :size, to: :to_set
def self.empty
new(Set.new, Set.new)
......
......@@ -28,9 +28,7 @@ def system_hook_service
SystemHooksService.new
end
def repository
project.repository
end
delegate :repository, to: :project
# Add an error to the specified model for restricted visibility levels
def deny_visibility_level(model, denied_visibility_level = nil)
......
......@@ -10,9 +10,7 @@ def execute(pipeline)
end
end
def project
pipeline.project
end
delegate :project, to: :pipeline
private
......
......@@ -33,7 +33,7 @@
Abuse Reports
%span.badge.count= number_with_delimiter(AbuseReport.count(:all))
- if askimet_enabled?
- if akismet_enabled?
= nav_link(controller: :spam_logs) do
= link_to admin_spam_logs_path, title: "Spam Logs" do
%span
......
......@@ -24,9 +24,7 @@ def get(path, extra_query = {})
response.parsed
end
def expired?
connection.expired?
end
delegate :expired?, to: :connection
def refresh!
response = connection.refresh!
......
......@@ -21,9 +21,7 @@ class AccessDeniedError < StandardError; end
PROTECTION_DEV_CAN_MERGE = 3
class << self
def values
options.values
end
delegate :values, to: :options
def all_values
options_with_owner.values
......
......@@ -91,9 +91,7 @@ def exists?
blank_node? || @entries.include?(@path)
end
def empty?
children.empty?
end
delegate :empty?, to: :children
def total_size
descendant_pattern = %r{^#{Regexp.escape(@path)}}
......
......@@ -25,9 +25,7 @@ def ensure_application_settings!
settings || in_memory_application_settings
end
def sidekiq_throttling_enabled?
current_application_settings.sidekiq_throttling_enabled?
end
delegate :sidekiq_throttling_enabled?, to: :current_application_settings
def in_memory_application_settings
@in_memory_application_settings ||= ::ApplicationSetting.new(::ApplicationSetting.defaults)
......
......@@ -218,9 +218,7 @@ def parents
raw_commit.parents.map { |c| Gitlab::Git::Commit.new(c) }
end
def tree
raw_commit.tree
end
delegate :tree, to: :raw_commit
def stats
Gitlab::Git::CommitStats.new(self)
......
......@@ -162,13 +162,9 @@ def has_commits?
!empty?
end
def empty?
rugged.empty?
end
def bare?
rugged.bare?
end
delegate :empty?,
:bare?,
to: :rugged
def repo_exists?
!!rugged
......@@ -565,9 +561,7 @@ def commit_count(ref)
# will trigger a +:mixed+ reset and the working directory will be
# replaced with the content of the index. (Untracked and ignored files
# will be left alone)
def reset(ref, reset_type)
rugged.reset(ref, reset_type)
end
delegate :reset, to: :rugged
# Mimic the `git clean` command and recursively delete untracked files.
# Valid keys that can be passed in the +options+ hash are:
......
......@@ -7,9 +7,7 @@ def project_association
raise NotImplementedError
end
def number
raw_data.number
end
delegate :number, to: :raw_data
def find_condition
{ iid: number }
......
......@@ -43,9 +43,7 @@ def email
attribute_value(:email)
end
def dn
entry.dn
end
delegate :dn, to: :entry
private
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment