Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion lib/mongoid/core_ext/relations/options.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
module Mongoid
module Relations
module Options
COMMON << :versioned
VERSIONED_OPTIONS = [:versioned].freeze

def validate!(options)
valid_options = options[:relation]::VALID_OPTIONS + COMMON + VERSIONED_OPTIONS
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like something like this here -> options[:relation]::VALID_OPTIONS + common_options(),
where

def self.common_options
    super + [:versioned]
end
# or maybe have DSL for extending common options dedicated for extnsions
Mongoid::Relations::Options.add_common_option(:versioned)

, but all that requires changes in mongoid itself....

Copy link

@ebeigarts ebeigarts Jul 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be less intrusive to use

alias_method :validate_without_versioned!, :validate!

def validate!(options)
  validate_without_versioned!(options - [:versioned])
end

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ebeigarts yes, looks definetly cleaner, only in case of invalid option exception message contains all valid options, but in this case versioned wont be included in exception message.

options.keys.each do |key|
if !valid_options.include?(key)
raise Errors::InvalidOptions.new(
options[:name],
key,
valid_options
)
end
end
true
end
end
end
end