module ObjectState::Owner
Public Instance Methods
assign_attributes_from_state_hash(attrs)
click to toggle source
# File lib/object_state/owner.rb, line 37 def assign_attributes_from_state_hash(attrs) key = respond_to?(:model_name) ? model_name.singular : self.class.to_s.underscore return unless model_attrs = attrs.stringify_keys[key] model_id = model_attrs.stringify_keys['id'] || model_attrs.stringify_keys['_id'] return if respond_to?(:id) && model_id.to_s != id.to_s object_state(model_attrs.except(*%i(_id id))).try(:update_model!) end
object_state(attrs = {})
click to toggle source
# File lib/object_state/owner.rb, line 29 def object_state(attrs = {}) self.class.object_state_class.new(self, attrs) end
to_object_state_hash(attrs = {})
click to toggle source
# File lib/object_state/owner.rb, line 33 def to_object_state_hash(attrs = {}) object_state(attrs).try(:to_hash) end