Extract serializable as module again

pull/6097/head
Oliver Günther 7 years ago
parent e0d323e707
commit 266bddeeb4
No known key found for this signature in database
GPG Key ID: 88872239EB414F99
  1. 23
      app/models/queries/filters/serializable.rb
  2. 4
      app/models/queries/filters/shared/custom_fields/base.rb
  3. 4
      app/models/queries/work_packages/filter/work_package_filter.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

@ -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

@ -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

Loading…
Cancel
Save