diff options
author | Toon Claes <toon@gitlab.com> | 2019-02-28 19:57:34 +0100 |
---|---|---|
committer | Toon Claes <toon@gitlab.com> | 2019-02-28 19:57:34 +0100 |
commit | 62d7990b9bb30cf33ed87017c5c633d1cccc75c2 (patch) | |
tree | c3e1b69c58a412ba1c6f50a0337a23d9f9d6e1a4 /lib/api/entities.rb | |
parent | f6453eca992a9c142268e78ac782cef98110d183 (diff) | |
download | gitlab-ce-tc-standard-gem.tar.gz |
Ran standardrb --fix on the whole codebasetc-standard-gem
Inspired by https://twitter.com/searls/status/1101137953743613952 I
decided to try https://github.com/testdouble/standard on our codebase.
It's opinionated, but at least it's a _standard_.
Diffstat (limited to 'lib/api/entities.rb')
-rw-r--r-- | lib/api/entities.rb | 108 |
1 files changed, 54 insertions, 54 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 18f15632f2b..b01f65709bb 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -21,7 +21,7 @@ module API expose :link do expose :file_path, as: :url expose :markdown do |_entity| - self.markdown_link + markdown_link end end @@ -46,7 +46,7 @@ module API end expose :avatar_path, if: ->(user, options) { options.fetch(:only_path, false) && user.avatar_path } - expose :custom_attributes, using: 'API::Entities::CustomAttribute', if: :with_custom_attributes + expose :custom_attributes, using: "API::Entities::CustomAttribute", if: :with_custom_attributes expose :web_url do |user, options| Gitlab::Routing.url_helpers.user_url(user) @@ -176,7 +176,7 @@ module API end end - expose :license, with: 'API::Entities::LicenseBasic', if: :license do |project| + expose :license, with: "API::Entities::LicenseBasic", if: :license do |project| project.repository.license end @@ -186,8 +186,8 @@ module API expose :star_count, :forks_count expose :last_activity_at - expose :namespace, using: 'API::Entities::NamespaceBasic' - expose :custom_attributes, using: 'API::Entities::CustomAttribute', if: :with_custom_attributes + expose :namespace, using: "API::Entities::NamespaceBasic" + expose :custom_attributes, using: "API::Entities::CustomAttribute", if: :with_custom_attributes # rubocop: disable CodeReuse/ActiveRecord def self.preload_relation(projects_relation, options = {}) @@ -196,8 +196,8 @@ module API # N+1 is solved then by using `subject.tags.map(&:name)` # MR describing the solution: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/20555 projects_relation.preload(:project_feature, :route) - .preload(:import_state, :tags) - .preload(namespace: [:route, :owner]) + .preload(:import_state, :tags) + .preload(namespace: [:route, :owner]) end # rubocop: enable CodeReuse/ActiveRecord end @@ -210,11 +210,11 @@ module API expose_url(api_v4_projects_path(id: project.id)) end - expose :issues, if: -> (project, options) { issues_available?(project, options) } do |project| + expose :issues, if: ->(project, options) { issues_available?(project, options) } do |project| expose_url(api_v4_projects_issues_path(id: project.id)) end - expose :merge_requests, if: -> (project, options) { mrs_available?(project, options) } do |project| + expose :merge_requests, if: ->(project, options) { mrs_available?(project, options) } do |project| expose_url(api_v4_projects_merge_requests_path(id: project.id)) end @@ -271,7 +271,7 @@ module API expose :printing_merge_request_link_enabled expose :merge_method - expose :statistics, using: 'API::Entities::ProjectStatistics', if: :statistics + expose :statistics, using: "API::Entities::ProjectStatistics", if: :statistics # rubocop: disable CodeReuse/ActiveRecord def self.preload_relation(projects_relation, options = {}) @@ -280,10 +280,10 @@ module API # N+1 is solved then by using `subject.tags.map(&:name)` # MR describing the solution: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/20555 super(projects_relation).preload(:group) - .preload(project_group_links: { group: :route }, - fork_network: :root_project, - fork_network_member: :forked_from_project, - forked_from_project: [:route, :forks, :tags, namespace: :route]) + .preload(project_group_links: {group: :route}, + fork_network: :root_project, + fork_network_member: :forked_from_project, + forked_from_project: [:route, :forks, :tags, namespace: :route]) end # rubocop: enable CodeReuse/ActiveRecord @@ -342,10 +342,10 @@ module API expose :parent_id end - expose :custom_attributes, using: 'API::Entities::CustomAttribute', if: :with_custom_attributes + expose :custom_attributes, using: "API::Entities::CustomAttribute", if: :with_custom_attributes expose :statistics, if: :statistics do - with_options format_with: -> (value) { value.to_i } do + with_options format_with: ->(value) { value.to_i } do expose :storage_size expose :repository_size expose :lfs_objects_size @@ -359,7 +359,7 @@ module API projects = GroupProjectsFinder.new( group: group, current_user: options[:current_user], - options: { only_owned: true } + options: {only_owned: true} ).execute Entities::Project.prepare_relation(projects) @@ -369,7 +369,7 @@ module API projects = GroupProjectsFinder.new( group: group, current_user: options[:current_user], - options: { only_shared: true } + options: {only_shared: true} ).execute Entities::Project.prepare_relation(projects) @@ -400,7 +400,7 @@ module API class CommitDetail < Commit expose :stats, using: Entities::CommitStats, if: :stats expose :status - expose :last_pipeline, using: 'API::Entities::PipelineBasic' + expose :last_pipeline, using: "API::Entities::PipelineBasic" expose :project_id end @@ -521,8 +521,8 @@ module API class Milestone < Grape::Entity expose :id, :iid - expose :project_id, if: -> (entity, options) { entity&.project_id } - expose :group_id, if: -> (entity, options) { entity&.group_id } + expose :project_id, if: ->(entity, options) { entity&.project_id } + expose :group_id, if: ->(entity, options) { entity&.group_id } expose :title, :description expose :state, :created_at, :updated_at expose :due_date @@ -559,7 +559,7 @@ module API Gitlab::UrlBuilder.build(issue) end - expose :time_stats, using: 'API::Entities::IssuableTimeStats' do |issue| + expose :time_stats, using: "API::Entities::IssuableTimeStats" do |issue| issue end end @@ -648,10 +648,10 @@ module API merge_request.metrics&.latest_closed_at end - expose :title_html, if: -> (_, options) { options[:render_html] } do |entity| + expose :title_html, if: ->(_, options) { options[:render_html] } do |entity| MarkupHelper.markdown_field(entity, :title) end - expose :description_html, if: -> (_, options) { options[:render_html] } do |entity| + expose :description_html, if: ->(_, options) { options[:render_html] } do |entity| MarkupHelper.markdown_field(entity, :description) end expose :target_branch, :source_branch @@ -681,15 +681,15 @@ module API expose :discussion_locked expose :should_remove_source_branch?, as: :should_remove_source_branch expose :force_remove_source_branch?, as: :force_remove_source_branch - expose :allow_collaboration, if: -> (merge_request, _) { merge_request.for_fork? } + expose :allow_collaboration, if: ->(merge_request, _) { merge_request.for_fork? } # Deprecated - expose :allow_collaboration, as: :allow_maintainer_to_push, if: -> (merge_request, _) { merge_request.for_fork? } + expose :allow_collaboration, as: :allow_maintainer_to_push, if: ->(merge_request, _) { merge_request.for_fork? } expose :web_url do |merge_request| Gitlab::UrlBuilder.build(merge_request) end - expose :time_stats, using: 'API::Entities::IssuableTimeStats' do |merge_request| + expose :time_stats, using: "API::Entities::IssuableTimeStats" do |merge_request| merge_request end @@ -705,19 +705,19 @@ module API merge_request.merge_request_diff.real_size end - expose :latest_build_started_at, if: -> (_, options) { build_available?(options) } do |merge_request, _options| + expose :latest_build_started_at, if: ->(_, options) { build_available?(options) } do |merge_request, _options| merge_request.metrics&.latest_build_started_at end - expose :latest_build_finished_at, if: -> (_, options) { build_available?(options) } do |merge_request, _options| + expose :latest_build_finished_at, if: ->(_, options) { build_available?(options) } do |merge_request, _options| merge_request.metrics&.latest_build_finished_at end - expose :first_deployed_to_production_at, if: -> (_, options) { build_available?(options) } do |merge_request, _options| + expose :first_deployed_to_production_at, if: ->(_, options) { build_available?(options) } do |merge_request, _options| merge_request.metrics&.first_deployed_to_production_at end - expose :pipeline, using: Entities::PipelineBasic, if: -> (_, options) { build_available?(options) } do |merge_request, _options| + expose :pipeline, using: Entities::PipelineBasic, if: ->(_, options) { build_available?(options) } do |merge_request, _options| merge_request.metrics&.pipeline end @@ -725,9 +725,9 @@ module API # Allow the status of a rebase to be determined expose :merge_error - expose :rebase_in_progress?, as: :rebase_in_progress, if: -> (_, options) { options[:include_rebase_in_progress] } + expose :rebase_in_progress?, as: :rebase_in_progress, if: ->(_, options) { options[:include_rebase_in_progress] } - expose :diverged_commits_count, as: :diverged_commits_count, if: -> (_, options) { options[:include_diverged_commits_count] } + expose :diverged_commits_count, as: :diverged_commits_count, if: ->(_, options) { options[:include_diverged_commits_count] } def build_available?(options) options[:project]&.feature_available?(:builds, options[:current_user]) @@ -783,7 +783,7 @@ module API class Note < Grape::Entity # Only Issue and MergeRequest have iid - NOTEABLE_TYPES_WITH_IID = %w(Issue MergeRequest).freeze + NOTEABLE_TYPES_WITH_IID = %w[Issue MergeRequest].freeze expose :id expose :type @@ -842,7 +842,7 @@ module API class CommitStatus < Grape::Entity expose :id, :sha, :ref, :status, :name, :target_url, :description, - :created_at, :started_at, :finished_at, :allow_failure, :coverage + :created_at, :started_at, :finished_at, :allow_failure, :coverage expose :author, using: Entities::UserBasic end @@ -862,7 +862,7 @@ module API expose :push_event_payload, as: :push_data, using: PushEventPayload, - if: -> (event, _) { event.push? } + if: ->(event, _) { event.push? } expose :author_username do |event, options| event.author&.username @@ -875,8 +875,8 @@ module API class Todo < Grape::Entity expose :id - expose :project, using: Entities::ProjectIdentity, if: -> (todo, _) { todo.project_id } - expose :group, using: 'API::Entities::NamespaceBasic', if: -> (todo, _) { todo.group_id } + expose :project, using: Entities::ProjectIdentity, if: ->(todo, _) { todo.project_id } + expose :group, using: "API::Entities::NamespaceBasic", if: ->(todo, _) { todo.group_id } expose :author, using: Entities::UserBasic expose :action_name expose :target_type @@ -909,12 +909,12 @@ module API end class Namespace < NamespaceBasic - expose :members_count_with_descendants, if: -> (namespace, opts) { expose_members_count_with_descendants?(namespace, opts) } do |namespace, _| + expose :members_count_with_descendants, if: ->(namespace, opts) { expose_members_count_with_descendants?(namespace, opts) } do |namespace, _| namespace.users_with_descendants.count end def expose_members_count_with_descendants?(namespace, opts) - namespace.kind == 'group' && Ability.allowed?(opts[:current_user], :admin_group, namespace) + namespace.kind == "group" && Ability.allowed?(opts[:current_user], :admin_group, namespace) end end @@ -987,10 +987,10 @@ module API # MySQL doesn't support LIMIT inside an IN subquery if Gitlab::Database.mysql? - project_ids = relation.pluck('projects.id') + project_ids = relation.pluck("projects.id") namespace_ids = relation.pluck(:namespace_id) else - project_ids = relation.select('projects.id') + project_ids = relation.select("projects.id") namespace_ids = relation.select(:namespace_id) end @@ -1135,7 +1135,7 @@ module API MarkupHelper.markdown_field(entity, :description) end expose :created_at - expose :author, using: Entities::UserBasic, if: -> (release, _) { release.author.present? } + expose :author, using: Entities::UserBasic, if: ->(release, _) { release.author.present? } expose :commit, using: Entities::Commit expose :assets do @@ -1229,7 +1229,7 @@ module API class Job < JobBasic # artifacts_file is included in job_artifacts, but kept for backward compatibility (remove in api/v5) - expose :artifacts_file, using: JobArtifactFile, if: -> (job, opts) { job.artifacts? } + expose :artifacts_file, using: JobArtifactFile, if: ->(job, opts) { job.artifacts? } expose :job_artifacts, as: :artifacts, using: JobArtifact expose :runner, with: Runner expose :artifacts_expire_at @@ -1251,7 +1251,7 @@ module API class Variable < Grape::Entity expose :key, :value - expose :protected?, as: :protected, if: -> (entity, _) { entity.respond_to?(:protected?) } + expose :protected?, as: :protected, if: ->(entity, _) { entity.respond_to?(:protected?) } end class Pipeline < PipelineBasic @@ -1293,15 +1293,15 @@ module API class LicenseBasic < Grape::Entity expose :key, :name, :nickname expose :url, as: :html_url - expose(:source_url) { |license| license.meta['source'] } + expose(:source_url) { |license| license.meta["source"] } end class License < LicenseBasic expose :popular?, as: :popular - expose(:description) { |license| license.meta['description'] } - expose(:conditions) { |license| license.meta['conditions'] } - expose(:permissions) { |license| license.meta['permissions'] } - expose(:limitations) { |license| license.meta['limitations'] } + expose(:description) { |license| license.meta["description"] } + expose(:conditions) { |license| license.meta["conditions"] } + expose(:permissions) { |license| license.meta["permissions"] } + expose(:limitations) { |license| license.meta["limitations"] } expose :content end @@ -1348,7 +1348,7 @@ module API expose :name expose :state expose :gates, using: FeatureGate do |model| - model.gates.map do |gate| + model.gates.map { |gate| value = model.gate_values[gate.key] # By default all gate values are populated. Only show relevant ones. @@ -1356,8 +1356,8 @@ module API next end - { key: gate.key, value: value } - end.compact + {key: gate.key, value: value} + }.compact end end @@ -1532,7 +1532,7 @@ module API class Badge < BasicBadgeDetails expose :id expose :kind do |badge| - badge.type == 'ProjectBadge' ? 'project' : 'group' + badge.type == "ProjectBadge" ? "project" : "group" end end |