Skip to content

Commit

Permalink
Issue #81. Upgrade helper method
Browse files Browse the repository at this point in the history
  • Loading branch information
kalashnikovisme committed Sep 13, 2024
1 parent 85d4a7e commit 7be3cf7
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions lib/tramway/configs/entity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Entity < Dry::Struct
HumanNameStruct = Struct.new(:single, :plural)

def routes
RouteStruct.new(Rails.application.routes.url_helpers.public_send(route_helper_method))
RouteStruct.new(route_helper_method)
end

def human_name
Expand All @@ -34,19 +34,25 @@ def human_name
private

def model_class
name.camelize.constantize
name.classify.constantize
rescue StandardError
nil
end

def route_helper_method
underscored_name = name.parameterize.pluralize.underscore

if route.present?
route.helper_method_by(underscored_name)
else
"#{underscored_name}_path"
end
engine, method_name = if pages.include?(:index)
[Tramway::Engine, "#{underscored_name}_path"]
else
if route.present?
[Rails.application, route.helper_method_by(underscored_name)]
else
[Rails.application, "#{underscored_name}_path"]
end
end

engine.routes.url_helpers.public_send(method_name)
end
end
end
Expand Down

0 comments on commit 7be3cf7

Please sign in to comment.