railties 4.0.13 → 4.1.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (129) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +155 -385
  3. data/README.rdoc +1 -1
  4. data/bin/rails +1 -1
  5. data/lib/rails.rb +11 -13
  6. data/lib/rails/all.rb +1 -0
  7. data/lib/rails/api/task.rb +9 -12
  8. data/lib/rails/app_rails_loader.rb +2 -2
  9. data/lib/rails/application.rb +154 -149
  10. data/lib/rails/application/configuration.rb +1 -14
  11. data/lib/rails/application/default_middleware_stack.rb +99 -0
  12. data/lib/rails/application/finisher.rb +2 -0
  13. data/lib/rails/application_controller.rb +16 -0
  14. data/lib/rails/cli.rb +1 -2
  15. data/lib/rails/commands.rb +2 -94
  16. data/lib/rails/commands/application.rb +2 -28
  17. data/lib/rails/commands/commands_tasks.rb +174 -0
  18. data/lib/rails/commands/console.rb +2 -2
  19. data/lib/rails/commands/dbconsole.rb +1 -1
  20. data/lib/rails/commands/plugin.rb +23 -0
  21. data/lib/rails/commands/runner.rb +1 -1
  22. data/lib/rails/commands/server.rb +46 -30
  23. data/lib/rails/configuration.rb +4 -1
  24. data/lib/rails/console/helpers.rb +6 -0
  25. data/lib/rails/engine.rb +29 -18
  26. data/lib/rails/engine/commands.rb +1 -1
  27. data/lib/rails/engine/railties.rb +0 -8
  28. data/lib/rails/generators.rb +4 -3
  29. data/lib/rails/generators/actions.rb +1 -1
  30. data/lib/rails/generators/active_model.rb +0 -8
  31. data/lib/rails/generators/app_base.rb +213 -74
  32. data/lib/rails/generators/base.rb +17 -16
  33. data/lib/rails/generators/erb/scaffold/templates/_form.html.erb +1 -1
  34. data/lib/rails/generators/erb/scaffold/templates/index.html.erb +1 -3
  35. data/lib/rails/generators/migration.rb +18 -26
  36. data/lib/rails/generators/named_base.rb +4 -7
  37. data/lib/rails/generators/rails/app/app_generator.rb +91 -5
  38. data/lib/rails/generators/rails/app/templates/Gemfile +20 -15
  39. data/lib/rails/generators/rails/app/templates/Rakefile +1 -1
  40. data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +2 -0
  41. data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css +5 -3
  42. data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +5 -1
  43. data/lib/rails/generators/rails/app/templates/config/application.rb +2 -0
  44. data/lib/rails/generators/rails/app/templates/config/databases/frontbase.yml +7 -10
  45. data/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml +11 -31
  46. data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml +25 -29
  47. data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml +8 -10
  48. data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml +8 -11
  49. data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml +6 -3
  50. data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml +8 -22
  51. data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml +7 -9
  52. data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml +9 -12
  53. data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml +8 -8
  54. data/lib/rails/generators/rails/app/templates/config/databases/sqlserver.yml +7 -17
  55. data/lib/rails/generators/rails/app/templates/config/environment.rb +1 -1
  56. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +2 -5
  57. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +1 -1
  58. data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +1 -4
  59. data/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt +1 -1
  60. data/lib/rails/generators/rails/app/templates/config/routes.rb +1 -1
  61. data/lib/rails/generators/rails/app/templates/config/{initializers/secret_token.rb.tt → secrets.yml} +10 -2
  62. data/lib/rails/generators/rails/app/templates/public/404.html +20 -11
  63. data/lib/rails/generators/rails/app/templates/public/422.html +20 -11
  64. data/lib/rails/generators/rails/app/templates/public/500.html +19 -10
  65. data/lib/rails/generators/rails/controller/USAGE +1 -0
  66. data/lib/rails/generators/rails/controller/controller_generator.rb +35 -1
  67. data/lib/rails/generators/rails/generator/USAGE +1 -0
  68. data/lib/rails/generators/rails/generator/generator_generator.rb +2 -0
  69. data/lib/rails/generators/rails/model/USAGE +5 -5
  70. data/lib/rails/generators/rails/{plugin_new → plugin}/USAGE +0 -0
  71. data/lib/rails/generators/rails/{plugin_new/plugin_new_generator.rb → plugin/plugin_generator.rb} +10 -4
  72. data/lib/rails/generators/rails/{plugin_new → plugin}/templates/%name%.gemspec +1 -0
  73. data/lib/rails/generators/rails/{plugin_new → plugin}/templates/Gemfile +16 -1
  74. data/lib/rails/generators/rails/{plugin_new → plugin}/templates/MIT-LICENSE +0 -0
  75. data/lib/rails/generators/rails/{plugin_new → plugin}/templates/README.rdoc +0 -0
  76. data/lib/rails/generators/rails/{plugin_new → plugin}/templates/Rakefile +0 -0
  77. data/lib/rails/generators/rails/{plugin_new → plugin}/templates/app/controllers/%name%/application_controller.rb.tt +0 -0
  78. data/lib/rails/generators/rails/{plugin_new → plugin}/templates/app/helpers/%name%/application_helper.rb.tt +0 -0
  79. data/lib/rails/generators/rails/{plugin_new → plugin}/templates/app/mailers/.empty_directory +0 -0
  80. data/lib/rails/generators/rails/{plugin_new → plugin}/templates/app/models/.empty_directory +0 -0
  81. data/lib/rails/generators/rails/{plugin_new → plugin}/templates/app/views/layouts/%name%/application.html.erb.tt +0 -0
  82. data/lib/rails/generators/rails/{plugin_new → plugin}/templates/bin/rails.tt +0 -4
  83. data/lib/rails/generators/rails/{plugin_new → plugin}/templates/config/routes.rb +0 -0
  84. data/lib/rails/generators/rails/{plugin_new → plugin}/templates/gitignore +0 -0
  85. data/lib/rails/generators/rails/{plugin_new → plugin}/templates/lib/%name%.rb +0 -0
  86. data/lib/rails/generators/rails/{plugin_new → plugin}/templates/lib/%name%/engine.rb +0 -0
  87. data/lib/rails/generators/rails/{plugin_new → plugin}/templates/lib/%name%/version.rb +0 -0
  88. data/lib/rails/generators/rails/{plugin_new → plugin}/templates/lib/tasks/%name%_tasks.rake +0 -0
  89. data/lib/rails/generators/rails/{plugin_new → plugin}/templates/rails/application.rb +1 -0
  90. data/lib/rails/generators/rails/{plugin_new → plugin}/templates/rails/boot.rb +0 -0
  91. data/lib/rails/generators/rails/{plugin_new → plugin}/templates/rails/javascripts.js +0 -0
  92. data/lib/rails/generators/rails/{plugin_new → plugin}/templates/rails/routes.rb +0 -0
  93. data/lib/rails/generators/rails/{plugin_new → plugin}/templates/rails/stylesheets.css +5 -3
  94. data/lib/rails/generators/rails/{plugin_new → plugin}/templates/test/%name%_test.rb +0 -0
  95. data/lib/rails/generators/rails/{plugin_new → plugin}/templates/test/integration/navigation_test.rb +0 -0
  96. data/lib/rails/generators/rails/{plugin_new → plugin}/templates/test/test_helper.rb +0 -0
  97. data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +1 -1
  98. data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb +2 -2
  99. data/lib/rails/generators/resource_helpers.rb +20 -5
  100. data/lib/rails/generators/test_unit/generator/generator_generator.rb +26 -0
  101. data/lib/rails/generators/test_unit/generator/templates/generator_test.rb +16 -0
  102. data/lib/rails/generators/test_unit/mailer/mailer_generator.rb +8 -1
  103. data/lib/rails/generators/test_unit/mailer/templates/preview.rb +11 -0
  104. data/lib/rails/generators/testing/assertions.rb +1 -1
  105. data/lib/rails/generators/testing/behaviour.rb +3 -13
  106. data/lib/rails/info.rb +5 -3
  107. data/lib/rails/info_controller.rb +5 -15
  108. data/lib/rails/mailers_controller.rb +73 -0
  109. data/lib/rails/paths.rb +13 -18
  110. data/lib/rails/rack/debugger.rb +2 -2
  111. data/lib/rails/rack/logger.rb +1 -1
  112. data/lib/rails/railtie.rb +38 -2
  113. data/lib/rails/source_annotation_extractor.rb +2 -2
  114. data/lib/rails/tasks.rb +0 -2
  115. data/lib/rails/tasks/documentation.rake +0 -5
  116. data/lib/rails/tasks/engine.rake +1 -1
  117. data/lib/rails/tasks/framework.rake +2 -12
  118. data/lib/rails/templates/layouts/application.html.erb +2 -2
  119. data/lib/rails/templates/rails/mailers/email.html.erb +98 -0
  120. data/lib/rails/templates/rails/mailers/index.html.erb +8 -0
  121. data/lib/rails/templates/rails/mailers/mailer.html.erb +6 -0
  122. data/lib/rails/test_help.rb +4 -1
  123. data/lib/rails/test_unit/sub_test_task.rb +44 -3
  124. data/lib/rails/test_unit/testing.rake +9 -111
  125. data/lib/rails/version.rb +3 -3
  126. data/lib/rails/welcome_controller.rb +4 -3
  127. metadata +99 -76
  128. data/lib/rails/commands/plugin_new.rb +0 -9
  129. data/lib/rails/generators/actions/create_migration.rb +0 -68
@@ -3,9 +3,5 @@
3
3
  ENGINE_ROOT = File.expand_path('../..', __FILE__)
4
4
  ENGINE_PATH = File.expand_path('../../lib/<%= name -%>/engine', __FILE__)
5
5
 
6
- # Set up gems listed in the Gemfile.
7
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
8
- require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
9
-
10
6
  require 'rails/all'
11
7
  require 'rails/engine/commands'
@@ -7,6 +7,7 @@ require 'rails/all'
7
7
  <%= comment_if :skip_active_record %>require "active_record/railtie"
8
8
  require "action_controller/railtie"
9
9
  require "action_mailer/railtie"
10
+ <%= comment_if :skip_action_view %>require "action_view/railtie"
10
11
  <%= comment_if :skip_sprockets %>require "sprockets/railtie"
11
12
  <%= comment_if :skip_test_unit %>require "rails/test_unit/railtie"
12
13
  <% end -%>
@@ -5,9 +5,11 @@
5
5
  * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
6
  * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
7
  *
8
- * You're free to add application-wide styles to this file and they'll appear at the top of the
9
- * compiled file, but it's generally better to create a new file per style scope.
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
10
12
  *
11
- *= require_self
12
13
  *= require_tree .
14
+ *= require_self
13
15
  */
@@ -13,7 +13,7 @@ module Rails
13
13
  argument :attributes, type: :array, default: [], banner: "field:type field:type"
14
14
 
15
15
  def create_controller_files
16
- template "controller.rb", File.join('app/controllers', class_path, "#{controller_file_name}_controller.rb")
16
+ template "controller.rb", File.join('app/controllers', controller_class_path, "#{controller_file_name}_controller.rb")
17
17
  end
18
18
 
19
19
  hook_for :template_engine, :test_framework, as: :scaffold
@@ -59,9 +59,9 @@ class <%= controller_class_name %>Controller < ApplicationController
59
59
  # Only allow a trusted parameter "white list" through.
60
60
  def <%= "#{singular_table_name}_params" %>
61
61
  <%- if attributes_names.empty? -%>
62
- params[<%= ":#{singular_table_name}" %>]
62
+ params[:<%= singular_table_name %>]
63
63
  <%- else -%>
64
- params.require(<%= ":#{singular_table_name}" %>).permit(<%= attributes_names.map { |name| ":#{name}" }.join(', ') %>)
64
+ params.require(:<%= singular_table_name %>).permit(<%= attributes_names.map { |name| ":#{name}" }.join(', ') %>)
65
65
  <%- end -%>
66
66
  end
67
67
  end
@@ -9,11 +9,19 @@ module Rails
9
9
 
10
10
  def self.included(base) #:nodoc:
11
11
  base.class_option :force_plural, type: :boolean, desc: "Forces the use of a plural ModelName"
12
+ base.class_option :model_name, type: :string, desc: "ModelName to be used"
12
13
  end
13
14
 
14
15
  # Set controller variables on initialization.
15
16
  def initialize(*args) #:nodoc:
16
17
  super
18
+ if options[:model_name]
19
+ controller_name = name
20
+ self.name = options[:model_name]
21
+ assign_names!(self.name)
22
+ else
23
+ controller_name = name
24
+ end
17
25
 
18
26
  if name == name.pluralize && name.singularize != name.pluralize && !options[:force_plural]
19
27
  unless ResourceHelpers.skip_warn
@@ -24,19 +32,26 @@ module Rails
24
32
  assign_names!(name)
25
33
  end
26
34
 
27
- @controller_name = name.pluralize
35
+ assign_controller_names!(controller_name.pluralize)
28
36
  end
29
37
 
30
38
  protected
31
39
 
32
- attr_reader :controller_name
40
+ attr_reader :controller_name, :controller_file_name
33
41
 
34
42
  def controller_class_path
35
- class_path
43
+ if options[:model_name]
44
+ @controller_class_path
45
+ else
46
+ class_path
47
+ end
36
48
  end
37
49
 
38
- def controller_file_name
39
- @controller_file_name ||= file_name.pluralize
50
+ def assign_controller_names!(name)
51
+ @controller_name = name
52
+ @controller_class_path = name.include?('/') ? name.split('/') : name.split('::')
53
+ @controller_class_path.map! { |m| m.underscore }
54
+ @controller_file_name = @controller_class_path.pop
40
55
  end
41
56
 
42
57
  def controller_file_path
@@ -0,0 +1,26 @@
1
+ require 'rails/generators/test_unit'
2
+
3
+ module TestUnit # :nodoc:
4
+ module Generators # :nodoc:
5
+ class GeneratorGenerator < Base # :nodoc:
6
+ check_class_collision suffix: "GeneratorTest"
7
+
8
+ class_option :namespace, type: :boolean, default: true,
9
+ desc: "Namespace generator under lib/generators/name"
10
+
11
+ def create_generator_files
12
+ template 'generator_test.rb', File.join('test/lib/generators', class_path, "#{file_name}_generator_test.rb")
13
+ end
14
+
15
+ protected
16
+
17
+ def generator_path
18
+ if options[:namespace]
19
+ File.join("generators", regular_class_path, file_name, "#{file_name}_generator")
20
+ else
21
+ File.join("generators", regular_class_path, "#{file_name}_generator")
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,16 @@
1
+ require 'test_helper'
2
+ require '<%= generator_path %>'
3
+
4
+ <% module_namespacing do -%>
5
+ class <%= class_name %>GeneratorTest < Rails::Generators::TestCase
6
+ tests <%= class_name %>Generator
7
+ destination Rails.root.join('tmp/generators')
8
+ setup :prepare_destination
9
+
10
+ # test "generator runs without errors" do
11
+ # assert_nothing_raised do
12
+ # run_generator ["arguments"]
13
+ # end
14
+ # end
15
+ end
16
+ <% end -%>
@@ -4,11 +4,18 @@ module TestUnit # :nodoc:
4
4
  module Generators # :nodoc:
5
5
  class MailerGenerator < Base # :nodoc:
6
6
  argument :actions, type: :array, default: [], banner: "method method"
7
- check_class_collision suffix: "Test"
7
+
8
+ def check_class_collision
9
+ class_collisions "#{class_name}Test", "#{class_name}Preview"
10
+ end
8
11
 
9
12
  def create_test_files
10
13
  template "functional_test.rb", File.join('test/mailers', class_path, "#{file_name}_test.rb")
11
14
  end
15
+
16
+ def create_preview_files
17
+ template "preview.rb", File.join('test/mailers/previews', class_path, "#{file_name}_preview.rb")
18
+ end
12
19
  end
13
20
  end
14
21
  end
@@ -0,0 +1,11 @@
1
+ <% module_namespacing do -%>
2
+ class <%= class_name %>Preview < ActionMailer::Preview
3
+ <% actions.each do |action| -%>
4
+
5
+ def <%= action %>
6
+ <%= class_name %>.<%= action %>
7
+ end
8
+ <% end -%>
9
+
10
+ end
11
+ <% end -%>
@@ -21,7 +21,7 @@ module Rails
21
21
  # end
22
22
  # end
23
23
  def assert_file(relative, *contents)
24
- absolute = File.expand_path(relative, destination_root)
24
+ absolute = File.expand_path(relative, destination_root).shellescape
25
25
  assert File.exist?(absolute), "Expected file #{relative.inspect} to exist, but does not"
26
26
 
27
27
  read = File.read(absolute) if block_given? || !contents.empty?
@@ -61,11 +61,9 @@ module Rails
61
61
  # You can provide a configuration hash as second argument. This method returns the output
62
62
  # printed by the generator.
63
63
  def run_generator(args=self.default_arguments, config={})
64
- without_thor_debug do
65
- capture(:stdout) do
66
- args += ['--skip-bundle'] unless args.include? '--dev'
67
- self.generator_class.start(args, config.reverse_merge(destination_root: destination_root))
68
- end
64
+ capture(:stdout) do
65
+ args += ['--skip-bundle'] unless args.include? '--dev'
66
+ self.generator_class.start(args, config.reverse_merge(destination_root: destination_root))
69
67
  end
70
68
  end
71
69
 
@@ -102,14 +100,6 @@ module Rails
102
100
  dirname, file_name = File.dirname(absolute), File.basename(absolute).sub(/\.rb$/, '')
103
101
  Dir.glob("#{dirname}/[0-9]*_*.rb").grep(/\d+_#{file_name}.rb$/).first
104
102
  end
105
-
106
- # TODO: remove this once Bundler 1.5.2 is released
107
- def without_thor_debug # :nodoc:
108
- thor_debug, ENV['THOR_DEBUG'] = ENV['THOR_DEBUG'], nil
109
- yield
110
- ensure
111
- ENV['THOR_DEBUG'] = thor_debug
112
- end
113
103
  end
114
104
  end
115
105
  end
@@ -23,7 +23,7 @@ module Rails
23
23
  end
24
24
 
25
25
  def frameworks
26
- %w( active_record action_pack action_mailer active_support )
26
+ %w( active_record action_pack action_view action_mailer active_support )
27
27
  end
28
28
 
29
29
  def framework_version(framework)
@@ -61,8 +61,10 @@ module Rails
61
61
  end
62
62
  end
63
63
 
64
- # The Ruby version and platform, e.g. "1.8.2 (powerpc-darwin8.2.0)".
65
- property 'Ruby version', "#{RUBY_VERSION} (#{RUBY_PLATFORM})"
64
+ # The Ruby version and platform, e.g. "2.0.0-p247 (x86_64-darwin12.4.0)".
65
+ property 'Ruby version' do
66
+ "#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL} (#{RUBY_PLATFORM})"
67
+ end
66
68
 
67
69
  # The RubyGems version, if it's installed.
68
70
  property 'RubyGems version' do
@@ -1,9 +1,9 @@
1
+ require 'rails/application_controller'
1
2
  require 'action_dispatch/routing/inspector'
2
3
 
3
- class Rails::InfoController < ActionController::Base # :nodoc:
4
- self.view_paths = File.expand_path('../templates', __FILE__)
4
+ class Rails::InfoController < Rails::ApplicationController # :nodoc:
5
5
  prepend_view_path ActionDispatch::DebugExceptions::RESCUES_TEMPLATE_PATH
6
- layout -> { request.xhr? ? nil : 'application' }
6
+ layout -> { request.xhr? ? false : 'application' }
7
7
 
8
8
  before_filter :require_local!
9
9
 
@@ -13,21 +13,11 @@ class Rails::InfoController < ActionController::Base # :nodoc:
13
13
 
14
14
  def properties
15
15
  @info = Rails::Info.to_html
16
+ @page_title = 'Properties'
16
17
  end
17
18
 
18
19
  def routes
19
20
  @routes_inspector = ActionDispatch::Routing::RoutesInspector.new(_routes.routes)
20
- end
21
-
22
- protected
23
-
24
- def require_local!
25
- unless local_request?
26
- render text: '<p>For security purposes, this information is only available to local requests.</p>', status: :forbidden
27
- end
28
- end
29
-
30
- def local_request?
31
- Rails.application.config.consider_all_requests_local || request.local?
21
+ @page_title = 'Routes'
32
22
  end
33
23
  end
@@ -0,0 +1,73 @@
1
+ require 'rails/application_controller'
2
+
3
+ class Rails::MailersController < Rails::ApplicationController # :nodoc:
4
+ prepend_view_path ActionDispatch::DebugExceptions::RESCUES_TEMPLATE_PATH
5
+
6
+ before_filter :require_local!
7
+ before_filter :find_preview, only: :preview
8
+
9
+ def index
10
+ @previews = ActionMailer::Preview.all
11
+ @page_title = "Mailer Previews"
12
+ end
13
+
14
+ def preview
15
+ if params[:path] == @preview.preview_name
16
+ @page_title = "Mailer Previews for #{@preview.preview_name}"
17
+ render action: 'mailer'
18
+ else
19
+ email = File.basename(params[:path])
20
+
21
+ if @preview.email_exists?(email)
22
+ @email = @preview.call(email)
23
+
24
+ if params[:part]
25
+ part_type = Mime::Type.lookup(params[:part])
26
+
27
+ if part = find_part(part_type)
28
+ response.content_type = part_type
29
+ render text: part.respond_to?(:decoded) ? part.decoded : part
30
+ else
31
+ raise AbstractController::ActionNotFound, "Email part '#{part_type}' not found in #{@preview.name}##{email}"
32
+ end
33
+ else
34
+ @part = find_preferred_part(request.format, Mime::HTML, Mime::TEXT)
35
+ render action: 'email', layout: false, formats: %w[html]
36
+ end
37
+ else
38
+ raise AbstractController::ActionNotFound, "Email '#{email}' not found in #{@preview.name}"
39
+ end
40
+ end
41
+ end
42
+
43
+ protected
44
+ def find_preview
45
+ candidates = []
46
+ params[:path].to_s.scan(%r{/|$}){ candidates << $` }
47
+ preview = candidates.detect{ |candidate| ActionMailer::Preview.exists?(candidate) }
48
+
49
+ if preview
50
+ @preview = ActionMailer::Preview.find(preview)
51
+ else
52
+ raise AbstractController::ActionNotFound, "Mailer preview '#{params[:path]}' not found"
53
+ end
54
+ end
55
+
56
+ def find_preferred_part(*formats)
57
+ if @email.multipart?
58
+ formats.each do |format|
59
+ return find_part(format) if @email.parts.any?{ |p| p.mime_type == format }
60
+ end
61
+ else
62
+ @email
63
+ end
64
+ end
65
+
66
+ def find_part(format)
67
+ if @email.multipart?
68
+ @email.parts.find{ |p| p.mime_type == format }
69
+ elsif @email.mime_type == format
70
+ @email
71
+ end
72
+ end
73
+ end
@@ -81,34 +81,28 @@ module Rails
81
81
  end
82
82
 
83
83
  def autoload_once
84
- filter_by(:autoload_once?)
84
+ filter_by { |p| p.autoload_once? }
85
85
  end
86
86
 
87
87
  def eager_load
88
- filter_by(:eager_load?)
88
+ filter_by { |p| p.eager_load? }
89
89
  end
90
90
 
91
91
  def autoload_paths
92
- filter_by(:autoload?)
92
+ filter_by { |p| p.autoload? }
93
93
  end
94
94
 
95
95
  def load_paths
96
- filter_by(:load_path?)
96
+ filter_by { |p| p.load_path? }
97
97
  end
98
98
 
99
- protected
99
+ private
100
100
 
101
- def filter_by(constraint)
102
- all = []
103
- all_paths.each do |path|
104
- if path.send(constraint)
105
- paths = path.existent
106
- paths -= path.children.map { |p| p.send(constraint) ? [] : p.existent }.flatten
107
- all.concat(paths)
108
- end
109
- end
110
- all.uniq!
111
- all
101
+ def filter_by(&block)
102
+ all_paths.find_all(&block).flat_map { |path|
103
+ paths = path.existent
104
+ paths - path.children.map { |p| yield(p) ? [] : p.existent }.flatten
105
+ }.uniq
112
106
  end
113
107
  end
114
108
 
@@ -130,8 +124,9 @@ module Rails
130
124
  end
131
125
 
132
126
  def children
133
- keys = @root.keys.select { |k| k.include?(@current) }
134
- keys.delete(@current)
127
+ keys = @root.keys.find_all { |k|
128
+ k.start_with?(@current) && k != @current
129
+ }
135
130
  @root.values_at(*keys.sort)
136
131
  end
137
132