Skip to content

Commit

Permalink
method_missing should always be private
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleym1972 committed Apr 23, 2010
1 parent 08df67d commit 65b71f0
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 14 deletions.
1 change: 1 addition & 0 deletions config/environment.rb
@@ -1,6 +1,7 @@
require 'rubygems'
gem 'activesupport', '~> 2.3.0'
gem 'activerecord', '~> 2.3.0'
gem 'actionpack', '~> 2.3.0'
gem 'rspec', '>= 1.3.0'

require 'action_controller'
Expand Down
11 changes: 7 additions & 4 deletions lib/cash/buffered.rb
Expand Up @@ -80,15 +80,12 @@ def flush
end
end

def method_missing(method, *args, &block)
@cache.send(method, *args, &block)
end

def respond_to?(method)
@cache.respond_to?(method)
end

protected

def perform_commands
@commands.each do |command|
command.call(@cache)
Expand All @@ -98,6 +95,12 @@ def perform_commands
def buffer_command(command)
@commands << command
end

private

def method_missing(method, *args, &block)
@cache.send(method, *args, &block)
end
end

class NestedBuffered < Buffered
Expand Down
16 changes: 10 additions & 6 deletions lib/cash/local.rb
Expand Up @@ -12,12 +12,6 @@ def cache_locally
ensure
@remote_cache = original_cache
end

def method_missing(method, *args, &block)
autoload_missing_constants do
@remote_cache.send(method, *args, &block)
end
end

def autoload_missing_constants
yield if block_given?
Expand All @@ -29,6 +23,14 @@ def autoload_missing_constants
raise error
end
end

private

def method_missing(method, *args, &block)
autoload_missing_constants do
@remote_cache.send(method, *args, &block)
end
end
end

class LocalBuffer
Expand Down Expand Up @@ -65,6 +67,8 @@ def delete(key, *options)
@local_cache.delete(key)
end

private

def method_missing(method, *args, &block)
@remote_cache.send(method, *args, &block)
end
Expand Down
9 changes: 5 additions & 4 deletions lib/cash/transactional.rb
Expand Up @@ -22,15 +22,16 @@ def transaction
end
end

def method_missing(method, *args, &block)
@cache.send(method, *args, &block)
end

def respond_to?(method)
@cache.respond_to?(method)
end

private

def method_missing(method, *args, &block)
@cache.send(method, *args, &block)
end

def begin_transaction
@cache = Buffered.push(@cache, @lock)
end
Expand Down
9 changes: 9 additions & 0 deletions spec/cash/buffered_spec.rb
@@ -0,0 +1,9 @@
require "spec_helper"

module Cash
describe Buffered do
it "should have method missing as a private method" do
Buffered.private_instance_methods.should include("method_missing")
end
end
end
9 changes: 9 additions & 0 deletions spec/cash/local_buffer_spec.rb
@@ -0,0 +1,9 @@
require "spec_helper"

module Cash
describe LocalBuffer do
it "should have method missing as a private method" do
LocalBuffer.private_instance_methods.should include("method_missing")
end
end
end
9 changes: 9 additions & 0 deletions spec/cash/local_spec.rb
@@ -0,0 +1,9 @@
require "spec_helper"

module Cash
describe Local do
it "should have method missing as a private method" do
Local.private_instance_methods.should include("method_missing")
end
end
end
4 changes: 4 additions & 0 deletions spec/cash/transactional_spec.rb
Expand Up @@ -570,5 +570,9 @@ module Cash
end
end
end

it "should have method_missing as a private method" do
Transactional.private_instance_methods.should include("method_missing")
end
end
end

0 comments on commit 65b71f0

Please sign in to comment.