Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Follow AR options naming style #94

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
21 changes: 14 additions & 7 deletions lib/default_value_for.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,22 @@ module ClassMethods
#
# The <tt>options</tt> can be used to specify the following things:
# * <tt>value</tt> - Sets the default value.
# * <tt>allows_nil (default: true)</tt> - Sets explicitly passed nil values if option is set to true.
# * <tt>allow_nil (default: true)</tt> - Sets explicitly passed nil values if option is set to true.
def default_value_for(attribute, options = {}, &block)
value = options
allows_nil = true
value = options
allow_nil = true

if options.is_a?(Hash)
opts = options.stringify_keys
value = opts.fetch('value', options)
allows_nil = opts.fetch('allows_nil', true)
opts = options.stringify_keys
value = opts.fetch('value', options)
allow_nil = opts.fetch('allow_nil') do
if opts.key?('allows_nil')
# TODO: Add deprecation warning?
opts['allows_nil']
else
true
end
end
end

if !method_defined?(:set_default_values)
Expand Down Expand Up @@ -90,7 +97,7 @@ def default_value_for(attribute, options = {}, &block)
container = NormalValueContainer.new(value)
end
_default_attribute_values[attribute.to_s] = container
_default_attribute_values_not_allowing_nil << attribute.to_s unless allows_nil
_default_attribute_values_not_allowing_nil << attribute.to_s unless allow_nil
end

def default_values(values)
Expand Down