Skip to content

Commit

Permalink
Rename Base to Decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
haines committed Oct 9, 2012
1 parent 16140fe commit 025742c
Show file tree
Hide file tree
Showing 19 changed files with 64 additions and 64 deletions.
16 changes: 8 additions & 8 deletions Readme.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
If you need common methods in your decorators, create an `app/decorators/application_decorator.rb`:

``` ruby
class ApplicationDecorator < Draper::Base
class ApplicationDecorator < Draper::Decorator
# your methods go here
end
```
Expand All @@ -45,7 +45,7 @@ Why hate normal helpers? In Ruby/Rails we approach everything from an Object-Ori
A decorator wraps an object with presentation-related accessor methods. For instance, if you had an `Article` object, then the decorator could override `.published_at` to use formatted output like this:

```ruby
class ArticleDecorator < Draper::Base
class ArticleDecorator < Draper::Decorator
decorates :article

def published_at
Expand Down Expand Up @@ -149,7 +149,7 @@ rails generate decorator article
Open the decorator model (ex: `app/decorators/article_decorator.rb`) and add normal instance methods. To access the wrapped source object, use a method named after the `decorates` argument:

```ruby
class ArticleDecorator < Draper::Base
class ArticleDecorator < Draper::Decorator
decorates :article

def author_name
Expand All @@ -163,7 +163,7 @@ end
You probably want to make use of Rails helpers and those defined in your application. Use the `helpers` or `h` method proxy:

```ruby
class ArticleDecorator < Draper::Base
class ArticleDecorator < Draper::Decorator
decorates :article

def published_at
Expand All @@ -179,7 +179,7 @@ end
Hate seeing that `h.` proxy all over? Willing to mix a bazillion methods into your decorator? Then try lazy helpers:

```ruby
class ArticleDecorator < Draper::Base
class ArticleDecorator < Draper::Decorator
decorates :article
include Draper::LazyHelpers

Expand Down Expand Up @@ -298,7 +298,7 @@ Then within your views you can utilize both the normal data methods and your new
Ta-da! Object-oriented data formatting for your view layer. Below is the complete decorator with extra comments removed:
```ruby
class ArticleDecorator < Draper::Base
class ArticleDecorator < Draper::Decorator
decorates :article
def published_at
Expand All @@ -314,12 +314,12 @@ end
Add a `decorates_association :association_name` to gain access to a decorated version of your target association.

```ruby
class ArticleDecorator < Draper::Base
class ArticleDecorator < Draper::Decorator
decorates :article
decorates_association :author # belongs_to :author association
end

class AuthorDecorator < Draper::Base
class AuthorDecorator < Draper::Decorator
decorates :author

def fancy_name
Expand Down
2 changes: 1 addition & 1 deletion lib/draper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require 'draper/version'
require 'draper/system'
require 'draper/active_model_support'
require 'draper/base'
require 'draper/decorator'
require 'draper/lazy_helpers'
require 'draper/model_support'
require 'draper/helper_support'
Expand Down
2 changes: 1 addition & 1 deletion lib/draper/active_model_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def self.extended(base)
proxies.each do |method_name|
if base.model.respond_to?(method_name)
base.singleton_class.class_eval do
if !base.class.instance_methods.include?(method_name) || base.class.instance_method(method_name).owner === Draper::Base
if !base.class.instance_methods.include?(method_name) || base.class.instance_method(method_name).owner === Draper::Decorator
define_method(method_name) do |*args, &block|
model.send(method_name, *args, &block)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/draper/base.rb → lib/draper/decorator.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Draper
class Base
class Decorator
require 'active_support/core_ext/class/attribute'
require 'active_support/core_ext/array/extract_options'

Expand All @@ -20,7 +20,7 @@ class Base
def initialize(input, options = {})
input.to_a if input.respond_to?(:to_a) # forces evaluation of a lazy query from AR
self.class.model_class = input.class if model_class.nil?
@model = input.kind_of?(Draper::Base) ? input.model : input
@model = input.kind_of?(Draper::Decorator) ? input.model : input
self.options = options
self.extend Draper::ActiveModelSupport::Proxies
end
Expand Down
2 changes: 1 addition & 1 deletion lib/draper/test/minitest_integration.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class MiniTest::Rails::ActiveSupport::TestCase
# Use AS::TestCase for the base class when describing a decorator
register_spec_type(self) do |desc|
desc < Draper::Base if desc.is_a?(Class)
desc < Draper::Decorator if desc.is_a?(Class)
end
register_spec_type(/Decorator( ?Test)?\z/i, self)
end
2 changes: 1 addition & 1 deletion lib/generators/decorator/decorator_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def parent_class_name
elsif defined?(ApplicationDecorator)
"ApplicationDecorator"
else
"Draper::Base"
"Draper::Decorator"
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions performance/decorators.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require "./performance/models"
class ProductDecorator < Draper::Base
class ProductDecorator < Draper::Decorator
decorates :product

def awesome_title
Expand All @@ -21,7 +21,7 @@ def method_missing(method, *args, &block)

end

class FastProductDecorator < Draper::Base
class FastProductDecorator < Draper::Decorator
decorates :product

def awesome_title
Expand Down
Loading

0 comments on commit 025742c

Please sign in to comment.