Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Remove plugins, Toy.clear and Toy.reset.

With AS::Concern, plugins are pretty easy without some built in way of
doing it. Just make a module and include it.
  • Loading branch information...
commit 642d7c0f4fe06500cac878648caa83d871a7b993 1 parent c02fa41
@jnunemaker authored
View
22 lib/toy.rb
@@ -17,27 +17,6 @@
module Toy
extend self
- # Resets all tracking of things in memory. Useful for running
- # before each request in development mode with Rails and such.
- def reset
- IdentityMap.clear
- plugins.clear
- models.clear
- end
-
- # Clears all the adapters for all the models. Useful in specs/tests/etc.
- # Do not use in production, harty harr harr.
- #
- # Note: that if your models are auto-loaded like in Rails, you will need
- # to make sure they are loaded in order to clear them or ToyStore will
- # not be aware of their existence.
- def clear
- models.each do |model|
- model.adapter.clear
- end
- IdentityMap.clear
- end
-
def logger
@logger
end
@@ -98,7 +77,6 @@ module Identity
require 'toy/identity_map'
require 'toy/exceptions'
-require 'toy/plugins'
require 'toy/object'
require 'toy/store'
View
32 lib/toy/plugins.rb
@@ -1,32 +0,0 @@
-module Toy
- def models
- Toy::Store.direct_descendants
- end
-
- def plugins
- Toy::Store.plugins
- end
-
- def plugin(mod)
- Toy::Store.plugin(mod)
- end
-
- module Plugins
- include ActiveSupport::DescendantsTracker
-
- def plugins
- @plugins ||= []
- end
-
- def plugin(mod)
- include(mod)
- direct_descendants.each {|model| model.send(:include, mod) }
- plugins << mod
- end
-
- def included(base=nil, &block)
- direct_descendants << base if base
- super
- end
- end
-end
View
1  lib/toy/store.rb
@@ -1,7 +1,6 @@
module Toy
module Store
extend ActiveSupport::Concern
- extend Plugins
include Toy::Object
include Persistence
View
2  spec/helper.rb
@@ -36,8 +36,6 @@
c.before(:each) do
Toy::IdentityMap.enabled = false
- Toy.clear
- Toy.reset
Toy.key_factory = nil
end
end
View
48 spec/toy/plugins_spec.rb
@@ -1,48 +0,0 @@
-require 'helper'
-
-describe Toy::Plugins do
- uses_constants('User', 'Game')
-
- it "keeps track of class that include toy store" do
- Toy.models.should == [User, Game]
- end
-
- describe ".plugin" do
- before do
- @mod = Module.new {
- extend ActiveSupport::Concern
-
- def bar
- 'bar'
- end
- }
-
- class_methods_module = Module.new do
- def foo
- 'foo'
- end
- end
-
- @mod.const_set :ClassMethods, class_methods_module
-
- Toy.plugin(@mod)
- end
-
- it "includes module in all models" do
- [User, Game].each do |model|
- model.foo.should == 'foo'
- model.new.bar.should == 'bar'
- end
- end
-
- it "adds plugin to plugins" do
- Toy.plugins.should == [@mod]
- end
-
- it "adds plugins to classes declared after plugin was called" do
- klass = ToyStore()
- klass.foo.should == 'foo'
- klass.new.bar.should == 'bar'
- end
- end
-end
View
17 spec/toy_spec.rb
@@ -3,21 +3,6 @@
describe Toy do
uses_constants('User', 'Game')
- describe ".clear" do
- it "can clear all the adapters in one magical moment" do
- user = User.create!
- game = Game.create!
- Toy.clear
- User.get(user.id).should be_nil
- Game.get(game.id).should be_nil
- end
-
- it "does not raise error when no default adapter set" do
- klass = Class.new { include Toy::Store }
- lambda { Toy.clear }.should_not raise_error
- end
- end
-
describe ".logger" do
before do
@logger = Toy.logger
@@ -46,4 +31,4 @@
Toy.key_factory.should be_instance_of(Toy::Identity::UUIDKeyFactory)
end
end
-end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.