lib/heimdallr/proxy/collection.rb in heimdallr-1.0.1 vs lib/heimdallr/proxy/collection.rb in heimdallr-1.0.2

- old
+ new

@@ -19,15 +19,20 @@ @context, @scope, @options = context, scope, options @restrictions = @scope.restrictions(context) end - # Collections cannot be restricted twice. + # Collections cannot be restricted with different context or options. # + # @return self # @raise [RuntimeError] - def restrict(*args) - raise RuntimeError, "Collections cannot be restricted twice" + def restrict(context, options=nil) + if @context == context && options.nil? + self + else + raise RuntimeError, "Heimdallr proxies cannot be restricted with nonmatching context or options" + end end # @private # @macro [attach] delegate_as_constructor # A proxy for +$1+ method which adds fixtures to the attribute list and @@ -206,21 +211,22 @@ "#<Heimdallr::Proxy::Collection: #{@scope.to_sql}>" end # Return the associated security metadata. The returned hash will contain keys # +:context+, +:scope+ and +:options+, corresponding to the parameters in - # {#initialize}, and +:model+, representing the model class. + # {#initialize}, +:model+ and +:restrictions+, representing the model class. # # Such a name was deliberately selected for this method in order to reduce namespace # pollution. # # @return [Hash] def reflect_on_security { - model: @scope, - context: @context, - scope: @scope, - options: @options + model: @scope, + context: @context, + scope: @scope, + options: @options, + restrictions: @restrictions, }.merge(@restrictions.reflection) end def creatable? @restrictions.can? :create \ No newline at end of file