Module: Brick::RouteSet

Defined in:
lib/brick.rb

Instance Method Summary collapse

Instance Method Details

#finalize!Object



336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
# File 'lib/brick.rb', line 336

def finalize!
  existing_controllers = routes.each_with_object({}) { |r, s| c = r.defaults[:controller]; s[c] = nil if c }
  ::Rails.application.routes.append do
    # %%% TODO: If no auto-controllers then enumerate the controllers folder in order to build matching routes
    # If auto-controllers and auto-models are both enabled then this makes sense:
    ::Brick.relations.each do |k, v|
      unless existing_controllers.key?(controller_name = k.underscore.pluralize)
        options = {}
        options[:only] = [:index, :show] if v.key?(:isView)
        send(:resources, controller_name.to_sym, **options)
      end
    end
  end
  super
end