Sha256: 047811fdda6045151d6ea7e230516da3a246e48e127405f157dd840ad9be6ad5

Contents?: true

Size: 1.17 KB

Versions: 5

Compression:

Stored size: 1.17 KB

Contents

module RailsAdmin
  module Adapters
    module ActiveRecord
      class AbstractObject
        # undef almost all of this class's methods so it will pass almost
        # everything through to its delegate using method_missing (below).
        instance_methods.each { |m| undef_method m unless m.to_s =~ /(^__|^send$|^object_id$)/ }
        #                                                  ^^^^^
        # the unnecessary "to_s" above is a workaround for meta_where, see
        # https://github.com/sferik/rails_admin/issues/374

        attr_accessor :object

        def initialize(object)
          self.object = object
        end

        def set_attributes(attributes)
          object.assign_attributes(attributes) if attributes
        end

        def save(options = {validate: true})
          object.save(**options)
        end

        if RUBY_VERSION >= '2.7'
          def method_missing(method_name, *args, **kwargs, &block)
            object.send(method_name, *args, **kwargs, &block)
          end
        else
          def method_missing(method_name, *args, &block)
            object.send(method_name, *args, &block)
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rails_admin-2.3.1 lib/rails_admin/adapters/active_record/abstract_object.rb
rails_admin-2.3.0 lib/rails_admin/adapters/active_record/abstract_object.rb
rails_admin-2.2.1 lib/rails_admin/adapters/active_record/abstract_object.rb
rails_admin-2.2.0 lib/rails_admin/adapters/active_record/abstract_object.rb
rails_admin-2.1.1 lib/rails_admin/adapters/active_record/abstract_object.rb