lib/heimdallr/proxy/record.rb in heimdallr-1.0.1 vs lib/heimdallr/proxy/record.rb in heimdallr-1.0.2
- old
+ new
@@ -138,15 +138,20 @@
# @return [String]
def class_name
@record.class.name
end
- # Records cannot be restricted twice.
+ # Records cannot be restricted with different context or options.
#
+ # @return self
# @raise [RuntimeError]
- def restrict(context)
- raise RuntimeError, "Records 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
# A whitelisting dispatcher for attribute-related method calls.
# Every unknown method is first normalized (that is, stripped of its +?+ or +=+
# suffix). Then, if the normalized form is whitelisted, it is passed to the
@@ -235,21 +240,22 @@
"#<Heimdallr::Proxy::Record: #{@record.inspect}>"
end
# Return the associated security metadata. The returned hash will contain keys
# +:context+, +:record+, +: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: @record.class,
- context: @context,
- record: @record,
- options: @options
+ model: @record.class,
+ context: @context,
+ record: @record,
+ options: @options,
+ restrictions: @restrictions,
}.merge(@restrictions.reflection)
end
def creatable?
@restrictions.can? :create
\ No newline at end of file