Sha256: 9d22992a72cefb1084ed422c5cace3a05f45bd685adccc6811db960adf1630e7
Contents?: true
Size: 1.77 KB
Versions: 8
Compression:
Stored size: 1.77 KB
Contents
# frozen_string_literal: true module Katalyst module Tables module Collection module Core # :nodoc: extend ActiveSupport::Concern include ActiveModel::Model include ActiveModel::Attributes include ActiveModel::Dirty include ActiveSupport::Configurable include Reducers class_methods do def permitted_params _default_attributes.to_h.each_with_object([]) do |(k, v), h| h << case v when Array { k => [] } else k end end end end included do attr_accessor :items delegate :model, :each, :count, :empty?, to: :items, allow_nil: true delegate :model_name, to: :model, allow_nil: true end def initialize(**options) super clear_changes_information end def filter # no-op by default end def filtered? self.class.new.filters != filters end def filters attributes.except("page", "sort") end def apply(items) @items = items reducers.build do |_| filter self end.call(self) self end def with_params(params) self.attributes = params.permit(self.class.permitted_params) self end # Returns a hash of the current attributes that have changed from defaults. def to_params attributes.slice(*changed) end def inspect "#<#{self.class.name} @attributes=#{attributes.inspect} @model=\"#{model}\" @count=#{items&.count}>" end end end end end
Version data entries
8 entries across 8 versions & 1 rubygems