From 010a0c92eb573cd4c216c51371356adddfde11cf Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Fri, 7 Aug 2009 15:00:12 -0300 Subject: [PATCH] Rename find_by_parts and find_by_parts? to find and exists? --- actionmailer/lib/action_mailer/base.rb | 4 ++-- actionpack/lib/abstract_controller/layouts.rb | 4 ++-- .../lib/abstract_controller/rendering_controller.rb | 2 +- actionpack/lib/action_controller/base.rb | 2 +- actionpack/lib/action_controller/legacy/layout.rb | 2 +- actionpack/lib/action_view/base.rb | 2 +- actionpack/lib/action_view/paths.rb | 10 +++++----- actionpack/lib/action_view/render/partials.rb | 2 +- actionpack/lib/action_view/render/rendering.rb | 4 ++-- actionpack/lib/action_view/template/resolver.rb | 2 +- .../abstract_controller/abstract_controller_test.rb | 4 ++-- actionpack/test/abstract_controller/helper_test.rb | 2 +- 12 files changed, 20 insertions(+), 20 deletions(-) diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 7b03a7f9ff..e36ee72298 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -499,7 +499,7 @@ def create!(method_name, *parameters) #:nodoc: # ==== # TODO: Revisit this # template_exists = @parts.empty? - # template_exists ||= template_root.find_by_parts("#{mailer_name}/#{@template}") + # template_exists ||= template_root.find("#{mailer_name}/#{@template}") # @body = render_message(@template, @body) if template_exists # Finally, if there are other message parts and a textual body exists, @@ -585,7 +585,7 @@ def render(opts) if file prefix = mailer_name unless file =~ /\// - template = view_paths.find_by_parts(file, {:formats => formats}, prefix) + template = view_paths.find(file, {:formats => formats}, prefix) end layout = _pick_layout(layout, diff --git a/actionpack/lib/abstract_controller/layouts.rb b/actionpack/lib/abstract_controller/layouts.rb index 0cb3d166f7..c1fb80415b 100644 --- a/actionpack/lib/abstract_controller/layouts.rb +++ b/actionpack/lib/abstract_controller/layouts.rb @@ -76,7 +76,7 @@ def _layout(details) when nil self.class_eval <<-ruby_eval, __FILE__, __LINE__ + 1 def _layout(details) - if view_paths.find_by_parts?("#{_implied_layout_name}", details, "layouts") + if view_paths.exists?("#{_implied_layout_name}", details, "layouts") "#{_implied_layout_name}" else super @@ -131,7 +131,7 @@ def _layout_for_name(name, details = {:formats => formats}) def _find_layout(name, details) # TODO: Make prefix actually part of details in ViewPath#find_by_parts prefix = details.key?(:prefix) ? details.delete(:prefix) : "layouts" - view_paths.find_by_parts(name, details, prefix) + view_paths.find(name, details, prefix) end # Returns the default layout for this controller and a given set of details. diff --git a/actionpack/lib/abstract_controller/rendering_controller.rb b/actionpack/lib/abstract_controller/rendering_controller.rb index 23cd71e0bd..bb7891fbfd 100644 --- a/actionpack/lib/abstract_controller/rendering_controller.rb +++ b/actionpack/lib/abstract_controller/rendering_controller.rb @@ -111,7 +111,7 @@ def self.body_to_s(body) def _determine_template(options) name = (options[:_template_name] || action_name).to_s - options[:_template] ||= view_paths.find_by_parts( + options[:_template] ||= view_paths.find( name, { :formats => formats }, options[:_prefix], options[:_partial] ) end diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index 40f4802b74..61f1c715c8 100644 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -51,7 +51,7 @@ def default_render def method_for_action(action_name) super || begin - if view_paths.find_by_parts?(action_name.to_s, {:formats => formats, :locales => [I18n.locale]}, controller_path) + if view_paths.exists?(action_name.to_s, {:formats => formats, :locales => [I18n.locale]}, controller_path) "default_render" end end diff --git a/actionpack/lib/action_controller/legacy/layout.rb b/actionpack/lib/action_controller/legacy/layout.rb index 3f3d20b95f..43aea0eba2 100644 --- a/actionpack/lib/action_controller/legacy/layout.rb +++ b/actionpack/lib/action_controller/legacy/layout.rb @@ -191,7 +191,7 @@ def default_layout(*args) def memoized_find_layout(layout, formats) #:nodoc: return layout if layout.nil? || layout.respond_to?(:render) prefix = layout.to_s =~ /layouts\// ? nil : "layouts" - view_paths.find_by_parts(layout.to_s, {:formats => formats}, prefix) + view_paths.find(layout.to_s, {:formats => formats}, prefix) end def find_layout(*args) diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb index 9e696af83b..7932f01ebb 100644 --- a/actionpack/lib/action_view/base.rb +++ b/actionpack/lib/action_view/base.rb @@ -202,7 +202,7 @@ def self.cache_template_loading? delegate :logger, :to => :controller, :allow_nil => true - delegate :find_by_parts, :to => :view_paths + delegate :find, :to => :view_paths include Context diff --git a/actionpack/lib/action_view/paths.rb b/actionpack/lib/action_view/paths.rb index 074b475819..4001757a9b 100644 --- a/actionpack/lib/action_view/paths.rb +++ b/actionpack/lib/action_view/paths.rb @@ -33,12 +33,12 @@ def unshift(*objs) super(*objs.map { |obj| self.class.type_cast(obj) }) end - def find_by_parts(path, details = {}, prefix = nil, partial = false) + def find(path, details = {}, prefix = nil, partial = false) # template_path = path.sub(/^\//, '') template_path = path each do |load_path| - if template = load_path.find_by_parts(template_path, details, prefix, partial) + if template = load_path.find(template_path, details, prefix, partial) return template end end @@ -48,11 +48,11 @@ def find_by_parts(path, details = {}, prefix = nil, partial = false) raise ActionView::MissingTemplate.new(self, "#{prefix}/#{path} - #{details.inspect} - partial: #{!!partial}") end - def find_by_parts?(path, extension = nil, prefix = nil, partial = false) + def exists?(path, extension = nil, prefix = nil, partial = false) template_path = path.sub(/^\//, '') each do |load_path| - return true if template = load_path.find_by_parts(template_path, extension, prefix, partial) + return true if template = load_path.find(template_path, extension, prefix, partial) end false end @@ -62,7 +62,7 @@ def find_template(original_template_path, format = nil, html_fallback = true) template_path = original_template_path.sub(/^\//, '') each do |load_path| - if template = load_path.find_by_parts(template_path, format) + if template = load_path.find(template_path, format) return template # Try to find html version if the format is javascript elsif format == :js && html_fallback && template = load_path["#{template_path}.#{I18n.locale}.html"] diff --git a/actionpack/lib/action_view/render/partials.rb b/actionpack/lib/action_view/render/partials.rb index 48cba9c02b..c559a572b0 100644 --- a/actionpack/lib/action_view/render/partials.rb +++ b/actionpack/lib/action_view/render/partials.rb @@ -258,7 +258,7 @@ def _render_partial_collection(collection, options = {}, template = nil, &block) def _pick_partial_template(partial_path) #:nodoc: prefix = controller_path unless partial_path.include?(?/) - find_by_parts(partial_path, {:formats => formats}, prefix, true) + find(partial_path, {:formats => formats}, prefix, true) end end end diff --git a/actionpack/lib/action_view/render/rendering.rb b/actionpack/lib/action_view/render/rendering.rb index 9c25fab6bb..742b965556 100644 --- a/actionpack/lib/action_view/render/rendering.rb +++ b/actionpack/lib/action_view/render/rendering.rb @@ -24,10 +24,10 @@ def render(options = {}, locals = {}, &block) #:nodoc: return _render_content(_render_partial(options), layout, options[:locals]) end - layout = find_by_parts(layout, {:formats => formats}) if layout + layout = find(layout, {:formats => formats}) if layout if file = options[:file] - template = find_by_parts(file, {:formats => formats}) + template = find(file, {:formats => formats}) _render_template(template, layout, :locals => options[:locals] || {}) elsif inline = options[:inline] _render_inline(inline, layout, options) diff --git a/actionpack/lib/action_view/template/resolver.rb b/actionpack/lib/action_view/template/resolver.rb index d15f53a11b..ebfc6cc8ce 100644 --- a/actionpack/lib/action_view/template/resolver.rb +++ b/actionpack/lib/action_view/template/resolver.rb @@ -10,7 +10,7 @@ def initialize(options) end # Normalizes the arguments and passes it on to find_template - def find_by_parts(*args) + def find(*args) find_all_by_parts(*args).first end diff --git a/actionpack/test/abstract_controller/abstract_controller_test.rb b/actionpack/test/abstract_controller/abstract_controller_test.rb index 10b97f4eb4..9438a4dfc9 100644 --- a/actionpack/test/abstract_controller/abstract_controller_test.rb +++ b/actionpack/test/abstract_controller/abstract_controller_test.rb @@ -139,10 +139,10 @@ class WithLayouts < PrefixedViews private def self.layout(formats) begin - view_paths.find_by_parts(name.underscore, {:formats => formats}, "layouts") + view_paths.find(name.underscore, {:formats => formats}, "layouts") rescue ActionView::MissingTemplate begin - view_paths.find_by_parts("application", {:formats => formats}, "layouts") + view_paths.find("application", {:formats => formats}, "layouts") rescue ActionView::MissingTemplate end end diff --git a/actionpack/test/abstract_controller/helper_test.rb b/actionpack/test/abstract_controller/helper_test.rb index cd6d4ee90e..e9a60c0307 100644 --- a/actionpack/test/abstract_controller/helper_test.rb +++ b/actionpack/test/abstract_controller/helper_test.rb @@ -4,7 +4,7 @@ module AbstractController module Testing class ControllerWithHelpers < AbstractController::Base - include RenderingController + include AbstractController::RenderingController include Helpers def render(string) -- GitLab