Permalink
Browse files

Frill.decorate

  • Loading branch information...
1 parent 66a6255 commit b0782ae2dcd12b283e647c44f4868029ea77ee50 @moonmaster9000 committed Apr 29, 2012
Showing with 39 additions and 0 deletions.
  1. +6 −0 lib/frill/frill.rb
  2. +33 −0 spec/frill_spec.rb
View
@@ -12,6 +12,12 @@ def self.reset!
@decorators = nil
end
+ def self.decorate object, context
+ decorators.each do |d|
+ object.extend d if d.frill? object, context
+ end
+ end
+
module ClassMethods
def before decorator
move Frill.decorators.index(decorator)
View
@@ -17,6 +17,39 @@
end
end
+ describe ".decorate" do
+ let(:object) { double :object }
+ let(:object_context) { double :object_context }
+ let(:eigenclass) { (class << object; self; end) }
+
+ let!(:applicable_module) do
+ Module.new do
+ include Frill
+
+ def self.frill? object, context
+ true
+ end
+ end
+ end
+
+ let!(:unapplicable_module) do
+ Module.new do
+ include Frill
+
+ def self.frill? object, context
+ false
+ end
+ end
+ end
+
+ it "should decorate the object with any applicable modules" do
+ Frill.decorate object, object_context
+
+ eigenclass.included_modules.should include applicable_module
+ eigenclass.included_modules.should_not include unapplicable_module
+ end
+ end
+
describe ".included" do
let(:test_module) { double :module }

0 comments on commit b0782ae

Please sign in to comment.