haberdasher 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - jruby-18mode # JRuby in 1.8 mode
5
+ - jruby-19mode # JRuby in 1.9 mode
6
+ - rbx-18mode
7
+ - rbx-19mode
8
+ - 1.8.7
9
+ gemfile:
10
+ - gemfiles/as235.gemfile
11
+ - gemfiles/as236.gemfile
12
+ - gemfiles/as238.gemfile
@@ -0,0 +1,11 @@
1
+ appraise "as235" do
2
+ gem "activesupport", "2.3.5"
3
+ end
4
+
5
+ appraise "as236" do
6
+ gem "activesupport", "2.3.6"
7
+ end
8
+
9
+ appraise "as238" do
10
+ gem "activesupport", "2.3.8"
11
+ end
@@ -0,0 +1,4 @@
1
+ ## Version 0.0.1
2
+
3
+ Relies on activesupport 2.3.5. Future versions will relax this requirement;
4
+ most likely, it will be listed as "~> 2.3.5" (twiddle waka) instead of "2.3.5"
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in haberdasher.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Kenrick Chien
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,68 @@
1
+ # Haberdasher
2
+
3
+ [![Dependency Status](https://gemnasium.com/kchien/haberdasher.png)](https://gemnasium.com/kchien/haberdasher)
4
+ [![Build Status](https://travis-ci.org/kchien/haberdasher.png?branch=master)](https://travis-ci.org/kchien/haberdasher)
5
+ [![Code Climate](https://codeclimate.com/github/kchien/haberdasher.png)](https://codeclimate.com/github/kchien/haberdasher)
6
+
7
+ Decorator library providing a [draper](https://github.com/drapergem/draper) style API for Rails 2.3.x apps.
8
+
9
+ ## Installation
10
+
11
+ ### Rails 2.3.x
12
+
13
+ If you're using [bundler](http://gembundler.com/), then add this line to your application's Gemfile:
14
+
15
+ gem 'haberdasher'
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ If you're not using bundler:
22
+
23
+ <pre>
24
+ # in config/environment.rb
25
+ config.gem "haberdasher"
26
+ </pre>
27
+
28
+ ## Usage
29
+
30
+ ## Writing Decorators
31
+
32
+ Similar to draper, decorators inherit from `Haberdasher::Decorator`, live in your `app/decorators`
33
+ directory, and are named for the model that they decorate:
34
+
35
+ ```ruby
36
+ # app/decorators/article_decorator.rb
37
+ class ArticleDecorator < Haberdasher::Decorator
38
+ # ...
39
+ end
40
+ ```
41
+ ## Using Decorators
42
+
43
+ ### Use `#decorate`
44
+ For the time being, explicitly `#include` the `Haberdasher::Decoratoratable` in your model:
45
+
46
+ ```ruby
47
+ # app/models/article.rb
48
+ class Article < ActiveRecord::Base
49
+ include Haberdasher::Decoratoratable
50
+ #other methods....
51
+ end
52
+ ```
53
+
54
+ ### Or use the decorator explicitly without mixing any modules in
55
+ ``` ruby
56
+ # app/controllers/articles_controller.rb
57
+ def show
58
+ @article = ArticleDecorator.new Article.find params[:id]
59
+ end
60
+ ```
61
+
62
+ ## Contributing
63
+
64
+ 1. Fork it
65
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
66
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
67
+ 4. Push to the branch (`git push origin my-new-feature`)
68
+ 5. Create new Pull Request
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ require "appraisal"
5
+
6
+ RSpec::Core::RakeTask.new
7
+ task :default => :spec
8
+ task :test => :spec
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activesupport", "2.3.5"
6
+
7
+ gemspec :path=>"../"
@@ -0,0 +1,34 @@
1
+ PATH
2
+ remote: /Users/ken/code/ruby/haberdasher
3
+ specs:
4
+ haberdasher (0.0.1)
5
+ activesupport (~> 2.3.5)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (2.3.5)
11
+ appraisal (0.5.2)
12
+ bundler
13
+ rake
14
+ diff-lcs (1.2.4)
15
+ rake (10.0.4)
16
+ rspec (2.13.0)
17
+ rspec-core (~> 2.13.0)
18
+ rspec-expectations (~> 2.13.0)
19
+ rspec-mocks (~> 2.13.0)
20
+ rspec-core (2.13.1)
21
+ rspec-expectations (2.13.0)
22
+ diff-lcs (>= 1.1.3, < 2.0)
23
+ rspec-mocks (2.13.1)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ activesupport (= 2.3.5)
30
+ appraisal
31
+ bundler (~> 1.3)
32
+ haberdasher!
33
+ rake
34
+ rspec (~> 2.13.0)
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activesupport", "2.3.6"
6
+
7
+ gemspec :path=>"../"
@@ -0,0 +1,34 @@
1
+ PATH
2
+ remote: /Users/ken/code/ruby/haberdasher
3
+ specs:
4
+ haberdasher (0.0.1)
5
+ activesupport (~> 2.3.5)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (2.3.6)
11
+ appraisal (0.5.2)
12
+ bundler
13
+ rake
14
+ diff-lcs (1.2.4)
15
+ rake (10.0.4)
16
+ rspec (2.13.0)
17
+ rspec-core (~> 2.13.0)
18
+ rspec-expectations (~> 2.13.0)
19
+ rspec-mocks (~> 2.13.0)
20
+ rspec-core (2.13.1)
21
+ rspec-expectations (2.13.0)
22
+ diff-lcs (>= 1.1.3, < 2.0)
23
+ rspec-mocks (2.13.1)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ activesupport (= 2.3.6)
30
+ appraisal
31
+ bundler (~> 1.3)
32
+ haberdasher!
33
+ rake
34
+ rspec (~> 2.13.0)
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activesupport", "2.3.8"
6
+
7
+ gemspec :path=>"../"
@@ -0,0 +1,34 @@
1
+ PATH
2
+ remote: /Users/ken/code/ruby/haberdasher
3
+ specs:
4
+ haberdasher (0.0.1)
5
+ activesupport (~> 2.3.5)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (2.3.8)
11
+ appraisal (0.5.2)
12
+ bundler
13
+ rake
14
+ diff-lcs (1.2.4)
15
+ rake (10.0.4)
16
+ rspec (2.13.0)
17
+ rspec-core (~> 2.13.0)
18
+ rspec-expectations (~> 2.13.0)
19
+ rspec-mocks (~> 2.13.0)
20
+ rspec-core (2.13.1)
21
+ rspec-expectations (2.13.0)
22
+ diff-lcs (>= 1.1.3, < 2.0)
23
+ rspec-mocks (2.13.1)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ activesupport (= 2.3.8)
30
+ appraisal
31
+ bundler (~> 1.3)
32
+ haberdasher!
33
+ rake
34
+ rspec (~> 2.13.0)
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'haberdasher/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "haberdasher"
8
+ spec.version = Haberdasher::VERSION
9
+ spec.authors = ["Kenrick Chien"]
10
+ spec.email = ["ken.chien@gmail.com"]
11
+ spec.description = %q{Decorators for your models}
12
+ spec.summary = %q{haberdasher is inspired by the excellent draper gem.
13
+ Its goal is to support legacy apps written in Rails 2.3.x, starting from
14
+ Rails 2.3.5.
15
+ }
16
+ spec.homepage = "https://github.com/kchien/haberdasher"
17
+ spec.license = "MIT"
18
+
19
+ spec.files = `git ls-files`.split($/)
20
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_runtime_dependency "activesupport", "~> 2.3.5"
25
+
26
+ spec.add_development_dependency "appraisal"
27
+ spec.add_development_dependency "bundler", "~> 1.3"
28
+ spec.add_development_dependency "rake"
29
+ spec.add_development_dependency "rspec", "~> 2.13.0"
30
+ end
@@ -0,0 +1,5 @@
1
+ require "haberdasher/version"
2
+
3
+ module Haberdasher
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,13 @@
1
+ module Haberdasher
2
+ class Decorator
3
+ attr_reader :model
4
+
5
+ def initialize model
6
+ @model = model
7
+ end
8
+
9
+ def method_missing method, *args, &block
10
+ model.send method, *args, &block
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require 'active_support'
2
+
3
+ module Haberdasher
4
+ module Decoratoratable
5
+ def decorate
6
+ decorator_class.new self
7
+ end
8
+
9
+ def decorator_class
10
+ "#{self.class}Decorator".constantize
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module Haberdasher
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+ require 'haberdasher/decorator'
3
+
4
+ class Book
5
+ attr_accessor :title
6
+ attr_accessor :author
7
+
8
+ def initialize
9
+ yield self if block_given?
10
+ end
11
+ end
12
+
13
+ class BookDecorator < Haberdasher::Decorator
14
+ def author_and_book
15
+ "#{author}: #{title}"
16
+ end
17
+ end
18
+
19
+ module Haberdasher
20
+ describe Decorator do
21
+
22
+ let(:book) {
23
+ Book.new do |b|
24
+ b.title = title
25
+ b.author = author
26
+ end
27
+ }
28
+
29
+ let(:title) { "How to Make Sushi" }
30
+ let(:author) { "John Doe" }
31
+
32
+ context "no decorator methods defined" do
33
+ let(:decorator) { described_class.new(book) }
34
+
35
+ it "delegates all methods to the wrapped object" do
36
+ decorator.title.should == title
37
+ end
38
+ end
39
+
40
+ context "decorator method composed of model's methods" do
41
+ let(:decorator) { BookDecorator.new(book) }
42
+
43
+ it "delegates the methods to the wrapped object" do
44
+ decorator.author_and_book.should == "#{author}: #{title}"
45
+ end
46
+ end
47
+
48
+ end
49
+ end
@@ -0,0 +1,35 @@
1
+ require 'haberdasher/decoratoratable'
2
+
3
+
4
+ module Haberdasher
5
+ describe Decoratoratable do
6
+
7
+ describe "mixing it into a class" do
8
+ class Apple
9
+ attr_accessor :color
10
+ end
11
+
12
+ class Cat; end
13
+ class CatDecorator < Haberdasher::Decorator; end
14
+
15
+ it "will respond to :decorate" do
16
+ expect {
17
+ Apple.send :include, Haberdasher::Decoratoratable
18
+ }\
19
+ .to change { Apple.new.respond_to? :decorate }\
20
+ .from(false)\
21
+ .to(true)
22
+ end
23
+
24
+ it "finds its decorator class by naming convention" do
25
+ Cat.send :include, Haberdasher::Decoratoratable
26
+ Cat.new.decorate.should be_a CatDecorator
27
+ end
28
+ end
29
+
30
+ describe "a class that does not mix it in and does not define :decorate" do
31
+ subject { Object.new }
32
+ it { should_not respond_to :decorate }
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,17 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+
12
+ # Run specs in random order to surface order dependencies. If you find an
13
+ # order dependency and want to debug it, you can fix the order by providing
14
+ # the seed, which is printed after each run.
15
+ # --seed 1234
16
+ config.order = 'random'
17
+ end
@@ -0,0 +1 @@
1
+
metadata ADDED
@@ -0,0 +1,154 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: haberdasher
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Kenrick Chien
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.3.5
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 2.3.5
30
+ - !ruby/object:Gem::Dependency
31
+ name: appraisal
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: bundler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '1.3'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rspec
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 2.13.0
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 2.13.0
94
+ description: Decorators for your models
95
+ email:
96
+ - ken.chien@gmail.com
97
+ executables: []
98
+ extensions: []
99
+ extra_rdoc_files: []
100
+ files:
101
+ - .gitignore
102
+ - .rspec
103
+ - .travis.yml
104
+ - Appraisals
105
+ - ChangeLog.md
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - gemfiles/as235.gemfile
111
+ - gemfiles/as235.gemfile.lock
112
+ - gemfiles/as236.gemfile
113
+ - gemfiles/as236.gemfile.lock
114
+ - gemfiles/as238.gemfile
115
+ - gemfiles/as238.gemfile.lock
116
+ - haberdasher.gemspec
117
+ - lib/haberdasher.rb
118
+ - lib/haberdasher/decorator.rb
119
+ - lib/haberdasher/decoratoratable.rb
120
+ - lib/haberdasher/version.rb
121
+ - spec/haberdasher/decorator_spec.rb
122
+ - spec/haberdasher/decoratoratable_spec.rb
123
+ - spec/spec_helper.rb
124
+ - test.txt
125
+ homepage: https://github.com/kchien/haberdasher
126
+ licenses:
127
+ - MIT
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ none: false
134
+ requirements:
135
+ - - ! '>='
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ none: false
140
+ requirements:
141
+ - - ! '>='
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ requirements: []
145
+ rubyforge_project:
146
+ rubygems_version: 1.8.23
147
+ signing_key:
148
+ specification_version: 3
149
+ summary: haberdasher is inspired by the excellent draper gem. Its goal is to support
150
+ legacy apps written in Rails 2.3.x, starting from Rails 2.3.5.
151
+ test_files:
152
+ - spec/haberdasher/decorator_spec.rb
153
+ - spec/haberdasher/decoratoratable_spec.rb
154
+ - spec/spec_helper.rb