merb-core 0.9.3 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (178) hide show
  1. data/LICENSE +1 -1
  2. data/README +3 -3
  3. data/Rakefile +144 -33
  4. data/bin/merb +0 -0
  5. data/bin/merb-specs +0 -0
  6. data/docs/bootloading.dox +1 -0
  7. data/docs/merb-core-call-stack-diagram.mmap +0 -0
  8. data/docs/merb-core-call-stack-diagram.pdf +0 -0
  9. data/docs/merb-core-call-stack-diagram.png +0 -0
  10. data/lib/merb-core.rb +159 -37
  11. data/lib/merb-core/autoload.rb +1 -0
  12. data/lib/merb-core/bootloader.rb +208 -92
  13. data/lib/merb-core/config.rb +20 -6
  14. data/lib/merb-core/controller/abstract_controller.rb +113 -61
  15. data/lib/merb-core/controller/exceptions.rb +28 -13
  16. data/lib/merb-core/controller/merb_controller.rb +73 -44
  17. data/lib/merb-core/controller/mime.rb +25 -7
  18. data/lib/merb-core/controller/mixins/authentication.rb +1 -1
  19. data/lib/merb-core/controller/mixins/controller.rb +44 -8
  20. data/lib/merb-core/controller/mixins/render.rb +191 -128
  21. data/lib/merb-core/controller/mixins/responder.rb +65 -63
  22. data/lib/merb-core/controller/template.rb +103 -54
  23. data/lib/merb-core/core_ext.rb +7 -12
  24. data/lib/merb-core/core_ext/kernel.rb +128 -136
  25. data/lib/merb-core/dispatch/cookies.rb +26 -4
  26. data/lib/merb-core/dispatch/default_exception/default_exception.rb +93 -0
  27. data/lib/merb-core/dispatch/default_exception/views/_css.html.erb +198 -0
  28. data/lib/merb-core/dispatch/default_exception/views/_javascript.html.erb +73 -0
  29. data/lib/merb-core/dispatch/default_exception/views/index.html.erb +92 -0
  30. data/lib/merb-core/dispatch/dispatcher.rb +156 -224
  31. data/lib/merb-core/dispatch/request.rb +126 -25
  32. data/lib/merb-core/dispatch/router.rb +61 -6
  33. data/lib/merb-core/dispatch/router/behavior.rb +122 -41
  34. data/lib/merb-core/dispatch/router/route.rb +147 -22
  35. data/lib/merb-core/dispatch/session.rb +52 -2
  36. data/lib/merb-core/dispatch/session/cookie.rb +4 -2
  37. data/lib/merb-core/dispatch/session/memcached.rb +38 -27
  38. data/lib/merb-core/dispatch/session/memory.rb +18 -11
  39. data/lib/merb-core/dispatch/worker.rb +28 -0
  40. data/lib/merb-core/gem_ext/erubis.rb +58 -0
  41. data/lib/merb-core/logger.rb +3 -31
  42. data/lib/merb-core/plugins.rb +25 -3
  43. data/lib/merb-core/rack.rb +18 -12
  44. data/lib/merb-core/rack/adapter.rb +10 -8
  45. data/lib/merb-core/rack/adapter/ebb.rb +2 -2
  46. data/lib/merb-core/rack/adapter/irb.rb +31 -21
  47. data/lib/merb-core/rack/adapter/swiftiplied_mongrel.rb +26 -0
  48. data/lib/merb-core/rack/adapter/thin.rb +19 -9
  49. data/lib/merb-core/rack/adapter/thin_turbo.rb +24 -0
  50. data/lib/merb-core/rack/application.rb +9 -84
  51. data/lib/merb-core/rack/middleware.rb +26 -0
  52. data/lib/merb-core/rack/middleware/path_prefix.rb +31 -0
  53. data/lib/merb-core/rack/middleware/profiler.rb +19 -0
  54. data/lib/merb-core/rack/middleware/static.rb +45 -0
  55. data/lib/merb-core/server.rb +27 -9
  56. data/lib/merb-core/tasks/audit.rake +68 -0
  57. data/lib/merb-core/tasks/merb.rb +1 -0
  58. data/lib/merb-core/tasks/merb_rake_helper.rb +12 -0
  59. data/lib/merb-core/tasks/stats.rake +71 -0
  60. data/lib/merb-core/test.rb +2 -1
  61. data/lib/merb-core/test/helpers/multipart_request_helper.rb +3 -3
  62. data/lib/merb-core/test/helpers/request_helper.rb +66 -24
  63. data/lib/merb-core/test/matchers/controller_matchers.rb +36 -4
  64. data/lib/merb-core/test/matchers/route_matchers.rb +12 -3
  65. data/lib/merb-core/test/matchers/view_matchers.rb +3 -3
  66. data/lib/merb-core/test/run_specs.rb +1 -0
  67. data/lib/merb-core/test/tasks/spectasks.rb +13 -5
  68. data/lib/merb-core/test/test_ext/string.rb +14 -0
  69. data/lib/merb-core/vendor/facets/dictionary.rb +3 -3
  70. data/lib/merb-core/vendor/facets/inflect.rb +82 -37
  71. data/lib/merb-core/version.rb +2 -2
  72. data/spec/private/config/config_spec.rb +39 -4
  73. data/spec/private/core_ext/kernel_spec.rb +3 -14
  74. data/spec/private/dispatch/bootloader_spec.rb +1 -1
  75. data/spec/private/dispatch/cookies_spec.rb +181 -69
  76. data/spec/private/dispatch/fixture/app/controllers/exceptions.rb +0 -2
  77. data/spec/private/dispatch/fixture/app/controllers/foo.rb +0 -2
  78. data/spec/private/dispatch/fixture/config/rack.rb +10 -0
  79. data/spec/private/dispatch/fixture/log/merb_test.log +7054 -1802
  80. data/spec/private/dispatch/route_params_spec.rb +2 -3
  81. data/spec/private/dispatch/session_mixin_spec.rb +47 -0
  82. data/spec/private/plugins/plugin_spec.rb +73 -59
  83. data/spec/private/router/behavior_spec.rb +60 -0
  84. data/spec/private/router/fixture/log/merb_test.log +1693 -0
  85. data/spec/private/router/route_spec.rb +414 -0
  86. data/spec/private/router/router_spec.rb +175 -0
  87. data/spec/private/vendor/facets/plural_spec.rb +564 -0
  88. data/spec/private/vendor/facets/singular_spec.rb +489 -0
  89. data/spec/public/abstract_controller/controllers/cousins.rb +41 -0
  90. data/spec/public/abstract_controller/controllers/helpers.rb +12 -2
  91. data/spec/public/abstract_controller/controllers/partial.rb +17 -2
  92. data/spec/public/abstract_controller/controllers/render.rb +16 -1
  93. data/spec/public/abstract_controller/controllers/views/helpers/capture_eq/index.erb +1 -0
  94. data/spec/public/abstract_controller/controllers/views/helpers/capture_with_args/index.erb +1 -0
  95. data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_two_throw_contents/index.erb +1 -0
  96. data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections_and_counter/_collection.erb +1 -0
  97. data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections_and_counter/index.erb +1 -0
  98. data/spec/public/abstract_controller/controllers/views/partial/with_absolute_partial/_partial.erb +1 -0
  99. data/spec/public/abstract_controller/controllers/views/partial/with_absolute_partial/index.erb +1 -0
  100. data/spec/public/abstract_controller/filter_spec.rb +20 -1
  101. data/spec/public/abstract_controller/helper_spec.rb +10 -2
  102. data/spec/public/abstract_controller/partial_spec.rb +8 -0
  103. data/spec/public/abstract_controller/render_spec.rb +8 -0
  104. data/spec/public/abstract_controller/spec_helper.rb +7 -3
  105. data/spec/public/boot_loader/boot_loader_spec.rb +2 -2
  106. data/spec/public/controller/base_spec.rb +10 -2
  107. data/spec/public/controller/config/init.rb +6 -0
  108. data/spec/public/controller/controllers/authentication.rb +9 -11
  109. data/spec/public/controller/controllers/base.rb +2 -8
  110. data/spec/public/controller/controllers/cookies.rb +16 -0
  111. data/spec/public/controller/controllers/dispatcher.rb +35 -0
  112. data/spec/public/controller/controllers/display.rb +62 -14
  113. data/spec/public/controller/controllers/redirect.rb +36 -0
  114. data/spec/public/controller/controllers/responder.rb +37 -11
  115. data/spec/public/controller/controllers/views/layout/custom_arg.json.erb +1 -0
  116. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/class_and_local_provides/index.html.erb +1 -0
  117. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/class_and_local_provides/index.xml.erb +1 -0
  118. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/display_with_template/no_layout.html.erb +1 -0
  119. data/spec/public/controller/cookies_spec.rb +23 -0
  120. data/spec/public/controller/dispatcher_spec.rb +411 -0
  121. data/spec/public/controller/display_spec.rb +43 -10
  122. data/spec/public/controller/redirect_spec.rb +33 -0
  123. data/spec/public/controller/responder_spec.rb +79 -11
  124. data/spec/public/controller/spec_helper.rb +3 -1
  125. data/spec/public/controller/url_spec.rb +10 -0
  126. data/spec/public/core/merb_core_spec.rb +11 -0
  127. data/spec/public/core_ext/fixtures/core_ext_dependency.rb +2 -0
  128. data/spec/public/core_ext/kernel_spec.rb +9 -0
  129. data/spec/public/core_ext/spec_helper.rb +1 -0
  130. data/spec/public/directory_structure/directory/log/merb_test.log +3729 -272
  131. data/spec/public/directory_structure/directory_spec.rb +3 -4
  132. data/spec/public/logger/logger_spec.rb +4 -4
  133. data/spec/public/reloading/directory/log/merb_test.log +288066 -15
  134. data/spec/public/reloading/reload_spec.rb +49 -27
  135. data/spec/public/request/multipart_spec.rb +26 -0
  136. data/spec/public/request/request_spec.rb +21 -2
  137. data/spec/public/router/fixation_spec.rb +27 -0
  138. data/spec/public/router/fixture/log/merb_test.log +30050 -0
  139. data/spec/public/router/nested_matches_spec.rb +97 -0
  140. data/spec/public/router/resource_spec.rb +1 -9
  141. data/spec/public/router/resources_spec.rb +0 -20
  142. data/spec/public/router/spec_helper.rb +27 -9
  143. data/spec/public/router/special_spec.rb +21 -8
  144. data/spec/public/template/template_spec.rb +17 -5
  145. data/spec/public/test/controller_matchers_spec.rb +10 -0
  146. data/spec/public/test/request_helper_spec.rb +29 -0
  147. data/spec/public/test/route_helper_spec.rb +18 -1
  148. data/spec/public/test/route_matchers_spec.rb +28 -1
  149. data/spec/public/test/view_matchers_spec.rb +3 -3
  150. data/spec/spec_helper.rb +56 -12
  151. metadata +89 -47
  152. data/lib/merb-core/core_ext/class.rb +0 -299
  153. data/lib/merb-core/core_ext/hash.rb +0 -426
  154. data/lib/merb-core/core_ext/mash.rb +0 -154
  155. data/lib/merb-core/core_ext/object.rb +0 -147
  156. data/lib/merb-core/core_ext/object_space.rb +0 -14
  157. data/lib/merb-core/core_ext/rubygems.rb +0 -28
  158. data/lib/merb-core/core_ext/set.rb +0 -46
  159. data/lib/merb-core/core_ext/string.rb +0 -89
  160. data/lib/merb-core/core_ext/time.rb +0 -13
  161. data/lib/merb-core/dispatch/exceptions.html.erb +0 -297
  162. data/spec/private/core_ext/class_spec.rb +0 -22
  163. data/spec/private/core_ext/hash_spec.rb +0 -522
  164. data/spec/private/core_ext/object_spec.rb +0 -121
  165. data/spec/private/core_ext/set_spec.rb +0 -26
  166. data/spec/private/core_ext/string_spec.rb +0 -167
  167. data/spec/private/core_ext/time_spec.rb +0 -16
  168. data/spec/private/dispatch/dispatch_spec.rb +0 -26
  169. data/spec/private/dispatch/fixture/log/development.log +0 -1
  170. data/spec/private/dispatch/fixture/log/merb.4000.pid +0 -1
  171. data/spec/private/dispatch/fixture/log/production.log +0 -1
  172. data/spec/private/dispatch/fixture/merb.4000.pid +0 -1
  173. data/spec/private/rack/application_spec.rb +0 -43
  174. data/spec/public/controller/log/merb.4000.pid +0 -1
  175. data/spec/public/directory_structure/directory/log/merb.4000.pid +0 -1
  176. data/spec/public/directory_structure/directory/merb.4000.pid +0 -1
  177. data/spec/public/reloading/directory/log/merb.4000.pid +0 -1
  178. data/spec/public/reloading/directory/merb.4000.pid +0 -1
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2008 Ezra Zygmuntowicz
1
+ Copyright (c) 2008 Engine Yard Inc.
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README CHANGED
@@ -15,7 +15,7 @@ Goals of this release:
15
15
 
16
16
  To familiarize yourself with how a merb-core application might look,
17
17
  use merb-gen (from merb-more) to generate a few apps:
18
- $ merb-gen myapp # a "normal" merb app
19
- $ merb-gen myapp --flat # a flattened app
20
- $ merb-gen myapp --very-flat # a single-file app
18
+ $ merb-gen app myapp # a "normal" merb app
19
+ $ merb-gen app myapp --flat # a flattened app
20
+ $ merb-gen app myapp --very-flat # a single-file app
21
21
 
data/Rakefile CHANGED
@@ -5,6 +5,7 @@ require "rake/rdoctask"
5
5
  require "rake/testtask"
6
6
  require "spec/rake/spectask"
7
7
  require "fileutils"
8
+ require "extlib"
8
9
 
9
10
  def __DIR__
10
11
  File.dirname(__FILE__)
@@ -15,35 +16,39 @@ require __DIR__ + "/tools/annotation_extract"
15
16
 
16
17
  include FileUtils
17
18
 
18
- NAME = "merb-core"
19
-
20
19
  require "lib/merb-core/version"
21
20
  require "lib/merb-core/test/run_specs"
21
+ require 'lib/merb-core/tasks/merb_rake_helper'
22
22
 
23
23
  ##############################################################################
24
- # Packaging & Installation
24
+ # Package && release
25
25
  ##############################################################################
26
- CLEAN.include ["**/.*.sw?", "pkg", "lib/*.bundle", "*.gem", "doc/rdoc", ".config", "coverage", "cache"]
26
+ RUBY_FORGE_PROJECT = "merb"
27
+ PROJECT_URL = "http://merbivore.com"
28
+ PROJECT_SUMMARY = "Merb. Pocket rocket web framework."
29
+ PROJECT_DESCRIPTION = PROJECT_SUMMARY
27
30
 
28
- windows = (PLATFORM =~ /win32|cygwin/) rescue nil
31
+ AUTHOR = "Ezra Zygmuntowicz"
32
+ EMAIL = "ez@engineyard.com"
29
33
 
30
- SUDO = windows ? "" : "sudo"
34
+ GEM_NAME = "merb-core"
35
+ PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
36
+ GEM_VERSION = Merb::VERSION + PKG_BUILD
31
37
 
32
- desc "Packages up Merb."
33
- task :default => :package
38
+ RELEASE_NAME = "REL #{GEM_VERSION}"
34
39
 
35
- task :merb => [:clean, :rdoc, :package]
40
+ require "extlib/tasks/release"
36
41
 
37
42
  spec = Gem::Specification.new do |s|
38
- s.name = NAME
39
- s.version = Merb::VERSION
43
+ s.name = GEM_NAME
44
+ s.version = GEM_VERSION
40
45
  s.platform = Gem::Platform::RUBY
41
- s.author = "Ezra Zygmuntowicz"
42
- s.email = "ez@engineyard.com"
43
- s.homepage = "http://merbivore.com"
44
- s.summary = "Merb. Pocket rocket web framework."
46
+ s.author = AUTHOR
47
+ s.email = EMAIL
48
+ s.homepage = PROJECT_URL
49
+ s.summary = PROJECT_SUMMARY
45
50
  s.bindir = "bin"
46
- s.description = s.summary
51
+ s.description = PROJECT_DESCRIPTION
47
52
  s.executables = %w( merb )
48
53
  s.require_path = "lib"
49
54
  s.files = %w( LICENSE README Rakefile TODO ) + Dir["{docs,bin,spec,lib,examples,app_generators,merb_generators,merb_default_generators,rspec_generators,test_unit_generators,script}/**/*"]
@@ -54,16 +59,16 @@ spec = Gem::Specification.new do |s|
54
59
  #s.rdoc_options += RDOC_OPTS + ["--exclude", "^(app|uploads)"]
55
60
 
56
61
  # Dependencies
62
+ s.add_dependency "extlib", ">=0.9.3"
57
63
  s.add_dependency "erubis"
58
64
  s.add_dependency "rake"
59
65
  s.add_dependency "json_pure"
60
66
  s.add_dependency "rspec"
61
67
  s.add_dependency "rack"
62
- s.add_dependency "hpricot"
63
68
  s.add_dependency "mime-types"
64
69
  # Requirements
65
70
  s.requirements << "install the json gem to get faster json parsing"
66
- s.required_ruby_version = ">= 1.8.4"
71
+ s.required_ruby_version = ">= 1.8.6"
67
72
  end
68
73
 
69
74
  Rake::GemPackageTask.new(spec) do |package|
@@ -72,32 +77,42 @@ end
72
77
 
73
78
  desc "Run :package and install the resulting .gem"
74
79
  task :install => :package do
75
- sh %{#{SUDO} gem install --local pkg/#{NAME}-#{Merb::VERSION}.gem --no-rdoc --no-ri}
80
+ sh %{#{sudo} gem install #{install_home} --local pkg/#{GEM_NAME}-#{GEM_VERSION}.gem --no-rdoc --no-ri}
76
81
  end
77
82
 
78
83
  desc "Run :package and install the resulting .gem with jruby"
79
84
  task :jinstall => :package do
80
- sh %{#{SUDO} jruby -S gem install pkg/#{NAME}-#{Merb::VERSION}.gem --no-rdoc --no-ri}
85
+ sh %{#{sudo} jruby -S gem install #{install_home} pkg/#{NAME}-#{Merb::VERSION}.gem --no-rdoc --no-ri}
81
86
  end
82
87
 
83
88
  desc "Run :clean and uninstall the .gem"
84
89
  task :uninstall => :clean do
85
- sh %{#{SUDO} gem uninstall #{NAME}}
90
+ sh %{#{sudo} gem uninstall #{NAME}}
86
91
  end
87
92
 
93
+ CLEAN.include ["**/.*.sw?", "pkg", "lib/*.bundle", "*.gem", "doc/rdoc", ".config", "coverage", "cache"]
94
+
95
+ desc "Run the specs."
96
+ task :default => :specs
97
+
98
+ task :merb => [:clean, :rdoc, :package]
99
+
100
+ ##############################################################################
101
+ # Github
102
+ ##############################################################################
88
103
  namespace :github do
89
104
  desc "Update Github Gemspec"
90
105
  task :update_gemspec do
91
106
  skip_fields = %w(new_platform original_platform)
92
107
  integer_fields = %w(specification_version)
93
-
108
+
94
109
  result = "Gem::Specification.new do |s|\n"
95
- spec.instance_variables.each do |ivar|
110
+ spec.instance_variables.each do |ivar|
96
111
  value = spec.instance_variable_get(ivar)
97
112
  name = ivar.split("@").last
98
113
  next if skip_fields.include?(name) || value.nil? || value == "" || (value.respond_to?(:empty?) && value.empty?)
99
114
  if name == "dependencies"
100
- value.each do |d|
115
+ value.each do |d|
101
116
  dep, *ver = d.to_s.split(" ")
102
117
  result << " s.add_dependency #{dep.inspect}, #{ver.join(" ").inspect.gsub(/[()]/, "")}\n"
103
118
  end
@@ -143,7 +158,7 @@ namespace :doc do
143
158
  desc "rdoc to rubyforge"
144
159
  task :rubyforge do
145
160
  # sh %{rake doc}
146
- sh %{#{SUDO} chmod -R 755 doc} unless windows
161
+ sh %{#{sudo} chmod -R 755 doc} unless windows?
147
162
  sh %{/usr/bin/scp -r -p doc/rdoc/* ezmobius@rubyforge.org:/var/www/gforge-projects/merb}
148
163
  end
149
164
 
@@ -255,14 +270,6 @@ task :stats do
255
270
  CodeStatistics.new(*STATS_DIRECTORIES).to_s
256
271
  end
257
272
 
258
- task :release => :package do
259
- if ENV["RELEASE"]
260
- sh %{rubyforge add_release merb merb "#{ENV["RELEASE"]}" pkg/#{NAME}-#{Merb::VERSION}.gem}
261
- else
262
- puts "Usage: rake release RELEASE='Clever tag line goes here'"
263
- end
264
- end
265
-
266
273
  ##############################################################################
267
274
  # SYNTAX CHECKING
268
275
  ##############################################################################
@@ -306,6 +313,68 @@ namespace :repo do
306
313
 
307
314
  end
308
315
 
316
+ def git_log(since_release = nil, log_format = "format:%an")
317
+ git_log_query = "git log --pretty='format:#{log_format}' --no-merges"
318
+ git_log_query << " --since='#{since_release}'" if since_release
319
+ puts
320
+ puts "Running #{git_log_query}"
321
+ puts
322
+ `#{git_log_query}`
323
+ end
324
+
325
+ def contributors(since_release = nil)
326
+ @merb_contributors ||= git_log(since_release).split("\n").uniq.sort
327
+ end
328
+
329
+ PREVIOUS_RELEASE = '0.9.3'
330
+ namespace :history do
331
+ namespace :update do
332
+ desc "updates contributors list"
333
+ task :contributors do
334
+ list = contributors.join "\n"
335
+
336
+ path = File.join(File.dirname(__FILE__), 'CONTRIBUTORS')
337
+
338
+ rm path if File.exists?(path)
339
+
340
+ puts "Writing contributors (#{contributors.size} entries)."
341
+ # windows needs wb
342
+ File.open(path, "wb") do |io|
343
+ io << "Use #{RUBY_FORGE_PROJECT}? Say thanks the following people:\n\n"
344
+ io << list
345
+ end
346
+ end
347
+ end
348
+
349
+
350
+ namespace :alltime do
351
+ desc 'shows all-time committers'
352
+ task :contributors do
353
+ puts 'All-time contributors (#{contributors.size} total): '
354
+ puts '=============================='
355
+ puts
356
+ puts contributors.join("\n")
357
+ end
358
+ end
359
+
360
+ namespace :current_release do
361
+ desc "show changes since previous release"
362
+ task :changes do
363
+ puts git_log(PREVIOUS_RELEASE, "format:* %s")
364
+ end
365
+
366
+
367
+ desc 'shows current release committers'
368
+ task :contributors do
369
+ puts "Current release contributors (#{contributors.size} total): "
370
+ puts '=============================='
371
+ puts
372
+ puts contributors(PREVIOUS_RELEASE).join("\n")
373
+ end
374
+ end
375
+ end
376
+
377
+
309
378
  # Run specific tests or test files. Searches nested spec directories as well.
310
379
  #
311
380
  # Based on a technique popularized by Geoffrey Grosenbach
@@ -333,3 +402,45 @@ rule "" do |t|
333
402
  sh "#{spec_cmd} #{run_file_name} --format specdoc --colour #{example}"
334
403
  end
335
404
  end
405
+
406
+ ##############################################################################
407
+ # Flog
408
+ ##############################################################################
409
+
410
+ namespace :flog do
411
+ task :worst_methods do
412
+ require "flog"
413
+ flogger = Flog.new
414
+ flogger.flog_files Dir["lib/**/*.rb"]
415
+ totals = flogger.totals.sort_by {|k,v| v}.reverse[0..10]
416
+ totals.each do |meth, total|
417
+ puts "%50s: %s" % [meth, total]
418
+ end
419
+ end
420
+
421
+ task :total do
422
+ require "flog"
423
+ flogger = Flog.new
424
+ flogger.flog_files Dir["lib/**/*.rb"]
425
+ puts "Total: #{flogger.total}"
426
+ end
427
+
428
+ task :per_method do
429
+ require "flog"
430
+ flogger = Flog.new
431
+ flogger.flog_files Dir["lib/**/*.rb"]
432
+ methods = flogger.totals.reject { |k,v| k =~ /\#none$/ }.sort_by { |k,v| v }
433
+ puts "Total Flog: #{flogger.total}"
434
+ puts "Total Methods: #{flogger.totals.size}"
435
+ puts "Flog / Method: #{flogger.total / methods.size}"
436
+ end
437
+ end
438
+
439
+ namespace :tools do
440
+ namespace :tags do
441
+ desc "Generates Emacs tags using Exuberant Ctags."
442
+ task :emacs do
443
+ sh "ctags -e --Ruby-kinds=-f -o TAGS -R lib"
444
+ end
445
+ end
446
+ end
data/bin/merb CHANGED
File without changes
File without changes
@@ -55,3 +55,4 @@ deflist: MimeTypes.
55
55
  \:xml: to_xml, application/xml or text/xml or application/x-xml, adds "Encoding: UTF-8" response header
56
56
  \:js: to_json, text/javascript ot application/javascript or application/x-javascript
57
57
  \:json: to_json, application/json or text/x-json
58
+
@@ -4,15 +4,70 @@ require 'rubygems'
4
4
  require 'set'
5
5
  require 'fileutils'
6
6
  require 'socket'
7
+ require 'pathname'
8
+ require "extlib"
7
9
 
8
- $LOAD_PATH.unshift File.dirname(__FILE__) unless
9
- $LOAD_PATH.include?(File.dirname(__FILE__)) ||
10
- $LOAD_PATH.include?(File.expand_path(File.dirname(__FILE__)))
10
+ __DIR__ = File.dirname(__FILE__)
11
+
12
+ $LOAD_PATH.unshift __DIR__ unless
13
+ $LOAD_PATH.include?(__DIR__) ||
14
+ $LOAD_PATH.include?(File.expand_path(__DIR__))
15
+
16
+ require 'merb-core' / 'vendor' / 'facets'
11
17
 
12
18
  module Merb
13
19
  module GlobalHelpers; end
14
20
  class << self
15
21
 
22
+ # Merge environment settings
23
+ # Can allow you to have a "localdev" that runs like your "development"
24
+ # OR
25
+ # A "staging" environment that runs like your "production"
26
+ #
27
+ # ==== Examples
28
+ # From any environment config file (ie, development.rb, custom.rb, localdev.rb, etc)
29
+ # staging.rb:
30
+ # Merb.merge_env "production" #We want to use all the settings production uses
31
+ # Merb::Config.use { |c|
32
+ # c[:log_level] = "debug" #except we want debug log level
33
+ # c[:exception_details] = true #and we want to see exception details
34
+ # }
35
+ #
36
+ # ==== Parameters
37
+ # env<~String>:: Environment to run like
38
+ # use_db<~Boolean>:: Should Merb use the merged environments DB connection
39
+ # Defaults to +false+
40
+ def merge_env(env,use_db=false)
41
+ if Merb.environment_info.nil?
42
+ Merb.environment_info = {
43
+ :real_env => Merb.environment,
44
+ :merged_envs => [],
45
+ :db_env => Merb.environment
46
+ }
47
+ end
48
+
49
+ #Only load if it hasn't been loaded
50
+ unless Merb.environment_info[:merged_envs].member? env
51
+ Merb.environment_info[:merged_envs] << env
52
+
53
+ env_file = Merb.dir_for(:config) / "environments" / ("#{env}.rb")
54
+ if File.exists?(env_file)
55
+ load(env_file)
56
+ else
57
+ Merb.logger.warn! "Environment file does not exist! #{env_file}"
58
+ end
59
+
60
+ end
61
+
62
+ # Mark specific environment to load when ORM loads,
63
+ # if multiple environments are loaded, the last one
64
+ # with use_db as TRUE will be loaded
65
+ if use_db
66
+ Merb.environment_info[:db_env] = env
67
+ end
68
+ end
69
+
70
+
16
71
  # Startup Merb by setting up the Config and starting the server.
17
72
  # This is where Merb application environment and root path are set.
18
73
  #
@@ -59,11 +114,12 @@ module Merb
59
114
  start_environment(Merb::Config.to_hash.merge(argv))
60
115
  end
61
116
 
62
- attr_accessor :environment, :load_paths, :adapter
117
+ attr_accessor :environment, :load_paths, :adapter, :environment_info, :started
63
118
 
64
119
  alias :env :environment
120
+ alias :started? :started
65
121
 
66
- Merb.load_paths = Hash.new { [Merb.root] } unless Merb.load_paths.is_a?(Hash)
122
+ Merb.load_paths = Dictionary.new { [Merb.root] } unless Merb.load_paths.is_a?(Dictionary)
67
123
 
68
124
  # This is the core mechanism for setting up your application layout.
69
125
  # There are three application layouts in Merb:
@@ -103,10 +159,10 @@ module Merb
103
159
  # uses to simplify transition of legacy application, you can
104
160
  # set it up like this:
105
161
  #
106
- # Merb.push_path(:models, Merb.root / "app" / "models", "**/*.rb")
107
- # Merb.push_path(:mailers, Merb.root / "app" / "models", "**/*.rb")
108
- # Merb.push_path(:controllers, Merb.root / "app" / "controllers", "**/*.rb")
109
- # Merb.push_path(:views, Merb.root / "app" / "views", "**/*.rb")
162
+ # Merb.push_path(:model, Merb.root / "app" / "models", "**/*.rb")
163
+ # Merb.push_path(:mailer, Merb.root / "app" / "models", "**/*.rb")
164
+ # Merb.push_path(:controller, Merb.root / "app" / "controllers", "**/*.rb")
165
+ # Merb.push_path(:view, Merb.root / "app" / "views", "**/*.rb")
110
166
  #
111
167
  # ==== Parameters
112
168
  # type<Symbol>:: The type of path being registered (i.e. :view)
@@ -116,7 +172,7 @@ module Merb
116
172
  # "**/*.rb".
117
173
  def push_path(type, path, file_glob = "**/*.rb")
118
174
  enforce!(type => Symbol)
119
- load_paths[type] = [path, file_glob]
175
+ load_paths[type] = [Pathname.new(path), file_glob]
120
176
  end
121
177
 
122
178
  # Removes given types of application components
@@ -132,8 +188,8 @@ module Merb
132
188
  # application components.
133
189
  #
134
190
  # Merb.root = "path/to/legacy/app/root"
135
- # Merb.remove_paths(:mailers)
136
- # Merb.push_path(:mailers, Merb.root / "app" / "models", "**/*.rb")
191
+ # Merb.remove_paths(:mailer)
192
+ # Merb.push_path(:mailer, Merb.root / "app" / "models", "**/*.rb")
137
193
  #
138
194
  # Will make Merb use app/models for mailers just like Ruby on Rails does.
139
195
  def remove_paths(*args)
@@ -145,22 +201,32 @@ module Merb
145
201
  #
146
202
  # ==== Returns
147
203
  # String:: The directory for the requested type.
148
- def dir_for(type) Merb.load_paths[type].first end
204
+ def dir_for(type)
205
+ Merb.load_paths[type].first
206
+ end
149
207
 
150
208
  # ==== Parameters
151
209
  # type<Symbol>:: The type of path to retrieve glob for, e.g. :view.
152
210
  #
153
211
  # ===== Returns
154
212
  # String:: The pattern with which to match files within the type directory.
155
- def glob_for(type) Merb.load_paths[type][1] end
213
+ def glob_for(type)
214
+ Merb.load_paths[type][1]
215
+ end
156
216
 
157
217
  # ==== Returns
158
218
  # String:: The Merb root path.
159
- def root() @root || Merb::Config[:merb_root] || Dir.pwd end
219
+ def root
220
+ app_root = @root || Merb::Config[:merb_root] || Dir.pwd
221
+
222
+ Pathname.new(app_root)
223
+ end
160
224
 
161
225
  # ==== Parameters
162
226
  # value<String>:: Path to the root directory.
163
- def root=(value) @root = value end
227
+ def root=(value)
228
+ @root = Pathname.new(value)
229
+ end
164
230
 
165
231
  # ==== Parameters
166
232
  # *path::
@@ -176,7 +242,9 @@ module Merb
176
242
  # Merb.path("views", "admin") # => "/home/merb/app/views/admin"
177
243
  #---
178
244
  # @public
179
- def root_path(*path) File.join(root, *path) end
245
+ def root_path(*path)
246
+ Pathname.new(File.join(root, *path))
247
+ end
180
248
 
181
249
  # Logger settings
182
250
  attr_accessor :logger
@@ -200,15 +268,19 @@ module Merb
200
268
  # ==== Returns
201
269
  # String:: Path to directory that contains the log file.
202
270
  def log_path
203
- case Merb::Config[:log_file]
271
+ path = case Merb::Config[:log_file]
204
272
  when String then File.dirname(Merb::Config[:log_file])
205
273
  else Merb.root_path("log")
206
274
  end
275
+
276
+ Pathname.new(path)
207
277
  end
208
278
 
209
279
  # ==== Returns
210
280
  # String:: The path of root directory of the Merb framework.
211
- def framework_root() @framework_root ||= File.dirname(__FILE__) end
281
+ def framework_root
282
+ @framework_root ||= Pathname(File.dirname(__FILE__))
283
+ end
212
284
 
213
285
  # ==== Returns
214
286
  # RegExp::
@@ -245,8 +317,35 @@ module Merb
245
317
  end
246
318
 
247
319
  # Set up default variables under Merb
248
- attr_accessor :generator_scope, :klass_hashes
249
- Merb.generator_scope = [:merb_default, :merb, :rspec]
320
+ attr_accessor :generator_scope, :klass_hashes, :orm_generator_scope, :test_framework_generator_scope
321
+
322
+ # Returns registered ORM generators as symbols,
323
+ # for instance, :datamapper.
324
+ #
325
+ # ==== Returns
326
+ # <Array(Symbol>:: registered ORM generators.
327
+ def orm_generator_scope
328
+ @orm_generator_scope ||= :merb_default
329
+ end
330
+
331
+ # Returns registered test framework generators.
332
+ #
333
+ # ==== Returns
334
+ # <Array(Symbol>:: registred test framework generators.
335
+ def test_framework_generator_scope
336
+ @test_framework_generator_scope ||= :rspec
337
+ end
338
+
339
+ # Returns all registered generators plus Merb generator.
340
+ #
341
+ # ==== Returns
342
+ # <Array(Symbol>::
343
+ # all registered generators, inc. needed by Merb itself.
344
+ def generator_scope
345
+ [:merb, orm_generator_scope, test_framework_generator_scope]
346
+ end
347
+
348
+
250
349
  Merb.klass_hashes = []
251
350
 
252
351
  attr_reader :registered_session_types
@@ -270,7 +369,7 @@ module Merb
270
369
  attr_accessor :frozen
271
370
 
272
371
  # ==== Returns
273
- # Boolean:: True if Merb is running via script/frozen-merb or other freezer.
372
+ # Boolean:: True if Merb is running via merb-freezer or other freezer.
274
373
  #
275
374
  # ==== Notes
276
375
  # Freezing means bundling framework libraries with your application
@@ -282,7 +381,7 @@ module Merb
282
381
  @frozen
283
382
  end
284
383
 
285
- # Used by script/frozen-merb and other freezers to mark Merb as frozen.
384
+ # Used by merb-freezer and other freezers to mark Merb as frozen.
286
385
  # See Merb::GlobalHelpers.frozen? for more details on framework freezing.
287
386
  def frozen!
288
387
  @frozen = true
@@ -322,6 +421,9 @@ module Merb
322
421
  # :session_id_key<String>:: session identifier,
323
422
  # default is _session_id
324
423
  #
424
+ # :session_store<String>:: session store to use (one of cookies,
425
+ # memcache or memory)
426
+ #
325
427
  # :log_delimiter<String>:: what Merb logger uses as delimiter
326
428
  # between message sections, default is " ~ "
327
429
  #
@@ -352,6 +454,10 @@ module Merb
352
454
  end
353
455
 
354
456
  # Load all basic dependencies (selected BootLoaders only).
457
+ # This sets up Merb framework component paths
458
+ # (directories for models, controllers, etc) using
459
+ # framework.rb or default layout, loads init file
460
+ # and dependencies specified in it and runs before_app_loads hooks.
355
461
  #
356
462
  # ==== Parameters
357
463
  # options<Hash>:: Options to pass on to the Merb config.
@@ -359,7 +465,7 @@ module Merb
359
465
  load_config(options)
360
466
  Merb::BootLoader::BuildFramework.run
361
467
  Merb::BootLoader::Dependencies.run
362
- Merb::BootLoader::BeforeAppRuns.run
468
+ Merb::BootLoader::BeforeAppLoads.run
363
469
  end
364
470
 
365
471
  # Reload application and framework classes.
@@ -422,7 +528,7 @@ module Merb
422
528
  # ==== Parameters
423
529
  # *args:: One or more symbols of Merb internal components.
424
530
  def disable(*components)
425
- disabled_components.push *components
531
+ disabled_components.push(*components)
426
532
  end
427
533
 
428
534
  # ==== Parameters
@@ -450,7 +556,17 @@ module Merb
450
556
  # Recommended way to find out what paths Rakefiles
451
557
  # are loaded from.
452
558
  def rakefiles
453
- @rakefiles ||= ['merb-core/test/tasks/spectasks']
559
+ @rakefiles ||= ['merb-core' / 'test' / 'tasks' / 'spectasks']
560
+ end
561
+
562
+ # === Returns
563
+ # Array(String):: Paths generators are loaded from
564
+ #
565
+ # === Notes
566
+ # Recommended way to find out what paths generators
567
+ # are loaded from.
568
+ def generators
569
+ @generators ||= []
454
570
  end
455
571
 
456
572
  # ==== Parameters
@@ -459,23 +575,29 @@ module Merb
459
575
  # ==== Notes
460
576
  # Recommended way to add Rakefiles load path for plugins authors.
461
577
  def add_rakefiles(*rakefiles)
462
- @rakefiles ||= ['merb-core/test/tasks/spectasks']
578
+ @rakefiles ||= ['merb-core' / 'test' / 'tasks' / 'spectasks']
463
579
  @rakefiles += rakefiles
464
580
  end
465
-
466
-
467
-
581
+
582
+ # ==== Parameters
583
+ # *generators:: Generator paths to add to the list of generators.
584
+ #
585
+ # ==== Notes
586
+ # Recommended way to add Generator load paths for plugin authors.
587
+ def add_generators(*generators)
588
+ @generators ||= []
589
+ @generators += generators
590
+ end
468
591
 
469
592
  end
470
593
  end
471
594
 
472
- require 'merb-core/autoload'
473
- require 'merb-core/server'
474
- require 'merb-core/gem_ext/erubis'
475
- require 'merb-core/logger'
476
- require 'merb-core/version'
477
- require 'merb-core/controller/mime'
478
- require 'merb-core/vendor/facets'
595
+ require 'merb-core' / 'autoload'
596
+ require 'merb-core' / 'server'
597
+ require 'merb-core' / 'gem_ext/erubis'
598
+ require 'merb-core' / 'logger'
599
+ require 'merb-core' / 'version'
600
+ require 'merb-core' / 'controller/mime'
479
601
 
480
602
  # Set the environment if it hasn't already been set.
481
603
  Merb.environment ||= ENV['MERB_ENV'] || Merb::Config[:environment] || (Merb.testing? ? 'test' : 'development')