decent_decoration 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ notifications:
6
+ email:
7
+ recipients:
8
+ - pewniak747@gmail.com
9
+ - bartosz.kopinski@netguru.pl
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # decent_decoration
2
+ [![Build Status](https://secure.travis-ci.org/netguru/decent_decoration.png?branch=master)](http://travis-ci.org/netguru/decent_decoration)
2
3
 
3
4
  decent_decoration allows you to use excellent [decent_exposure][decent_exposure] gem with decorators.
4
5
 
data/Rakefile CHANGED
@@ -1 +1,5 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ RSpec::Core::RakeTask.new(:spec)
4
+
5
+ task :default => :spec
@@ -21,4 +21,5 @@ Gem::Specification.new do |gem|
21
21
  gem.add_development_dependency 'rspec-rails', '~> 2.7'
22
22
  gem.add_development_dependency 'actionpack', '~> 3.1'
23
23
  gem.add_development_dependency 'activesupport', '~> 3.1'
24
+ gem.add_development_dependency 'draper', '>= 1.0.0'
24
25
  end
@@ -1,14 +1,21 @@
1
1
  module DecentDecoration
2
2
  module Decorate
3
3
  def expose_decorated(name, options = {}, &block)
4
- decorator_class = options.delete(:decorator) || "#{name.to_s.singularize.classify}Decorator".constantize
5
- decorated_name = name.to_sym
6
- undecorated_name = "undecorated_#{name}".to_sym
4
+ options[:model] ||= name
5
+ original_name = name.to_s
6
+ plural_name = original_name.pluralize
7
+ singular_name = original_name.singularize
8
+ decorator_class = options.delete(:decorator) || "#{options[:model].to_s.classify}Decorator".constantize
9
+
10
+ if plural_name == original_name && plural_name != singular_name && decorator_class.respond_to?(:decorate_collection)
11
+ decorate_method = :decorate_collection
12
+ else
13
+ decorate_method = decorator_class.respond_to?(:decorate) ? :decorate : :new
14
+ end
7
15
 
8
- options[:model] ||= decorated_name
9
- decorate_method = decorator_class.respond_to?(:decorate) ? :decorate : :new
16
+ undecorated_name = "undecorated_#{name}".to_sym
10
17
  expose(undecorated_name, options, &block)
11
- expose(decorated_name) { decorator_class.public_send(decorate_method, public_send(undecorated_name)) }
18
+ expose(name) { decorator_class.public_send(decorate_method, public_send(undecorated_name)) }
12
19
  end
13
20
  end
14
21
  end
@@ -1,3 +1,3 @@
1
1
  module DecentDecoration
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -1,24 +1,23 @@
1
- require 'fixtures/fake_rails_application'
1
+ class ConferencesController < ActionController::Base
2
+ include Rails.application.routes.url_helpers
2
3
 
3
- class Conference
4
- attr_accessor :name, :location
5
- extend ActiveModel::Naming
6
- def initialize(attrs={})
7
- self.attributes = attrs
8
- end
9
- def self.find(id)
10
- new if id
4
+ expose_decorated(:conference)
5
+ expose_decorated(:other_conference, model: Conference, decorator: CoolConferenceDecorator)
6
+
7
+ def show
8
+ render :text => "foo"
11
9
  end
12
- def attributes=(attributes)
13
- attributes.each { |k,v| send("#{k}=", v) }
10
+
11
+ def new
12
+ render :text => "foo"
14
13
  end
15
14
  end
16
15
 
17
- class ConferencesController < ActionController::Base
16
+ class AttendeesController < ActionController::Base
18
17
  include Rails.application.routes.url_helpers
19
18
 
20
- expose_decorated(:conference)
21
- expose_decorated(:other_conference, model: Conference, decorator: CoolConferenceDecorator)
19
+ expose_decorated(:attendee)
20
+ expose_decorated(:attendees) { [Attendee.new, Attendee.new] }
22
21
 
23
22
  def show
24
23
  render :text => "foo"
@@ -1,4 +1,5 @@
1
1
  require 'delegate'
2
+ require 'draper'
2
3
 
3
4
  class ConferenceDecorator < SimpleDelegator
4
5
  def decorated_object
@@ -8,3 +9,13 @@ end
8
9
 
9
10
  class CoolConferenceDecorator < ConferenceDecorator
10
11
  end
12
+
13
+ class AttendeeDecorator < Draper::Decorator
14
+ def full_name
15
+ "#{first_name} #{last_name}"
16
+ end
17
+
18
+ def self.find(id)
19
+ Attendee.find(id)
20
+ end
21
+ end
@@ -16,6 +16,8 @@ module Rails
16
16
  @routes.draw do
17
17
  get '/conferences/new' => "conferences#new"
18
18
  get '/conference/(:id)' => "conferences#show"
19
+ get '/attendees/new' => "attendees#new"
20
+ get '/attendee/(:id)' => "attendees#show"
19
21
  end
20
22
  @routes
21
23
  end
@@ -27,3 +29,7 @@ module Rails
27
29
  @app ||= App.new
28
30
  end
29
31
  end
32
+
33
+ require 'fixtures/models'
34
+ require 'fixtures/decorators'
35
+ require 'fixtures/controllers'
@@ -0,0 +1,31 @@
1
+ module Model
2
+ extend ActiveModel::Naming
3
+
4
+ def initialize(attrs={})
5
+ self.attributes = attrs
6
+ end
7
+
8
+ def attributes=(attributes)
9
+ attributes.each { |k,v| send("#{k}=", v) }
10
+ end
11
+
12
+ def self.included(klass)
13
+ def klass.find(id)
14
+ new if id
15
+ end
16
+
17
+ def klass.scoped
18
+ self
19
+ end
20
+ end
21
+ end
22
+
23
+ class Conference
24
+ include Model
25
+ attr_accessor :name, :location
26
+ end
27
+
28
+ class Attendee
29
+ include Model
30
+ attr_accessor :first_name, :last_name
31
+ end
@@ -0,0 +1,16 @@
1
+ require 'fixtures/fake_rails_application'
2
+ require 'rspec/rails'
3
+
4
+ describe AttendeesController, type: :controller do
5
+ it "should be a decorator" do
6
+ get '/attendee/dave'
7
+ controller.attendee.should be_instance_of(AttendeeDecorator)
8
+ end
9
+
10
+ it "should be a decorator in collection" do
11
+ get '/attendee/dave'
12
+ controller.attendees.each do |attendee|
13
+ attendee.should be_instance_of(AttendeeDecorator)
14
+ end
15
+ end
16
+ end
@@ -1,5 +1,4 @@
1
- require 'fixtures/decorators'
2
- require 'fixtures/controllers'
1
+ require 'fixtures/fake_rails_application'
3
2
  require 'rspec/rails'
4
3
 
5
4
  describe ConferencesController, type: :controller do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: decent_decoration
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-28 00:00:00.000000000 Z
12
+ date: 2013-02-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: decent_exposure
@@ -91,6 +91,22 @@ dependencies:
91
91
  - - ~>
92
92
  - !ruby/object:Gem::Version
93
93
  version: '3.1'
94
+ - !ruby/object:Gem::Dependency
95
+ name: draper
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: 1.0.0
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: 1.0.0
94
110
  description: Use decent_exposure with decorators (e.g. Draper)
95
111
  email:
96
112
  - pewniak747@gmail.com
@@ -99,6 +115,7 @@ extensions: []
99
115
  extra_rdoc_files: []
100
116
  files:
101
117
  - .gitignore
118
+ - .travis.yml
102
119
  - Gemfile
103
120
  - LICENSE.txt
104
121
  - README.md
@@ -110,6 +127,8 @@ files:
110
127
  - spec/fixtures/controllers.rb
111
128
  - spec/fixtures/decorators.rb
112
129
  - spec/fixtures/fake_rails_application.rb
130
+ - spec/fixtures/models.rb
131
+ - spec/integration/draper_spec.rb
113
132
  - spec/integration/rails_application_spec.rb
114
133
  homepage: https://github.com/netguru/decent_decoration
115
134
  licenses: []
@@ -131,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
150
  version: '0'
132
151
  requirements: []
133
152
  rubyforge_project:
134
- rubygems_version: 1.8.24
153
+ rubygems_version: 1.8.23
135
154
  signing_key:
136
155
  specification_version: 3
137
156
  summary: Use decent_exposure with decorators (e.g. Draper)
@@ -139,5 +158,6 @@ test_files:
139
158
  - spec/fixtures/controllers.rb
140
159
  - spec/fixtures/decorators.rb
141
160
  - spec/fixtures/fake_rails_application.rb
161
+ - spec/fixtures/models.rb
162
+ - spec/integration/draper_spec.rb
142
163
  - spec/integration/rails_application_spec.rb
143
- has_rdoc: