From 266bddeeb4dc3fa3d65d1351e432c46ad800a8cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Mon, 8 Jan 2018 07:32:06 +0100 Subject: [PATCH] Extract serializable as module again --- app/models/queries/filters/serializable.rb | 23 ++++++++++--------- .../filters/shared/custom_fields/base.rb | 4 +++- .../filter/work_package_filter.rb | 4 +++- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/app/models/queries/filters/serializable.rb b/app/models/queries/filters/serializable.rb index 9e233001f8..d64109ecc0 100644 --- a/app/models/queries/filters/serializable.rb +++ b/app/models/queries/filters/serializable.rb @@ -28,21 +28,22 @@ # See doc/COPYRIGHT.rdoc for more details. #++ -require_relative 'base' - module Queries module Filters - class Serializable < Base + module Serializable include ActiveModel::Serialization + extend ActiveSupport::Concern - # (de-)serialization - def self.from_hash(filter_hash) - filter_hash.keys.map do |field| - begin - create!(name, filter_hash[field]) - rescue ::Queries::Filters::InvalidError - Rails.logger.error "Failed to constantize field filter #{field} from hash." - ::Queries::NotExistingFilter.create!(field) + class_methods do + # (de-)serialization + def from_hash(filter_hash) + filter_hash.keys.map do |field| + begin + create!(name, filter_hash[field]) + rescue ::Queries::Filters::InvalidError + Rails.logger.error "Failed to constantize field filter #{field} from hash." + ::Queries::NotExistingFilter.create!(field) + end end end end diff --git a/app/models/queries/filters/shared/custom_fields/base.rb b/app/models/queries/filters/shared/custom_fields/base.rb index 9f81255dd4..ababda65fa 100644 --- a/app/models/queries/filters/shared/custom_fields/base.rb +++ b/app/models/queries/filters/shared/custom_fields/base.rb @@ -30,7 +30,9 @@ module Queries::Filters::Shared module CustomFields - class Base < Queries::Filters::Serializable + class Base < Queries::Filters::Base + include Queries::Filters::Serializable + attr_reader :custom_field attr_reader :custom_field_context diff --git a/app/models/queries/work_packages/filter/work_package_filter.rb b/app/models/queries/work_packages/filter/work_package_filter.rb index 37f0e5143c..7ff7b49b0c 100644 --- a/app/models/queries/work_packages/filter/work_package_filter.rb +++ b/app/models/queries/work_packages/filter/work_package_filter.rb @@ -28,7 +28,9 @@ # See doc/COPYRIGHT.rdoc for more details. #++ -class Queries::WorkPackages::Filter::WorkPackageFilter < ::Queries::Filters::Serializable +class Queries::WorkPackages::Filter::WorkPackageFilter < ::Queries::Filters::Base + include ::Queries::Filters::Serializable + self.model = WorkPackage def human_name