Sha256: 51040b0f059fb22feaa2784bfc3e0b57989113e9e41a4faf5cfb3c55e1d61e91

Contents?: true

Size: 703 Bytes

Versions: 12

Compression:

Stored size: 703 Bytes

Contents

# frozen_string_literal: true

module CanCan
  module ControllerResourceBuilder
    protected

    def build_resource
      resource = resource_base.new(resource_params || {})
      assign_attributes(resource)
    end

    def assign_attributes(resource)
      resource.send("#{parent_name}=", parent_resource) if @options[:singleton] && parent_resource
      initial_attributes.each do |attr_name, value|
        resource.send("#{attr_name}=", value)
      end
      resource
    end

    def initial_attributes
      current_ability.attributes_for(@params[:action].to_sym, resource_class).delete_if do |key, _value|
        resource_params && resource_params.include?(key)
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/cancancan-3.6.1/lib/cancan/controller_resource_builder.rb
cancancan-3.5.0 lib/cancan/controller_resource_builder.rb
cancancan-3.4.0 lib/cancan/controller_resource_builder.rb
cancancan-3.3.0 lib/cancan/controller_resource_builder.rb
cancancan-3.2.2 lib/cancan/controller_resource_builder.rb
cancancan-3.2.1 lib/cancan/controller_resource_builder.rb
cancancan-3.2.0 lib/cancan/controller_resource_builder.rb
cancancan-3.1.0 lib/cancan/controller_resource_builder.rb
cancancan-3.0.2 lib/cancan/controller_resource_builder.rb
cancancan-3.0.1 lib/cancan/controller_resource_builder.rb
cancancan-3.0.0 lib/cancan/controller_resource_builder.rb
cancancan-3.0.0.rc1 lib/cancan/controller_resource_builder.rb