Skip to content

Commit

Permalink
Merge pull request #299 from haines/renaming
Browse files Browse the repository at this point in the history
Renaming
  • Loading branch information
steveklabnik committed Oct 10, 2012
2 parents 16140fe + d06afda commit 02add97
Show file tree
Hide file tree
Showing 28 changed files with 92 additions and 92 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
6 changes: 3 additions & 3 deletions lib/draper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
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/decoratable'
require 'draper/helper_support'
require 'draper/view_context'
require 'draper/decorated_enumerable_proxy'
require 'draper/collection_decorator'
require 'draper/railtie' if defined?(Rails)

# Test 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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'active_support/core_ext/object/blank'
module Draper
class DecoratedEnumerableProxy
class CollectionDecorator
include Enumerable

delegate :as_json, :collect, :map, :each, :[], :all?, :include?, :first, :last, :shift, :in_groups_of, :to => :decorated_collection
Expand Down Expand Up @@ -61,7 +61,7 @@ def ==(other)
end

def to_s
"#<DecoratedEnumerableProxy of #{@klass} for #{@wrapped_collection.inspect}>"
"#<CollectionDecorator of #{@klass} for #{@wrapped_collection.inspect}>"
end

def context=(input)
Expand Down
2 changes: 1 addition & 1 deletion lib/draper/model_support.rb → lib/draper/decoratable.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Draper::ModelSupport
module Draper::Decoratable
extend ActiveSupport::Concern

def decorator(options = {})
Expand Down
12 changes: 6 additions & 6 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 Expand Up @@ -49,7 +49,7 @@ def self.find(input, options = {})
def self.decorates(input, options = {})
self.model_class = options[:class] || options[:class_name] || input.to_s.camelize
self.model_class = model_class.constantize if model_class.respond_to?(:constantize)
model_class.send :include, Draper::ModelSupport
model_class.send :include, Draper::Decoratable
define_method(input){ @model }
end

Expand Down Expand Up @@ -149,7 +149,7 @@ def self.decorate(input, options = {})
input.options = options unless options.empty?
return input
elsif input.respond_to?(:each) && !input.is_a?(Struct) && (!defined?(Sequel) || !input.is_a?(Sequel::Model))
Draper::DecoratedEnumerableProxy.new(input, self, options)
Draper::CollectionDecorator.new(input, self, options)
elsif options[:infer]
input.decorator(options)
else
Expand All @@ -160,9 +160,9 @@ def self.decorate(input, options = {})
# Fetch all instances of the decorated class and decorate them.
#
# @param [Hash] options (optional)
# @return [Draper::DecoratedEnumerableProxy]
# @return [Draper::CollectionDecorator]
def self.all(options = {})
Draper::DecoratedEnumerableProxy.new(model_class.all, self, options)
Draper::CollectionDecorator.new(model_class.all, self, options)
end

def self.first(options = {})
Expand Down
2 changes: 1 addition & 1 deletion lib/draper/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Railtie < Rails::Railtie

initializer "draper.extend_active_record_base" do |app|
ActiveSupport.on_load(:active_record) do
self.send(:include, Draper::ModelSupport)
self.send(:include, Draper::Decoratable)
end
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Draper::DecoratedEnumerableProxy do
describe Draper::CollectionDecorator do
before(:each){ ApplicationController.new.view_context }
subject{ ProductsDecorator.new(source, ProductDecorator) }
let(:source){ Product.new }
Expand Down
Loading

0 comments on commit 02add97

Please sign in to comment.