Sha256: db6f423fe0fbb2778fd79777f8fcce297710f4ef2d4493e4a9dbc2a9e2f3f25d

Contents?: true

Size: 1.56 KB

Versions: 14

Compression:

Stored size: 1.56 KB

Contents

module Protobuf
  module ActiveRecord
    module NestedAttributes
      extend ::ActiveSupport::Concern

      included do
        include ::Heredity::InheritableClassInstanceVariables

        class << self
          attr_accessor :_protobuf_nested_attributes
        end

        @_protobuf_nested_attributes = []

        inheritable_attributes :_protobuf_nested_attributes
      end

      module ClassMethods
        # :nodoc:
        def accepts_nested_attributes_for(*attr_names)
          attribute_names = attr_names.dup
          attribute_names.extract_options!
          attribute_names.map!(&:to_s)

          super

          self._protobuf_nested_attributes += attribute_names
        end
      end

      # :nodoc:
      def assign_nested_attributes_for_collection_association(association_name, attributes_collection)
        if attributes_collection.first.is_a?(::Protobuf::Message)
          reflection = self.class._reflect_on_association(association_name)
          attributes_collection = attributes_collection.map do |attributes|
            reflection.klass.attributes_from_proto(attributes)
          end
        end

        super(association_name, attributes_collection)
      end

      # :nodoc:
      def assign_nested_attributes_for_one_to_one_association(association_name, attributes)
        if attributes.is_a?(::Protobuf::Message)
          reflection = self.class._reflect_on_association(association_name)
          attributes = reflection.klass.attributes_from_proto(attributes)
        end

        super(association_name, attributes)
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
protobuf-activerecord-7.0.0 lib/protobuf/active_record/nested_attributes.rb
protobuf-activerecord-6.1.0 lib/protobuf/active_record/nested_attributes.rb
protobuf-activerecord-6.0.0 lib/protobuf/active_record/nested_attributes.rb
protobuf-activerecord-5.2.0 lib/protobuf/active_record/nested_attributes.rb
protobuf-activerecord-5.1.0 lib/protobuf/active_record/nested_attributes.rb
protobuf-activerecord-5.0.0 lib/protobuf/active_record/nested_attributes.rb
protobuf-activerecord-5.1.0.beta lib/protobuf/active_record/nested_attributes.rb
protobuf-activerecord-5.0.0.beta lib/protobuf/active_record/nested_attributes.rb
protobuf-activerecord-3.6.1 lib/protobuf/active_record/nested_attributes.rb
protobuf-activerecord-3.6.0 lib/protobuf/active_record/nested_attributes.rb
protobuf-activerecord-3.5.1 lib/protobuf/active_record/nested_attributes.rb
protobuf-activerecord-3.5.0 lib/protobuf/active_record/nested_attributes.rb
protobuf-activerecord-3.4.4 lib/protobuf/active_record/nested_attributes.rb
protobuf-activerecord-3.4.4.pre lib/protobuf/active_record/nested_attributes.rb