Sha256: 9c39c4edda2d30efe87e05b6c32dca70c03cbd950609b53ca737527e3dba9b78

Contents?: true

Size: 1.07 KB

Versions: 49

Compression:

Stored size: 1.07 KB

Contents

module Para
  class ControllerResource < CanCan::ControllerResource
    # Todo : Document why this extension was added ?
    def assign_attributes(resource)
      if @options[:singleton] && parent_resource && resource.respond_to?(:"#{ parent_name }=")
        resource.send(:"#{ parent_name }=", parent_resource)
      end

      initial_attributes.each do |attr_name, value|
        resource.send(:"#{ attr_name }=", value)
      end

      resource
    end

    # Remove automatic params assignation and let our controllers do it
    # manually, letting our attribute fields to parse the params with a
    # reference to the current resource.
    #
    # Before this override, some attribute fields raised during #parse_input
    # because of the controller resource that was missing at the time it
    # was called (during the resource instanciation ...)
    #
    def build_resource
      resource = resource_base.new

      unless @options[:bypass_params_assignation]
        resource.assign_attributes(resource_params || {})
      end

      assign_attributes(resource)
    end
  end
end

Version data entries

49 entries across 49 versions & 1 rubygems

Version Path
para-0.12.4 lib/para/controller_resource.rb
para-0.12.3 lib/para/controller_resource.rb
para-0.12.2 lib/para/controller_resource.rb
para-0.12.1 lib/para/controller_resource.rb
para-0.12.0 lib/para/controller_resource.rb
para-0.11.4 lib/para/controller_resource.rb
para-0.11.3 lib/para/controller_resource.rb
para-0.11.2 lib/para/controller_resource.rb
para-0.11.1 lib/para/controller_resource.rb
para-0.11.0 lib/para/controller_resource.rb
para-0.10.0 lib/para/controller_resource.rb
para-0.9.4 lib/para/controller_resource.rb
para-0.9.3.3 lib/para/controller_resource.rb
para-0.9.3.2 lib/para/controller_resource.rb
para-0.9.3.1 lib/para/controller_resource.rb
para-0.9.2 lib/para/controller_resource.rb
para-0.9.0 lib/para/controller_resource.rb
para-0.8.15 lib/para/controller_resource.rb
para-0.8.14 lib/para/controller_resource.rb
para-0.8.13 lib/para/controller_resource.rb