Skip to content

Commit

Permalink
organize code
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-Bob committed Sep 3, 2024
1 parent 4c784dd commit 294a3ea
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 12 additions & 0 deletions lib/avo/concerns/model_class_constantized.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ module ModelClassConstantized
def model_class=(value)
@model_class = value
end

# Cast the model class to a constantized version
def constantized_model_class
@constantized_model_class ||= case @model_class
when Class
@model_class
when String, Symbol
@model_class.to_s.safe_constantize
else
raise ArgumentError.new "Failed to find a proper model class for #{self}"
end
end
end
end
end
Expand Down
12 changes: 0 additions & 12 deletions lib/avo/resources/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,18 +152,6 @@ def model_class(record_class: nil)
class_name.safe_constantize
end

# Cast the model class to a constantized version
def constantized_model_class
@constantized_model_class ||= case @model_class
when Class
@model_class
when String, Symbol
@model_class.to_s.safe_constantize
else
raise ArgumentError.new "Failed to find a proper model class for #{self}"
end
end

# This is used as the model class ID
# We use this instead of the route_key to maintain compatibility with uncountable models
# With uncountable models route key appends an _index suffix (Fish->fish_index)
Expand Down

0 comments on commit 294a3ea

Please sign in to comment.