Sha256: 7bfae71908fb766863a9c8e8c801af178f426e3206c985754c79f10f53e342f8

Contents?: true

Size: 1.03 KB

Versions: 29

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

module Katalyst
  module Tables
    module Collection
      module HasParams # :nodoc:
        extend ActiveSupport::Concern

        refine Object do
          def to_params
            as_json
          end
        end

        refine ActiveModel::AttributeSet do
          def to_params
            to_h.transform_values(&:to_params).as_json
          end
        end

        refine ActiveModel::Attributes do
          def to_params
            if respond_to?(:changed)
              @attributes.to_params.slice(*changed)
            else
              @attributes.to_params
            end
          end
        end

        using HasParams

        # Returns a hash of the current attributes that have changed from defaults.
        # This uses Refinements internally so it needs to be exposed publicly with this super call.
        # rubocop:disable Lint/UselessMethodDefinition
        def to_params
          super
        end
        # rubocop:enable Lint/UselessMethodDefinition
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
katalyst-tables-3.7.0 app/models/concerns/katalyst/tables/collection/has_params.rb
katalyst-tables-3.6.2 app/models/concerns/katalyst/tables/collection/has_params.rb
katalyst-tables-3.6.1 app/models/concerns/katalyst/tables/collection/has_params.rb
katalyst-tables-3.6.0 app/models/concerns/katalyst/tables/collection/has_params.rb
katalyst-tables-3.5.5 app/models/concerns/katalyst/tables/collection/has_params.rb
katalyst-tables-3.5.4 app/models/concerns/katalyst/tables/collection/has_params.rb
katalyst-tables-3.5.3 app/models/concerns/katalyst/tables/collection/has_params.rb
katalyst-tables-3.5.2 app/models/concerns/katalyst/tables/collection/has_params.rb
katalyst-tables-3.5.1 app/models/concerns/katalyst/tables/collection/has_params.rb
katalyst-tables-3.5.0 app/models/concerns/katalyst/tables/collection/has_params.rb
katalyst-tables-3.4.6 app/models/concerns/katalyst/tables/collection/has_params.rb
katalyst-tables-3.4.5 app/models/concerns/katalyst/tables/collection/has_params.rb
katalyst-tables-3.4.4 app/models/concerns/katalyst/tables/collection/has_params.rb
katalyst-tables-3.4.3 app/models/concerns/katalyst/tables/collection/has_params.rb
katalyst-tables-3.4.2 app/models/concerns/katalyst/tables/collection/has_params.rb
katalyst-tables-3.4.1 app/models/concerns/katalyst/tables/collection/has_params.rb
katalyst-tables-3.4.0 app/models/concerns/katalyst/tables/collection/has_params.rb
katalyst-tables-3.3.4 app/models/concerns/katalyst/tables/collection/has_params.rb
katalyst-tables-3.3.3 app/models/concerns/katalyst/tables/collection/has_params.rb
katalyst-tables-3.3.2 app/models/concerns/katalyst/tables/collection/has_params.rb