Last active
February 25, 2019 02:52
-
-
Save mknkisk/b5859acdbd3820afeaec77baa620fe21 to your computer and use it in GitHub Desktop.
mongoid v6.1.1 not allowed fields detector
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/ruby | |
# frozen_string_literal: true | |
# USAGE: | |
# {RAILS_ROOT}/bin/rails r mongoid_not_allowed_fields_detector.rb | |
Rails.application.eager_load! | |
# mongoid v6.1.1 | |
# Mongoid.destructive_fields | |
# @see https://github.com/mongodb/mongoid/blob/aa2c63f4418f22395ab32473688ed695103707e2/lib/mongoid/config.rb#L84 | |
MONGOID_RESERVED_FIELDS = [ | |
:flagged_destroys, | |
:add_atomic_pull, | |
:add_atomic_unset, | |
:delayed_atomic_sets, | |
:atomic_path, | |
:atomic_array_pushes, | |
:atomic_array_pulls, | |
:atomic_array_add_to_sets, | |
:atomic_pulls, | |
:delayed_atomic_pulls, | |
:delayed_atomic_unsets, | |
:atomic_attribute_name, | |
:atomic_position, | |
:atomic_updates, | |
:process_flagged_destroys, | |
:_updates, | |
:atomic_delete_modifier, | |
:atomic_paths, | |
:atomic_insert_modifier, | |
:flag_as_destroyed, | |
:atomic_pushes, | |
:atomic_sets, | |
:atomic_unsets, | |
:[], | |
:[]=, | |
:attributes, | |
:attributes=, | |
:has_attribute?, | |
:read_attribute, | |
:attribute_present?, | |
:write_attribute, | |
:remove_attribute, | |
:assign_attributes, | |
:raw_attributes, | |
:attributes_before_type_cast, | |
:has_attribute_before_type_cast?, | |
:attribute_missing?, | |
:read_attribute_before_type_cast, | |
:write_attributes, | |
:typed_attributes, | |
:process_attributes, | |
:clone, | |
:dup, | |
:changed, | |
:changes, | |
:changed?, | |
:changed_attributes, | |
:remove_change, | |
:post_persist, | |
:setters, | |
:move_changes, | |
:children_changed?, | |
:previous_changes, | |
:__evolve_object_id__, | |
:attribute_names, | |
:apply_defaults, | |
:apply_pre_processed_defaults, | |
:apply_post_processed_defaults, | |
:using_object_ids?, | |
:database_field_name, | |
:apply_default, | |
:lazy_settable?, | |
:inspect, | |
:run_callbacks, | |
:run_before_callbacks, | |
:run_after_callbacks, | |
:callback_executable?, | |
:in_callback_state?, | |
:_matches?, | |
:atomically, | |
:fail_due_to_validation!, | |
:fail_due_to_callback!, | |
:hasherizer, | |
:upsert, | |
:update, | |
:update_attribute, | |
:update_attributes, | |
:update!, | |
:update_attributes!, | |
:save, | |
:save!, | |
:positionally, | |
:__metadata, | |
:relation_metadata, | |
:embedded?, | |
:embedded_many?, | |
:embedded_one?, | |
:metadata_name, | |
:referenced_many?, | |
:referenced_one?, | |
:reload_relations, | |
:__metadata=, | |
:reload, | |
:serializable_hash, | |
:shard_key_fields, | |
:shard_key_selector, | |
:persisted?, | |
:new_record?, | |
:destroyed?, | |
:readonly?, | |
:marked_for_destruction?, | |
:flagged_for_destroy=, | |
:new_record=, | |
:destroyed=, | |
:pushable?, | |
:updateable?, | |
:settable?, | |
:flagged_for_destroy?, | |
:cache_key, | |
:_children, | |
:_parent, | |
:_root, | |
:parentize, | |
:_reset_memoized_children!, | |
:collect_children, | |
:remove_child, | |
:hereditary?, | |
:reset_persisted_children, | |
:flag_children_persisted, | |
:_parent=, | |
:_root?, | |
:valid?, | |
:read_attribute_for_validation, | |
:begin_validate, | |
:exit_validate, | |
:validated?, | |
:performing_validations?, | |
:validating_with_query?, | |
:<=>, | |
:==, | |
:===, | |
:eql?, | |
:_synced, | |
:_syncable?, | |
:_synced?, | |
:remove_inverse_keys, | |
:update_inverse_keys, | |
:persisted?, | |
:assign_attributes, | |
:sanitize_for_mass_assignment, | |
:sanitize_forbidden_attributes, | |
:valid?, | |
:validate, | |
:errors, | |
:validate!, | |
:read_attribute_for_validation, | |
:invalid?, | |
:validates_with, | |
:run_validations!, | |
:raise_validation_error, | |
:==, | |
:options, | |
:collection, | |
:client, | |
:cluster, | |
:database_name, | |
:collection_name, | |
:storage_options, | |
:to_json, | |
:`, | |
:methods, | |
:singleton_methods, | |
:protected_methods, | |
:private_methods, | |
:public_methods, | |
:to_yaml, | |
:to_yaml_properties, | |
:blank?, | |
:presence, | |
:present?, | |
:psych_to_yaml, | |
:as_json, | |
:acts_like?, | |
:to_param, | |
:to_query, | |
:deep_dup, | |
:duplicable?, | |
:in?, | |
:presence_in, | |
:instance_values, | |
:instance_variable_names, | |
:with_options, | |
:html_safe?, | |
:pry, | |
:__binding__, | |
:dclone, | |
:require_dependency, | |
:unloadable, | |
:require_or_load, | |
:load_dependency, | |
:__array__, | |
:__deep_copy__, | |
:__add__, | |
:__add_from_array__, | |
:__intersect__, | |
:__intersect_from_object__, | |
:__intersect_from_array__, | |
:__union__, | |
:__union_from_object__, | |
:__expand_complex__, | |
:regexp?, | |
:ivar, | |
:__evolve_object_id__, | |
:__find_args__, | |
:__mongoize_object_id__, | |
:__mongoize_time__, | |
:blank_criteria?, | |
:multi_arged?, | |
:resizable?, | |
:mongoize, | |
:__to_inc__, | |
:numeric?, | |
:__sortable__, | |
:__setter__, | |
:do_or_do_not, | |
:remove_ivar, | |
:substitutable, | |
:you_must, | |
:to_bson_key, | |
:to_bson_normalized_value, | |
:to_bson_normalized_key, | |
:pretty_print, | |
:pretty_print_cycle, | |
:pretty_print_instance_variables, | |
:pretty_print_inspect, | |
:to_ruby, | |
:to_v8, | |
:try, | |
:try!, | |
:tap, | |
:public_send, | |
:instance_variables, | |
:instance_variable_set, | |
:instance_variable_defined?, | |
:remove_instance_variable, | |
:kind_of?, | |
:is_a?, | |
:instance_variable_get, | |
:instance_of?, | |
:class_eval, | |
:public_method, | |
:extend, | |
:define_singleton_method, | |
:singleton_method, | |
:to_enum, | |
:enum_for, | |
:suppress_warnings, | |
:<=>, | |
:===, | |
:=~, | |
:!~, | |
:eql?, | |
:respond_to?, | |
:freeze, | |
:inspect, | |
:display, | |
:ai, | |
:object_id, | |
:send, | |
:to_s, | |
:gem, | |
:pretty_inspect, | |
:awesome_inspect, | |
:awesome_print, | |
:byebug, | |
:debugger, | |
:method, | |
:nil?, | |
:hash, | |
:class, | |
:singleton_class, | |
:clone, | |
:dup, | |
:itself, | |
:taint, | |
:tainted?, | |
:untaint, | |
:untrust, | |
:trust, | |
:untrusted?, | |
:frozen?, | |
:!, | |
:!=, | |
:__send__, | |
:equal?, | |
:instance_eval, | |
:instance_exec, | |
:__id__, | |
:fields, | |
:aliased_fields, | |
:localized_fields, | |
:index_specifications, | |
:shard_key_fields, | |
:nested_attributes, | |
:readonly_attributes, | |
:storage_options, | |
:cascades, | |
:cyclic, | |
:cache_timestamp_format | |
].map(&:to_s).freeze | |
Mongoid.models.each do |klass| | |
invalid_fields = klass.fields.keys & MONGOID_RESERVED_FIELDS | |
if invalid_fields.present? | |
puts "Class=#{klass}\tfields=#{invalid_fields}" | |
end | |
invalid_embedded_relations = klass.embedded_relations.keys & MONGOID_RESERVED_FIELDS | |
if invalid_embedded_relations.present? | |
puts "Class=#{klass}\tembedded_relations=#{invalid_embedded_relations}" | |
end | |
invalid_relations = klass.relations.keys & MONGOID_RESERVED_FIELDS | |
if invalid_relations.present? | |
puts "Class=#{klass}\trelations=#{invalid_relations}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment