Sha256: 3509f81bfd4e638d621cbe2ee02aa390214b7ebd8b6c6472a00879278e23669a

Contents?: true

Size: 1.13 KB

Versions: 19

Compression:

Stored size: 1.13 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

      # 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}_type".to_sym] = resource.class.name
          retval["#{k}_id".to_sym] = resource.id
        end

        retval
      end

      def load_attributes!
        return unless view.respond_to?(:controller_path)

        # Assign namespace based off controller path unless given
        @attributes[:namespace] ||= view.controller_path.split('/')[0...-1].join('/')
      end

    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
effective_datatables-4.32.0 app/models/effective/effective_datatable/attributes.rb
effective_datatables-4.31.4 app/models/effective/effective_datatable/attributes.rb
effective_datatables-4.31.3 app/models/effective/effective_datatable/attributes.rb
effective_datatables-4.31.2 app/models/effective/effective_datatable/attributes.rb
effective_datatables-4.31.1 app/models/effective/effective_datatable/attributes.rb
effective_datatables-4.31.0 app/models/effective/effective_datatable/attributes.rb
effective_datatables-4.30.2 app/models/effective/effective_datatable/attributes.rb
effective_datatables-4.30.1 app/models/effective/effective_datatable/attributes.rb
effective_datatables-4.30.0 app/models/effective/effective_datatable/attributes.rb
effective_datatables-4.29.0 app/models/effective/effective_datatable/attributes.rb
effective_datatables-4.26.0 app/models/effective/effective_datatable/attributes.rb
effective_datatables-4.25.3 app/models/effective/effective_datatable/attributes.rb
effective_datatables-4.25.2 app/models/effective/effective_datatable/attributes.rb
effective_datatables-4.25.1 app/models/effective/effective_datatable/attributes.rb
effective_datatables-4.25.0 app/models/effective/effective_datatable/attributes.rb
effective_datatables-4.24.2 app/models/effective/effective_datatable/attributes.rb
effective_datatables-4.24.1 app/models/effective/effective_datatable/attributes.rb
effective_datatables-4.24.0 app/models/effective/effective_datatable/attributes.rb
effective_datatables-4.23.0 app/models/effective/effective_datatable/attributes.rb