From 65b71f097b48fb0ea9493a452f35c7554e90fcb3 Mon Sep 17 00:00:00 2001 From: Ashley Martens Date: Fri, 23 Apr 2010 13:38:49 -0700 Subject: [PATCH] method_missing should always be private --- config/environment.rb | 1 + lib/cash/buffered.rb | 11 +++++++---- lib/cash/local.rb | 16 ++++++++++------ lib/cash/transactional.rb | 9 +++++---- spec/cash/buffered_spec.rb | 9 +++++++++ spec/cash/local_buffer_spec.rb | 9 +++++++++ spec/cash/local_spec.rb | 9 +++++++++ spec/cash/transactional_spec.rb | 4 ++++ 8 files changed, 54 insertions(+), 14 deletions(-) create mode 100644 spec/cash/buffered_spec.rb create mode 100644 spec/cash/local_buffer_spec.rb create mode 100644 spec/cash/local_spec.rb diff --git a/config/environment.rb b/config/environment.rb index 0895b1c..3b39206 100644 --- a/config/environment.rb +++ b/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' diff --git a/lib/cash/buffered.rb b/lib/cash/buffered.rb index 2c3efcd..1625246 100644 --- a/lib/cash/buffered.rb +++ b/lib/cash/buffered.rb @@ -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) @@ -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 diff --git a/lib/cash/local.rb b/lib/cash/local.rb index 2576f53..d56c2b6 100644 --- a/lib/cash/local.rb +++ b/lib/cash/local.rb @@ -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? @@ -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 @@ -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 diff --git a/lib/cash/transactional.rb b/lib/cash/transactional.rb index 2313c23..0807da2 100644 --- a/lib/cash/transactional.rb +++ b/lib/cash/transactional.rb @@ -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 diff --git a/spec/cash/buffered_spec.rb b/spec/cash/buffered_spec.rb new file mode 100644 index 0000000..6443f27 --- /dev/null +++ b/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 \ No newline at end of file diff --git a/spec/cash/local_buffer_spec.rb b/spec/cash/local_buffer_spec.rb new file mode 100644 index 0000000..d3eb9dd --- /dev/null +++ b/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 \ No newline at end of file diff --git a/spec/cash/local_spec.rb b/spec/cash/local_spec.rb new file mode 100644 index 0000000..505c746 --- /dev/null +++ b/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 \ No newline at end of file diff --git a/spec/cash/transactional_spec.rb b/spec/cash/transactional_spec.rb index 42d6c7e..1bb7ab9 100644 --- a/spec/cash/transactional_spec.rb +++ b/spec/cash/transactional_spec.rb @@ -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