Sha256: b8ab5a00a1858425b894bb2f6c29289419841d267d49a64240c44036742dba89

Contents?: true

Size: 1.63 KB

Versions: 33

Compression:

Stored size: 1.63 KB

Contents

require 'active_support/concern'

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

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

            super(attributes, options)
          end

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

            super(attributes, options)
          end
        end

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

          super(attributes, options)
        end

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

          super(attributes, options)
        end

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

          super(attributes, options)
        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
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
protobuf-activerecord-3.6.0 lib/protobuf/active_record/mass_assignment_security/persistence.rb
protobuf-activerecord-3.5.1 lib/protobuf/active_record/mass_assignment_security/persistence.rb
protobuf-activerecord-3.5.0 lib/protobuf/active_record/mass_assignment_security/persistence.rb
protobuf-activerecord-3.4.4 lib/protobuf/active_record/mass_assignment_security/persistence.rb
protobuf-activerecord-3.4.4.pre lib/protobuf/active_record/mass_assignment_security/persistence.rb
protobuf-activerecord-3.4.3 lib/protobuf/active_record/mass_assignment_security/persistence.rb
protobuf-activerecord-3.4.2 lib/protobuf/active_record/mass_assignment_security/persistence.rb
protobuf-activerecord-3.4.1 lib/protobuf/active_record/mass_assignment_security/persistence.rb
protobuf-activerecord-3.4.0 lib/protobuf/active_record/mass_assignment_security/persistence.rb
protobuf-activerecord-3.3.8 lib/protobuf/active_record/mass_assignment_security/persistence.rb
protobuf-activerecord-3.3.7 lib/protobuf/active_record/mass_assignment_security/persistence.rb
protobuf-activerecord-3.3.6 lib/protobuf/active_record/mass_assignment_security/persistence.rb
protobuf-activerecord-3.3.5 lib/protobuf/active_record/mass_assignment_security/persistence.rb
protobuf-activerecord-3.3.4 lib/protobuf/active_record/mass_assignment_security/persistence.rb
protobuf-activerecord-3.3.3 lib/protobuf/active_record/mass_assignment_security/persistence.rb
protobuf-activerecord-3.3.2 lib/protobuf/active_record/mass_assignment_security/persistence.rb
protobuf-activerecord-3.3.1 lib/protobuf/active_record/mass_assignment_security/persistence.rb
protobuf-activerecord-3.3.0 lib/protobuf/active_record/mass_assignment_security/persistence.rb
protobuf-activerecord-3.2.2 lib/protobuf/active_record/mass_assignment_security/persistence.rb
protobuf-activerecord-3.2.1 lib/protobuf/active_record/mass_assignment_security/persistence.rb