# File lib/undo/serializer/active_model/connector.rb, line 21 def primary_key_attributes(object, attributes) fields = Array(primary_key_fetcher.call(object)).map(&:to_sym) fields.each_with_object({}) do |field, pk_attributes| pk_attributes[field] = attributes[field] || attributes[field.to_s] end end
class Undo::Serializer::ActiveModel::Connector
Public Instance Methods
associate(object, association, associations)
click to toggle source
# File lib/undo/serializer/active_model/connector.rb, line 40 def associate(object, association, associations) associator.call object, association, associations end
constantize(class_name)
click to toggle source
# File lib/undo/serializer/active_model/connector.rb, line 48 def constantize(class_name) class_name.split('::').inject(Kernel) { |object, name| object = object.const_get(name); object } end
get_option(name, options)
click to toggle source
# File lib/undo/serializer/active_model/connector.rb, line 52 def get_option(name, options) options.fetch name.to_sym do options.fetch name.to_s end end
initialize_object(meta)
click to toggle source
# File lib/undo/serializer/active_model/connector.rb, line 29 def initialize_object(meta) object_class = constantize get_option :class_name, meta pk_attributes = get_option :pk_attributes, meta object_initializer.call object_class, pk_attributes end
persist(object, object_meta)
click to toggle source
# File lib/undo/serializer/active_model/connector.rb, line 36 def persist(object, object_meta) persister.call object unless [false, nil, 0, "false"].include? get_option :persisted, object_meta end
primary_key_attributes(object, attributes)
click to toggle source
serialize_attributes(object)
click to toggle source
# File lib/undo/serializer/active_model/connector.rb, line 44 def serialize_attributes(object) attribute_serializer.call(object) || {} end