-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7f32e5e
commit 7232183
Showing
8 changed files
with
184 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# A sample Gemfile | ||
source :gemcutter | ||
# | ||
gem "rails", ">= 3.0.0" | ||
|
||
group :test do | ||
gem "rspec-rails", ">= 2.0.0.beta.19" | ||
gem "rcov" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
GEM | ||
remote: http://rubygems.org/ | ||
specs: | ||
abstract (1.0.0) | ||
actionmailer (3.0.0) | ||
actionpack (= 3.0.0) | ||
mail (~> 2.2.5) | ||
actionpack (3.0.0) | ||
activemodel (= 3.0.0) | ||
activesupport (= 3.0.0) | ||
builder (~> 2.1.2) | ||
erubis (~> 2.6.6) | ||
i18n (~> 0.4.1) | ||
rack (~> 1.2.1) | ||
rack-mount (~> 0.6.12) | ||
rack-test (~> 0.5.4) | ||
tzinfo (~> 0.3.23) | ||
activemodel (3.0.0) | ||
activesupport (= 3.0.0) | ||
builder (~> 2.1.2) | ||
i18n (~> 0.4.1) | ||
activerecord (3.0.0) | ||
activemodel (= 3.0.0) | ||
activesupport (= 3.0.0) | ||
arel (~> 1.0.0) | ||
tzinfo (~> 0.3.23) | ||
activeresource (3.0.0) | ||
activemodel (= 3.0.0) | ||
activesupport (= 3.0.0) | ||
activesupport (3.0.0) | ||
arel (1.0.1) | ||
activesupport (~> 3.0.0) | ||
builder (2.1.2) | ||
diff-lcs (1.1.2) | ||
erubis (2.6.6) | ||
abstract (>= 1.0.0) | ||
i18n (0.4.1) | ||
mail (2.2.5) | ||
activesupport (>= 2.3.6) | ||
mime-types | ||
treetop (>= 1.4.5) | ||
mime-types (1.16) | ||
nokogiri (1.4.3.1) | ||
polyglot (0.3.1) | ||
rack (1.2.1) | ||
rack-mount (0.6.13) | ||
rack (>= 1.0.0) | ||
rack-test (0.5.6) | ||
rack (>= 1.0) | ||
rails (3.0.0) | ||
actionmailer (= 3.0.0) | ||
actionpack (= 3.0.0) | ||
activerecord (= 3.0.0) | ||
activeresource (= 3.0.0) | ||
activesupport (= 3.0.0) | ||
bundler (~> 1.0.0) | ||
railties (= 3.0.0) | ||
railties (3.0.0) | ||
actionpack (= 3.0.0) | ||
activesupport (= 3.0.0) | ||
rake (>= 0.8.4) | ||
thor (~> 0.14.0) | ||
rake (0.8.7) | ||
rcov (0.9.8) | ||
rspec (2.0.0.beta.19) | ||
rspec-core (= 2.0.0.beta.19) | ||
rspec-expectations (= 2.0.0.beta.19) | ||
rspec-mocks (= 2.0.0.beta.19) | ||
rspec-core (2.0.0.beta.19) | ||
rspec-expectations (2.0.0.beta.19) | ||
diff-lcs (>= 1.1.2) | ||
rspec-mocks (2.0.0.beta.19) | ||
rspec-rails (2.0.0.beta.19) | ||
rspec (= 2.0.0.beta.19) | ||
webrat (>= 0.7.2.beta.1) | ||
thor (0.14.0) | ||
treetop (1.4.8) | ||
polyglot (>= 0.3.1) | ||
tzinfo (0.3.23) | ||
webrat (0.7.2.beta.1) | ||
nokogiri (>= 1.2.0) | ||
rack (>= 1.0) | ||
rack-test (>= 0.5.3) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
rails (>= 3.0.0) | ||
rcov | ||
rspec-rails (>= 2.0.0.beta.19) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require 'action_controller' | ||
|
||
module Respondie | ||
|
||
def use_trait(&block) | ||
Respondie::Builder.new("Respondie::Trait::$trait$", self).instance_eval(&block) | ||
end | ||
|
||
alias_method :use_traits, :use_trait | ||
|
||
end | ||
|
||
ActionController::Base.extend Respondie | ||
|
||
require 'respondie/builder' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class Respondie::Builder | ||
|
||
def initialize(pattern, controller) | ||
@pattern = pattern | ||
custom = Class.new(ActionController::Responder) | ||
controller.responder = custom | ||
@responder = controller.responder | ||
end | ||
|
||
def method_missing(sym) | ||
trait sym | ||
end | ||
|
||
private | ||
|
||
def trait(sym) | ||
type = @pattern.gsub(/\$trait\$/, sym.to_s.camelize) | ||
@responder.send :include, type.constantize | ||
self | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') | ||
|
||
class ProductsController | ||
attr_accessor :responder | ||
end | ||
module Respondie | ||
module Trait | ||
module Cute | ||
def is_cute? | ||
true | ||
end | ||
end | ||
end | ||
end | ||
|
||
describe Respondie::Builder do | ||
|
||
it "should include a type into a responder" do | ||
controller = ProductsController.new | ||
Respondie::Builder.new("Respondie::Trait::$trait$", controller).instance_eval { cute } | ||
controller.responder.instance_method(:is_cute?).should_not be_nil | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,19 @@ | ||
require File.expand_path(File.dirname(__FILE__) + '/spec_helper') | ||
|
||
describe "Respondie" do | ||
it "fails" do | ||
fail "hey buddy, you should probably rename this file and start specing for real" | ||
class ApplicationController < ActionController::Base | ||
end | ||
|
||
class MyController < ApplicationController | ||
end | ||
|
||
describe Respondie do | ||
|
||
it "should enhance ActionController with its cute method" do | ||
MyController.should respond_to(:use_trait) | ||
end | ||
|
||
it "should enhance ActionController with its cute plural method" do | ||
MyController.should respond_to(:use_traits) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,5 @@ | ||
$LOAD_PATH.unshift(File.dirname(__FILE__)) | ||
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) | ||
require 'respondie' | ||
require 'spec' | ||
require 'spec/autorun' | ||
|
||
Spec::Runner.configure do |config| | ||
|
||
end | ||
require 'rspec' | ||
require 'rspec/autorun' |