chaingang 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,27 +14,27 @@ module ChainGang
14
14
  def from(f); @from = f; self; end
15
15
 
16
16
  # Simply improves readability. Does nothing but return self.
17
- # Article.find.where.author!("moonmaster9000").and.published!(true)
17
+ # Article.find.where.author?("moonmaster9000").and.published?(true)
18
18
  def and; self; end
19
19
 
20
20
  # Simply improves readability. Does nothing but return self.
21
- # Article.find.where.author!("moonmaster9000").and.published!(true)
21
+ # Article.find.where.author?("moonmaster9000").and.published?(true)
22
22
  def where; self; end
23
23
 
24
24
  # Suppose you have a parameter name that collides with an existing method.
25
- # Simply set it with this param! method:
26
- # Article.find(:all).param!(:from, "New York Times")
27
- def param!(name, value)
25
+ # Simply set it with this param? method:
26
+ # Article.find(:all).param?(:from, "New York Times")
27
+ def param?(name, value)
28
28
  @params[name] = value
29
29
  self
30
30
  end
31
31
 
32
32
  # Set the query string parameters on your request by calling them as methods
33
- # with an exclamation point at the end.
34
- # Article.find(:all).where.author!("moonmaster9000") #/articles.xml?author=moonmaster9000
33
+ # with a question mark at the end.
34
+ # Article.find(:all).where.author?("moonmaster9000") #/articles.xml?author=moonmaster9000
35
35
  def method_missing(method_name, *args, &block)
36
- if args.length == 1 && exclamatory?(method_name)
37
- @params[unexclaim method_name] = args.first
36
+ if args.length == 1 && question?(method_name)
37
+ @params[unquestion method_name] = args.first
38
38
  self
39
39
  else
40
40
  self.execute.send method_name, *args, &block
@@ -57,12 +57,12 @@ module ChainGang
57
57
  end
58
58
 
59
59
  # @private
60
- def exclamatory?(string) #:nodoc:
61
- string.to_s[-1..-1] == "!"
60
+ def question?(string) #:nodoc:
61
+ string.to_s[-1..-1] == "?"
62
62
  end
63
63
 
64
64
  # @private
65
- def unexclaim(string) #:nodoc:
65
+ def unquestion(string) #:nodoc:
66
66
  string.to_s[0..-2].to_sym
67
67
  end
68
68
  end
@@ -63,8 +63,8 @@ describe ChainGang do
63
63
  @proxy = Client.find
64
64
  end
65
65
 
66
- it "should set a parameter when you call a method that ends with an exclamation and has exactly one argument" do
67
- @proxy.food!("taco").send(:value, :params)[:food].should == "taco"
66
+ it "should set a parameter when you call a method that ends with a question mark and has exactly one argument" do
67
+ @proxy.food?("taco").send(:value, :params)[:food].should == "taco"
68
68
  end
69
69
 
70
70
  it "should proxy the method to the executed result otherwise" do
@@ -76,23 +76,23 @@ describe ChainGang do
76
76
  describe "#execute" do
77
77
  it "should call the #find_without_chaingang method on the original client class" do
78
78
  Client.should_receive(:find_without_chaingang).with(:all, :from => "/poo", :params => { :hi => 'hi', :yes => 'no' }).and_return([])
79
- Client.find.from("/poo").where.hi!("hi").and.yes!("no").execute
79
+ Client.find.from("/poo").where.hi?("hi").and.yes?("no").execute
80
80
  end
81
81
  end
82
82
 
83
- describe "#param!" do
83
+ describe "#param?" do
84
84
  before do
85
85
  @proxy = Client.find
86
86
  end
87
87
 
88
88
  it "should require two arguments: param name and param value" do
89
- proc { @proxy.param! }.should raise_exception
90
- proc { @proxy.param! :param_name }.should raise_exception
91
- proc { @proxy.param! :param_name, "param value" }.should_not raise_exception
89
+ proc { @proxy.param? }.should raise_exception
90
+ proc { @proxy.param? :param_name }.should raise_exception
91
+ proc { @proxy.param? :param_name, "param value" }.should_not raise_exception
92
92
  end
93
93
 
94
94
  it "should set the parameter" do
95
- @proxy.param! :param_name, "param value"
95
+ @proxy.param? :param_name, "param value"
96
96
  @proxy.send(:value, :params)[:param_name].should == "param value"
97
97
  end
98
98
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chaingang
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 0.1.0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matt Parker