diff options
-rw-r--r-- | app/serializers/base_serializer.rb | 10 | ||||
-rw-r--r-- | app/serializers/build_entity.rb | 2 | ||||
-rw-r--r-- | app/serializers/commit_entity.rb | 6 | ||||
-rw-r--r-- | app/serializers/deployment_entity.rb | 2 | ||||
-rw-r--r-- | app/serializers/entity_request.rb | 4 | ||||
-rw-r--r-- | app/serializers/environment_entity.rb | 2 | ||||
-rw-r--r-- | app/serializers/request_aware_entity.rb | 11 | ||||
-rw-r--r-- | spec/serializers/entity_request_spec.rb | 8 |
8 files changed, 14 insertions, 31 deletions
diff --git a/app/serializers/base_serializer.rb b/app/serializers/base_serializer.rb index aeb01dc2ad5..de9a181db90 100644 --- a/app/serializers/base_serializer.rb +++ b/app/serializers/base_serializer.rb @@ -1,17 +1,11 @@ class BaseSerializer def initialize(parameters = {}) - @entity = self.class.entity_class @request = EntityRequest.new(parameters) - @opts = { request: @request } - end - - def set(parameters) - @request.merge!(parameters) - self end def represent(resource, opts = {}) - @entity.represent(resource, @opts.reverse_merge(opts)) + self.class.entity_class + .represent(resource, opts.merge(request: @request)) end def self.entity(entity_class) diff --git a/app/serializers/build_entity.rb b/app/serializers/build_entity.rb index 203bd747ad9..3d9ac66de0e 100644 --- a/app/serializers/build_entity.rb +++ b/app/serializers/build_entity.rb @@ -19,6 +19,6 @@ class BuildEntity < Grape::Entity private def url_to(route, build) - @urls.send("#{route}_url", build.project.namespace, build.project, build) + send("#{route}_url", build.project.namespace, build.project, build) end end diff --git a/app/serializers/commit_entity.rb b/app/serializers/commit_entity.rb index 827782e85bb..f7eba6fc1e3 100644 --- a/app/serializers/commit_entity.rb +++ b/app/serializers/commit_entity.rb @@ -4,9 +4,9 @@ class CommitEntity < API::Entities::RepoCommit expose :author, using: UserEntity expose :commit_url do |commit| - @urls.namespace_project_tree_url( - @request.project.namespace, - @request.project, + namespace_project_tree_url( + request.project.namespace, + request.project, id: commit.id) end end diff --git a/app/serializers/deployment_entity.rb b/app/serializers/deployment_entity.rb index d743b44c4a0..ad6fc8d665b 100644 --- a/app/serializers/deployment_entity.rb +++ b/app/serializers/deployment_entity.rb @@ -11,7 +11,7 @@ class DeploymentEntity < Grape::Entity end expose :ref_url do |deployment| - @urls.namespace_project_tree_url( + namespace_project_tree_url( deployment.project.namespace, deployment.project, id: deployment.ref) diff --git a/app/serializers/entity_request.rb b/app/serializers/entity_request.rb index 12ceb38b284..456ba1174c0 100644 --- a/app/serializers/entity_request.rb +++ b/app/serializers/entity_request.rb @@ -5,10 +5,6 @@ class EntityRequest # that is present in the controller (see #20045). # def initialize(parameters) - merge!(parameters) - end - - def merge!(parameters) parameters.each do |key, value| define_singleton_method(key) { value } end diff --git a/app/serializers/environment_entity.rb b/app/serializers/environment_entity.rb index e80a4335f53..ee4392cc46d 100644 --- a/app/serializers/environment_entity.rb +++ b/app/serializers/environment_entity.rb @@ -10,7 +10,7 @@ class EnvironmentEntity < Grape::Entity expose :stoppable? expose :environment_url do |environment| - @urls.namespace_project_environment_url( + namespace_project_environment_url( environment.project.namespace, environment.project, environment) diff --git a/app/serializers/request_aware_entity.rb b/app/serializers/request_aware_entity.rb index 1586507492d..ff8c1142abc 100644 --- a/app/serializers/request_aware_entity.rb +++ b/app/serializers/request_aware_entity.rb @@ -1,10 +1,11 @@ module RequestAwareEntity - attr_reader :request + extend ActiveSupport::Concern - def initialize(object, options = {}) - super(object, options) + included do + include Gitlab::Routing.url_helpers + end - @request = options.fetch(:request) - @urls = Gitlab::Routing.url_helpers + def request + @options.fetch(:request) end end diff --git a/spec/serializers/entity_request_spec.rb b/spec/serializers/entity_request_spec.rb index 1c220a7b95d..86654adfd54 100644 --- a/spec/serializers/entity_request_spec.rb +++ b/spec/serializers/entity_request_spec.rb @@ -15,12 +15,4 @@ describe EntityRequest do expect { subject.some_method }.to raise_error NoMethodError end end - - describe '#merge!' do - before { subject.merge!(build: 'some build') } - - it 'appends parameters' do - expect(subject.build).to eq 'some build' - end - end end |