Skip to content

Commit

Permalink
refactor: fix typo & use private :symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
hatsu38 committed Aug 28, 2024
1 parent 099a1f1 commit 9e2fc62
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/enum/enum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@ def delete_all
super
end

private

def define_enum_methods
return if @enum_accessors.blank?

@records&.each do |record|
enum_vallue = @enum_accessors.map { |name| record.attributes[name] }.join("_").downcase.gsub(/\W+/, '_').gsub(/^_|_$/, '')
method_name = "#{enum_vallue}?"
enum_value = @enum_accessors.map { |name| record.attributes[name] }.join("_").downcase.gsub(/\W+/, '_').gsub(/^_|_$/, '')
method_name = "#{enum_value}?"
define_method(method_name) do
self.id == record.id
end
end
end

private :define_enum_methods

def set_constant(record)
constant = constant_for(record, @enum_accessors)
return nil if constant.blank?
Expand All @@ -53,6 +53,8 @@ def set_constant(record)
end
end

private :set_constant

def constant_for(record, field_names)
field_value = field_names.map { |name| record.attributes[name] }.join("_")
if constant = !field_value.nil? && field_value.dup
Expand All @@ -62,6 +64,8 @@ def constant_for(record, field_names)
constant
end
end

private :constant_for
end
end
end

0 comments on commit 9e2fc62

Please sign in to comment.