Skip to content

Fix minor Ruby warnings #461

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

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
4 changes: 4 additions & 0 deletions lib/enumerize/attribute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def respond_to_missing?(method, include_private=false)

def define_methods!(mod)
mod.module_eval <<-RUBY, __FILE__, __LINE__ + 1
alias_method "#{name}", "#{name}" if method_defined?("#{name}")
def #{name}
if defined?(super)
self.class.enumerized_attributes[:#{name}].find_value(super)
Expand All @@ -104,6 +105,7 @@ def #{name}
end
end

alias_method "#{name}=", "#{name}=" if method_defined?("#{name}=")
def #{name}=(new_value)
allowed_value_or_nil = self.class.enumerized_attributes[:#{name}].find_value(new_value)
allowed_value_or_nil = allowed_value_or_nil.value unless allowed_value_or_nil.nil?
Expand All @@ -121,10 +123,12 @@ def #{name}=(new_value)
allowed_value_or_nil
end

alias_method "#{name}_text", "#{name}_text" if method_defined?("#{name}_text")
def #{name}_text
self.#{name} && self.#{name}.text
end

alias_method "#{name}_value", "#{name}_value" if method_defined?("#{name}_value")
def #{name}_value
self.#{name} && self.#{name}.value
end
Expand Down