Sha256: 61ecc24a68f19939d5770ddbef13618aa4fed61111b88078affc954433ebf075

Contents?: true

Size: 1007 Bytes

Versions: 14

Compression:

Stored size: 1007 Bytes

Contents

# frozen_string_literal: true

module ConvenientService
  module Common
    module Plugins
      module AssignsAttributesInConstructor
        module UsingActiveModelAttributeAssignment
          class Middleware < Core::MethodChainMiddleware
            ##
            # TODO: Consider creation of a plugin that assigns `*args` with `assign_attributes` as well, not only `**kwargs`.
            # Check `Method#parameters` for a possible solution.
            # https://ruby-doc.org/core-3.1.0/Method.html#method-i-parameters
            #
            def next(*args, **kwargs, &block)
              chain.next(*args, **kwargs, &block)

              ##
              # NOTE: `assign_attributes` expects `attr_writer` for all `kwargs` keys.
              #
              # https://api.rubyonrails.org/classes/ActiveModel/AttributeAssignment.html#method-i-assign_attributes
              #
              entity.assign_attributes(kwargs)
            end
          end
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
convenient_service-0.11.0 lib/convenient_service/common/plugins/assigns_attributes_in_constructor/using_active_model_attribute_assignment/middleware.rb
convenient_service-0.10.1 lib/convenient_service/common/plugins/assigns_attributes_in_constructor/using_active_model_attribute_assignment/middleware.rb
convenient_service-0.10.0 lib/convenient_service/common/plugins/assigns_attributes_in_constructor/using_active_model_attribute_assignment/middleware.rb
convenient_service-0.9.0 lib/convenient_service/common/plugins/assigns_attributes_in_constructor/using_active_model_attribute_assignment/middleware.rb
convenient_service-0.8.0 lib/convenient_service/common/plugins/assigns_attributes_in_constructor/using_active_model_attribute_assignment/middleware.rb
convenient_service-0.7.0 lib/convenient_service/common/plugins/assigns_attributes_in_constructor/using_active_model_attribute_assignment/middleware.rb
convenient_service-0.6.0 lib/convenient_service/common/plugins/assigns_attributes_in_constructor/using_active_model_attribute_assignment/middleware.rb
convenient_service-0.5.0 lib/convenient_service/common/plugins/assigns_attributes_in_constructor/using_active_model_attribute_assignment/middleware.rb
convenient_service-0.4.0 lib/convenient_service/common/plugins/assigns_attributes_in_constructor/using_active_model_attribute_assignment/middleware.rb
convenient_service-0.3.1 lib/convenient_service/common/plugins/assigns_attributes_in_constructor/using_active_model_attribute_assignment/middleware.rb
convenient_service-0.3.0 lib/convenient_service/common/plugins/assigns_attributes_in_constructor/using_active_model_attribute_assignment/middleware.rb
convenient_service-0.2.1 lib/convenient_service/common/plugins/assigns_attributes_in_constructor/using_active_model_attribute_assignment/middleware.rb
convenient_service-0.2.0 lib/convenient_service/common/plugins/assigns_attributes_in_constructor/using_active_model_attribute_assignment/middleware.rb
convenient_service-0.1.0 lib/convenient_service/common/plugins/assigns_attributes_in_constructor/using_active_model_attribute_assignment/middleware.rb