lib/scrivito/basic_widget.rb in scrivito_sdk-0.18.1 vs lib/scrivito/basic_widget.rb in scrivito_sdk-0.30.0.rc1
- old
+ new
@@ -23,11 +23,11 @@
# Create a new Widget.
# The new Widget must be stored inside a container (i.e. an Obj or another Widget)
# before it can be used.
#
- # See {BasicObj.create Obj.create} for a detailed overview of how to set attributes.
+ # See {Scrivito::BasicObj.create Obj.create} for a detailed overview of how to set attributes.
# @api public
# @param [Hash] attributes
#
# @example Create a widget using a subclass
# # you can create widgets by explicitly providing the attribute `_obj_class`
@@ -49,28 +49,28 @@
obj.revision
end
# Update the attributes of this Widget
#
- # See {BasicObj.create Obj.create} for a detailed overview of how to set attributes
+ # See {Scrivito::BasicObj.create Obj.create} for a detailed overview of how to set attributes
# @api public
# @param [Hash] attributes
def update(attributes)
obj.update(_widget_pool: { self => attributes })
reload
end
- # Destroys the {BasicWidget Widget} in the current {Workspace}
+ # Destroys the {Scrivito::BasicWidget Widget} in the current {Workspace}
# @api public
def destroy
new_widget_list = container[container_field_name] - [self]
container.update(container_field_name => new_widget_list)
end
- # Clones the {BasicWidget Widget}. The clone gets all
+ # Clones the {Scrivito::BasicWidget Widget}. The clone gets all
# attributes of the original widget except nested widget attributes.
- # The clone is not attached to an {BasicObj Obj} initially.
+ # The clone is not attached to an {Scrivito::BasicObj Obj} initially.
# It only becomes usable by assigning it to a widget attribute of an Obj.
#
# @example
# # From another_obj, take the first widget in my_widgets,
# # and put a clone in obj's my_widgets.
@@ -105,14 +105,25 @@
def eql?(other)
self == other
end
- # Reverts content changes of this widget. Widget attributes of this widget are not effected.
- # After calling this method it's as if this widget has been never modified in the current working copy.
- # This method does not work with +new+ or +deleted+ widgets.
- # This method also does also not work for the +published+ workspace or the +rtc+ working copy.
+ #
+ # Reverts all changes made to the +Widget+ in the current workspace.
+ #
+ # @api public
+ #
+ # @note This method does not support +Widget+s, which are +new+.
+ # Please use {Scrivito::BasicWidget#destroy Widget#destroy} to destroy them.
+ # @note This method does not support +Widget+s, which are +deleted+.
+ # Please use {Scrivito::BasicObj#revert Obj#revert} to restore them.
+ #
+ # @raise [ScrivitoError] If the current workspace is +published+.
+ # @raise [ScrivitoError] If the current workspace is the +rtc+ workspace.
+ # @raise [ScrivitoError] If the +Widget+ is +new+.
+ # @raise [ScrivitoError] If the +Widget+ is +deleted+.
+ #
def revert
workspace.assert_revertable
case modification
when Modification::UNMODIFIED
@@ -168,19 +179,23 @@
else
super
end
end
- # returns the entity ({BasicObj} or {BasicWidget}) that references this widget
+ # returns the entity ({Scrivito::BasicObj} or {Scrivito::BasicWidget}) that references this widget
# @api public
def container
@container || cache_container_and_field_name_for_widget.first
end
# returns the name of the widget field that references this widget
# @api public
def container_field_name
@container_field_name || cache_container_and_field_name_for_widget.second
+ end
+
+ def has_attribute?(key)
+ key.to_s == '_obj_class' || super
end
def inspect
if @id
if @obj