merb-core 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -103,7 +103,7 @@ task :gemspec do
103
103
  end
104
104
  end
105
105
 
106
- CLEAN.include ["**/.*.sw?", "pkg", "lib/*.bundle", "lib/*.so", "*.gem", "doc/rdoc", ".config", "coverage", "cache", "spec/**/*.log", "**/gems/*"]
106
+ CLEAN.include ["**/.*.sw?", "pkg", "lib/*.bundle", "lib/*.so", "*.gem", "doc/rdoc", ".config", "coverage", "cache", "spec/**/*.log", "gems/*"]
107
107
 
108
108
  desc "Run the specs."
109
109
  task :default => :specs
data/lib/merb-core.rb CHANGED
@@ -38,6 +38,7 @@ $MINIGEMS_SKIPPABLE = ['encoding/character/utf-8']
38
38
  module Merb
39
39
  # Create stub module for global controller helpers.
40
40
  module GlobalHelpers; end
41
+ class ReservedError < StandardError; end
41
42
 
42
43
  class << self
43
44
  attr_reader :exiting
@@ -434,7 +434,7 @@ class Merb::BootLoader::Dependencies < Merb::BootLoader
434
434
  if Merb::Config[:log_file]
435
435
  raise "log file should be a string, got: #{Merb::Config[:log_file].inspect}" unless Merb::Config[:log_file].is_a?(String)
436
436
  STDOUT.puts "Logging to file at #{Merb::Config[:log_file]}" unless Merb.testing?
437
- Merb::Config[:log_stream] = File.open(Merb::Config[:log_file], "w+")
437
+ Merb::Config[:log_stream] = File.open(Merb::Config[:log_file], "a")
438
438
  # but if it's not given, fallback to log stream or stdout
439
439
  else
440
440
  Merb::Config[:log_stream] ||= STDOUT
@@ -1,9 +1,12 @@
1
1
  class Merb::Controller < Merb::AbstractController
2
2
 
3
- class_inheritable_accessor :_hidden_actions, :_shown_actions
3
+ class_inheritable_accessor :_hidden_actions, :_shown_actions,
4
+ :_overridable, :_override_bang
4
5
 
5
6
  self._hidden_actions ||= []
6
7
  self._shown_actions ||= []
8
+ self._overridable ||= []
9
+ self._override_bang ||= []
7
10
 
8
11
  cattr_accessor :_subclasses
9
12
  self._subclasses = Set.new
@@ -27,6 +30,61 @@ class Merb::Controller < Merb::AbstractController
27
30
  klass._template_root = Merb.dir_for(:view) unless self._template_root
28
31
  end
29
32
 
33
+ # ==== Parameters
34
+ # *names<Array[Symbol]>::
35
+ # an Array of method names that should be overridable in application
36
+ # controllers.
37
+ #
38
+ # ==== Returns
39
+ # Array:: The list of methods that are overridable
40
+ #
41
+ # :api: plugin
42
+ def self.overridable(*names)
43
+ self._overridable.push(*names)
44
+ end
45
+
46
+ # In an application controller, call override! before a method to indicate
47
+ # that you want to override a method in Merb::Controller that is not
48
+ # normally overridable.
49
+ #
50
+ # Doing this may potentially break your app in a future release of Merb,
51
+ # and this is provided for users who are willing to take that risk.
52
+ # Without using override!, Merb will raise an error if you attempt to
53
+ # override a method defined on Merb::Controller.
54
+ #
55
+ # This is to help users avoid a common mistake of defining an action
56
+ # that overrides a core method on Merb::Controller.
57
+ #
58
+ # ==== Parameters
59
+ # *names<Array[Symbol]>::
60
+ # An Array of methods that will override Merb core classes on purpose
61
+ #
62
+ # ==== Example
63
+ #
64
+ # class Kontroller < Application
65
+ # def status
66
+ # render
67
+ # end
68
+ # end
69
+ #
70
+ # will raise a Merb::ReservedError, because #status is a method on
71
+ # Merb::Controller.
72
+ #
73
+ # class Kontroller < Application
74
+ # override! :status
75
+ # def status
76
+ # some_code || super
77
+ # end
78
+ # end
79
+ #
80
+ # will not raise a Merb::ReservedError, because the user specifically
81
+ # decided to override the status method.
82
+ #
83
+ # :api: public
84
+ def self.override!(*names)
85
+ self._overrride_bang.push(*names)
86
+ end
87
+
30
88
  # Hide each of the given methods from being callable as actions.
31
89
  #
32
90
  # ==== Parameters
@@ -97,6 +155,7 @@ class Merb::Controller < Merb::AbstractController
97
155
  def self._filter_params(params)
98
156
  params
99
157
  end
158
+ overridable :_filter_params
100
159
 
101
160
  # All methods that are callable as actions.
102
161
  #
@@ -135,6 +194,7 @@ class Merb::Controller < Merb::AbstractController
135
194
  def _template_location(context, type, controller)
136
195
  _conditionally_append_extension(controller ? "#{controller}/#{context}" : "#{context}", type)
137
196
  end
197
+ overridable :_template_location
138
198
 
139
199
  # The location to look for a template and mime-type. This is overridden
140
200
  # from AbstractController, which defines a version of this that does not
@@ -171,6 +231,7 @@ class Merb::Controller < Merb::AbstractController
171
231
  super()
172
232
  @request, @_status, @headers = request, status, headers
173
233
  end
234
+ overridable :initialize
174
235
 
175
236
  # Dispatch the action.
176
237
  #
@@ -389,4 +450,35 @@ class Merb::Controller < Merb::AbstractController
389
450
  def _conditionally_append_extension(template, type)
390
451
  type && !template.match(/\.#{type.to_s.escape_regexp}$/) ? "#{template}.#{type}" : template
391
452
  end
453
+
454
+ # When a method is added to a subclass of Merb::Controller (i.e. an app controller) that
455
+ # is defined on Merb::Controller, raise a Merb::ReservedError. An error will not be raised
456
+ # if the method is defined as overridable in the Merb API.
457
+ #
458
+ # This behavior can be overridden by using override! method_name before attempting to
459
+ # override the method.
460
+ #
461
+ # ==== Parameters
462
+ # meth<~to_sym> The method that is being added
463
+ #
464
+ # ==== Raises
465
+ # Merb::ReservedError::
466
+ # If the method being added is in a subclass of Merb::Controller,
467
+ # the method is defined on Merb::Controller, it is not defined
468
+ # as overridable in the Merb API, and the user has not specified
469
+ # that it can be overridden.
470
+ #
471
+ # ==== Returns
472
+ # nil
473
+ #
474
+ # :api: private
475
+ def self.method_added(meth)
476
+ if self < Merb::Controller && Merb::Controller.method_defined?(meth) &&
477
+ !self._overridable.include?(meth.to_sym) && !self._override_bang.include?(meth.to_sym)
478
+
479
+ raise Merb::ReservedError, "You tried to define #{meth} on " \
480
+ "#{self.name} but it was already defined on Merb::Controller. " \
481
+ "If you meant to override a core method, use override!"
482
+ end
483
+ end
392
484
  end
@@ -321,9 +321,9 @@ module Merb
321
321
  condition = "(cached_#{segment} = params[#{segment.inspect}] || include_defaults && defaults[#{segment.inspect}])"
322
322
 
323
323
  if @symbol_conditions[segment] && @symbol_conditions[segment].is_a?(Regexp)
324
- condition << " =~ #{@symbol_conditions[segment].inspect}"
324
+ condition << " && cached_#{segment}.to_s =~ #{@symbol_conditions[segment].inspect}"
325
325
  elsif @symbol_conditions[segment]
326
- condition << " == #{@symbol_conditions[segment].inspect}"
326
+ condition << " && cached_#{segment}.to_s == #{@symbol_conditions[segment].inspect}"
327
327
  end
328
328
 
329
329
  condition
@@ -9,7 +9,12 @@ begin
9
9
  require 'webrat'
10
10
  require 'webrat/merb'
11
11
  rescue LoadError => e
12
- Merb.fatal! "Couldn't load Webrat. You should run: sudo gem install webrat", e
12
+ if Merb.testing?
13
+ Merb.fatal! "Couldn't load Webrat. You should run: sudo gem install webrat", e
14
+ else
15
+ Merb.logger.warn! "Couldn't load Webrat, so some features, like `visit' will not " \
16
+ "be available. Please install webrat if you want these features."
17
+ end
13
18
  end
14
19
 
15
20
  if Merb.test_framework.to_s == "rspec"
@@ -112,7 +112,7 @@ module Merb
112
112
  cookies[cookie.name] = cookie.raw if cookie.matches?(uri)
113
113
  end
114
114
 
115
- cookies.values.join
115
+ cookies.values.join(';')
116
116
  end
117
117
 
118
118
  end
@@ -1,3 +1,4 @@
1
1
  module Merb
2
- VERSION = '1.0.1' unless defined?(Merb::VERSION)
2
+ VERSION = '1.0.2' unless defined?(Merb::VERSION)
3
+ DM_VERSION = '0.9.7' unless defined?(Merb::DM_VERSION)
3
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: merb-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ezra Zygmuntowicz
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-11-18 00:00:00 -08:00
12
+ date: 2008-11-24 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency