Permalink
Browse files

rearrange decorators (before, after, and first)

  • Loading branch information...
1 parent b78a1b3 commit 66a62559937dce2e504f078295b1e64581259060 @moonmaster9000 committed Apr 29, 2012
Showing with 55 additions and 2 deletions.
  1. +21 −0 lib/frill/frill.rb
  2. +2 −2 readme.markdown
  3. +32 −0 spec/frill_spec.rb
View
@@ -1,6 +1,7 @@
module Frill
def self.included(base)
self.decorators << base
+ base.extend ClassMethods
end
def self.decorators
@@ -10,4 +11,24 @@ def self.decorators
def self.reset!
@decorators = nil
end
+
+ module ClassMethods
+ def before decorator
+ move Frill.decorators.index(decorator)
+ end
+
+ def after decorator
+ decorator.before self
+ end
+
+ def first
+ move 0
+ end
+
+ private
+ def move index
+ Frill.decorators.delete self
+ Frill.decorators.insert index, self
+ end
+ end
end
View
@@ -58,7 +58,7 @@ require_relative 'timestamp_frill'
module HtmlTimestampFrill
include Frill
- decorate after: TimestampFrill
+ after TimestampFrill
def self.frill? object, context
object.respond_to?(:created_at) && context.format == "html"
@@ -118,7 +118,7 @@ possible:
```ruby
module ActionViewFrill
include Frill
- decorate before: :all
+ first
def helper
@helper ||= Object.new.extend ActionView::Helpers
View
@@ -26,4 +26,36 @@
it { should include test_module }
end
+
+ describe Frill::ClassMethods do
+ let(:module1) { Module.new { include Frill } }
+ let(:module2) { Module.new { include Frill } }
+
+ describe ".before" do
+ it "inserts the current module before the requested module in Frill's list of decorators" do
+ Frill.decorators.should == [module1, module2]
+
+ module2.before module1
+ Frill.decorators.should == [module2, module1]
+ end
+ end
+
+ describe ".after" do
+ it "inserts the current module after the requested module in Frill's list of decorators" do
+ Frill.decorators.should == [module1, module2]
+
+ module1.after module2
+ Frill.decorators.should == [module2, module1]
+ end
+ end
+
+ describe ".first" do
+ it "inserts the current module at the beginning of the list of Frill's decorators" do
+ Frill.decorators.should == [module1, module2]
+
+ module2.first
+ Frill.decorators.should == [module2, module1]
+ end
+ end
+ end
end

0 comments on commit 66a6255

Please sign in to comment.