Sha256: 13ceb0df91a744b6274b8b14e01e09393cc82f5f2c815a39fb524a3a3b6ec660

Contents?: true

Size: 1.68 KB

Versions: 11

Compression:

Stored size: 1.68 KB

Contents

module Restly::Base::Resource::Specification::MassAssignmentSecurity

  class DynamicAuthorizer < Restly::Proxies::Base

    attr_reader :spec

    def initialize(spec)
      @spec = spec
      super({ default: ActiveModel::MassAssignmentSecurity::BlackList.new })
    end

    private

    def method_missing(m, *args, &block)

      # Try to set the proper authorizer!
      if spec.accessible_attributes.present?
        __setobj__ ({ default: spec.accessible_attributes })

      elsif spec.protected_attributes.present?
        __setobj__ ({ default: spec.protected_attributes })

      end

      super
    end

  end

  class AccessibleAttributes < Restly::Proxies::Base

    attr_reader :spec

    def initialize(spec)
      @spec = spec
      super ActiveModel::MassAssignmentSecurity::WhiteList.new
    end

    private

    def method_missing(m, *args, &block)
      reload_specification! unless super.present?
      super
    end

    def reload_specification!
      accepts = spec.actions.map { |action| action['accepts_parameters'] }.flatten if spec.actions.present?
      __setobj__ ActiveModel::MassAssignmentSecurity::WhiteList.new accepts
    end

  end

  class ProtectedAttributes < Restly::Proxies::Base

    attr_reader :spec

    def initialize(spec)
      @spec = spec
      super ActiveModel::MassAssignmentSecurity::BlackList.new
    end

    private

    def method_missing(m, *args, &block)
      reload_specification! unless super.present?
      super
    end

    def reload_specification!
      rejects = spec.actions.map { |action| action['rejects_parameters'] }.flatten if spec.actions.present?
      __setobj__ ActiveModel::MassAssignmentSecurity::BlackList.new rejects
    end

  end

end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
restly-0.0.1.beta.10 lib/restly/base/resource/specification/mass_assignment_security.rb
restly-0.0.1.beta.9 lib/restly/base/resource/specification/mass_assignment_security.rb
restly-0.0.1.beta.6 lib/restly/base/resource/specification/mass_assignment_security.rb
restly-0.0.1.beta.5 lib/restly/base/resource/specification/mass_assignment_security.rb
restly-0.0.1.beta.4 lib/restly/base/resource/specification/mass_assignment_security.rb
restly-0.0.1.beta.3 lib/restly/base/resource/specification/mass_assignment_security.rb
restly-0.0.1.beta.2 lib/restly/base/resource/specification/mass_assignment_security.rb
restly-0.0.1.beta.1 lib/restly/base/resource/specification/mass_assignment_security.rb
restly-0.0.1.alpha.22 lib/restly/base/resource/specification/mass_assignment_security.rb
restly-0.0.1.alpha.19 lib/restly/base/resource/specification/mass_assignment_security.rb
restly-0.0.1.alpha.18 lib/restly/base/resource/specification/mass_assignment_security.rb