Sha256: bdf43c514f30e2efbe16449f2b4b0c12ca658c100a7b6668f5339064701fafed

Contents?: true

Size: 1.06 KB

Versions: 39

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

module Effective
  module EffectiveDatatable
    module Attributes

      private

      def assert_attributes!
        if datatables_ajax_request? || datatables_inline_request?
          raise 'expected attributes to be present' unless attributes.present?
        end
      end

      def load_attributes!
        return unless view.respond_to?(:controller_path)
        @attributes[:namespace] ||= view.controller_path.split('/')[0...-1].join('/')
      end

      # Polymorphic shorthand attributes.
      # If you pass resource: User(1), it sets resource_id: 1, resource_type: 'User'
      def initial_attributes(attributes)
        return {} if attributes.blank?

        resources = attributes.select { |k, v| v.kind_of?(ActiveRecord::Base) }
        return attributes if resources.blank?

        retval = attributes.except(*resources.keys)

        resources.each do |k, resource|
          retval["#{k}_id".to_sym] = resource.id
          retval["#{k}_type".to_sym] = resource.class.name
        end

        retval
      end

    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
effective_datatables-4.20.5 app/models/effective/effective_datatable/attributes.rb
effective_datatables-4.20.4 app/models/effective/effective_datatable/attributes.rb
effective_datatables-4.20.3 app/models/effective/effective_datatable/attributes.rb
effective_datatables-4.20.2 app/models/effective/effective_datatable/attributes.rb
effective_datatables-4.20.1 app/models/effective/effective_datatable/attributes.rb
effective_datatables-4.20.0 app/models/effective/effective_datatable/attributes.rb
effective_datatables-4.19.1 app/models/effective/effective_datatable/attributes.rb
effective_datatables-4.19.0 app/models/effective/effective_datatable/attributes.rb
effective_datatables-4.18.0 app/models/effective/effective_datatable/attributes.rb
effective_datatables-4.17.4 app/models/effective/effective_datatable/attributes.rb
effective_datatables-4.17.3 app/models/effective/effective_datatable/attributes.rb
effective_datatables-4.17.2 app/models/effective/effective_datatable/attributes.rb
effective_datatables-4.17.1 app/models/effective/effective_datatable/attributes.rb
effective_datatables-4.17.0 app/models/effective/effective_datatable/attributes.rb
effective_datatables-4.16.2 app/models/effective/effective_datatable/attributes.rb
effective_datatables-4.16.1 app/models/effective/effective_datatable/attributes.rb
effective_datatables-4.16.0 app/models/effective/effective_datatable/attributes.rb
effective_datatables-4.15.2 app/models/effective/effective_datatable/attributes.rb
effective_datatables-4.15.1 app/models/effective/effective_datatable/attributes.rb
effective_datatables-4.15.0 app/models/effective/effective_datatable/attributes.rb