Sha256: 4c963fb89e74d2c953a71005fb6b98d9d6ce4ac89251fc57b55f3006e35948b5

Contents?: true

Size: 1.45 KB

Versions: 33

Compression:

Stored size: 1.45 KB

Contents

require 'active_support/concern'

module Protobuf
  module ActiveRecord
    module Persistence
      extend ::ActiveSupport::Concern

      module ClassMethods
        # :nodoc:
        def create(attributes = {}, &block)
          attributes = attributes_from_proto(attributes) if attributes.is_a?(::Protobuf::Message)

          super(attributes, &block)
        end

        # :nodoc:
        def create!(attributes = {}, &block)
          attributes = attributes_from_proto(attributes) if attributes.is_a?(::Protobuf::Message)

          super(attributes, &block)
        end
      end

      # Override Active Record's initialize method so it can accept a protobuf
      # message as it's attributes.
      # :noapi:
      def initialize(*args, &block)
        args[0] = attributes_from_proto(args.first) if args.first.is_a?(::Protobuf::Message)

        super(*args, &block)
      end

      # :nodoc:
      def assign_attributes(attributes)
        attributes = attributes_from_proto(attributes) if attributes.is_a?(::Protobuf::Message)

        super(attributes)
      end

      # :nodoc:
      def update_attributes(attributes)
        attributes = attributes_from_proto(attributes) if attributes.is_a?(::Protobuf::Message)

        super(attributes)
      end

      # :nodoc:
      def update_attributes!(attributes)
        attributes = attributes_from_proto(attributes) if attributes.is_a?(::Protobuf::Message)

        super(attributes)
      end
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
protobuf-activerecord-3.2.0 lib/protobuf/active_record/persistence.rb
protobuf-activerecord-3.1.1 lib/protobuf/active_record/persistence.rb
protobuf-activerecord-3.1.0 lib/protobuf/active_record/persistence.rb
protobuf-activerecord-3.1.0.rc1 lib/protobuf/active_record/persistence.rb
protobuf-activerecord-3.1.0.alpha2 lib/protobuf/active_record/persistence.rb
protobuf-activerecord-3.1.0.alpha lib/protobuf/active_record/persistence.rb
protobuf-activerecord-3.0.2 lib/protobuf/active_record/persistence.rb
protobuf-activerecord-3.0.1 lib/protobuf/active_record/persistence.rb
protobuf-activerecord-3.0.0 lib/protobuf/active_record/persistence.rb
protobuf-activerecord-3.0.0.rc4 lib/protobuf/active_record/persistence.rb
protobuf-activerecord-3.0.0.rc3 lib/protobuf/active_record/persistence.rb
protobuf-activerecord-3.0.0.rc2 lib/protobuf/active_record/persistence.rb
protobuf-activerecord-3.0.0.pre lib/protobuf/active_record/persistence.rb