botch 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ae74c3065a7d5ed43b4449d9925b28878fbca7a8
4
- data.tar.gz: b654385120dc79ea047deee77e4e168b3c19f9f1
3
+ metadata.gz: eff678a7305dfcfc0c931cce263e2b35448b8468
4
+ data.tar.gz: 2a6c7ac9038ec3eed13797de421741514b918ea0
5
5
  SHA512:
6
- metadata.gz: 56e97284275e453754a81af2996f00c1e3789c2007bad2c4310c07cdcf00540aa3f02f5941f7c7e57755f0ee65b27539f1c3f50606701977491a7e9e2ebc773d
7
- data.tar.gz: b6bd8dc7a7589c0aa654fad04a564fdbf107c2e1195efd4cf8fa3f3e171b6e79406a0129174d398b3f84270d376f22f25591d6878585f3192dfc730876a03c6c
6
+ metadata.gz: 6e4776acf3a3fe5023b784e2b4eaa902b469827e677c9c4aadd6752f374074d51fd115029c8bcbcd0b070681f591745e9d5b8ab690e1c7ca5505be1990b88c29
7
+ data.tar.gz: a0465a209cd8fb5199906871144d49ed593fc9de2849f9012737e0b2598ba56999988dba45beacbf270b84278c22c0a98810b74c8ce5c2028a26ab5b0a1e811e
data/README.md CHANGED
@@ -54,7 +54,6 @@ end
54
54
 
55
55
  - RSpec
56
56
  - Documentation
57
- - Classic style
58
57
 
59
58
  ## Contributing to Botch
60
59
 
@@ -18,8 +18,7 @@ module Botch
18
18
 
19
19
  def add(label, options = {}, &block)
20
20
  raise ArgumentError unless block_given?
21
- if position = index(label)
22
- route = @routes[position]
21
+ if route = exists?(label)
23
22
  route[:block] = block
24
23
  route[:label] = label
25
24
  else
@@ -34,14 +33,10 @@ module Botch
34
33
  end
35
34
 
36
35
  def exist?(label)
37
- !!index(label)
36
+ @routes.find{ |route| route[:label] == label }
38
37
  end
39
38
 
40
- alias :exists? :exist?
41
-
42
- def index(label)
43
- @routes.index{ |route| route[:label] === label }
44
- end
39
+ alias exists? exist?
45
40
 
46
41
  def inject(url)
47
42
  @routes.inject([]) do |result, route|
@@ -122,9 +117,9 @@ module Botch
122
117
  route(:rule, label, options, &block)
123
118
  end
124
119
 
125
- def generate_wrapper(&method)
126
- method.arity != 0 ? proc {|args| method.call(*args) } :
127
- proc {|args| method.call }
120
+ def generate_wrapper(&block)
121
+ block.arity != 0 ? proc {|args| block.call(*args) } :
122
+ proc {|args| block.call }
128
123
  end
129
124
 
130
125
  def generate_method(method_name, &block)
@@ -153,8 +148,7 @@ module Botch
153
148
  end
154
149
 
155
150
  def request(method, *urls, &block)
156
-
157
- set_default_options unless self.client
151
+ set_default_options unless self.client
158
152
  raise ArgumentError unless self.client.respond_to?(method)
159
153
 
160
154
  block = generate_main_block(&block) if block_given?
@@ -189,7 +183,7 @@ module Botch
189
183
  def get(*urls, &block); request(:get, *urls, &block); end
190
184
  def post(*urls, &block); request(:post, *urls, &block); end
191
185
 
192
- alias :run :get
186
+ alias run get
193
187
 
194
188
  def client=(name)
195
189
  @client = Client.const_get("#{name.to_s.capitalize}Client").new(settings) if clients.include?(name)
@@ -0,0 +1,30 @@
1
+ require 'botch'
2
+
3
+ module Botch
4
+ module Delegator
5
+ class << self
6
+ def delegate(*methods)
7
+ methods.each do |method_name|
8
+ define_method(method_name) do |*args, &block|
9
+ Delegator.target.send(method_name, *args, &block)
10
+ end
11
+ end
12
+ end
13
+
14
+ def target
15
+ @target ||= Main
16
+ end
17
+
18
+ def target=(klass)
19
+ @target = klass
20
+ end
21
+ end
22
+
23
+ delegate :filter, :get, :helpers, :options, :post, :reset,
24
+ :request, :rule, :run, :set, :settings
25
+ end
26
+
27
+ class Main < Base; end
28
+ end
29
+
30
+ extend Botch::Delegator
@@ -1,3 +1,3 @@
1
1
  module Botch
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -0,0 +1,50 @@
1
+ $:.unshift(File.dirname(__FILE__))
2
+ require 'spec_helper'
3
+ require File.expand_path("../../lib/botch/main", __FILE__)
4
+
5
+
6
+ class DelegatorTest
7
+ class Dummy
8
+ attr_reader :result
9
+
10
+ def method_missing(*args, &block)
11
+ @result = args
12
+ @result << block if block_given?
13
+ end
14
+ end
15
+
16
+ def self.delegate_test(*args)
17
+ args.each do |name|
18
+ describe "delegate #{name}" do
19
+ before(:all) { @fake = Botch::Fake.new }
20
+
21
+ it "#{name}" do
22
+ result = DelegatorTest.dummy { send(name) }.result
23
+ expect(result).to eq([name])
24
+ end
25
+
26
+ it "#{name} with arguments" do
27
+ fake = @fake
28
+ result = DelegatorTest.dummy { send(name, fake.url) }.result
29
+ expect(result).to eq([name, "http://example.com/"])
30
+ end
31
+
32
+ it "#{name} with block" do
33
+ fake, block = @fake, proc {}
34
+ result = DelegatorTest.dummy { send(name, fake.url, &block) }.result
35
+ expect(result).to eq([name, "http://example.com/", block])
36
+ end
37
+ end
38
+ end
39
+ end
40
+
41
+ def self.dummy(&block)
42
+ dummy = Dummy.new
43
+ Botch::Delegator.target = dummy
44
+ Object.new.extend(Botch::Delegator).instance_eval(&block)
45
+ Botch::Delegator.target
46
+ end
47
+
48
+ delegate_test :filter, :get, :helpers, :options, :post, :reset,
49
+ :request, :rule, :run, :set, :settings
50
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: botch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - namusyaka
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-30 00:00:00.000000000 Z
11
+ date: 2013-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -96,8 +96,10 @@ files:
96
96
  - lib/botch/clients/abstract_client.rb
97
97
  - lib/botch/clients/faraday_client.rb
98
98
  - lib/botch/clients/mechanize_client.rb
99
+ - lib/botch/main.rb
99
100
  - lib/botch/version.rb
100
101
  - spec/botch_spec.rb
102
+ - spec/delegator_spec.rb
101
103
  - spec/faraday_spec.rb
102
104
  - spec/filter_spec.rb
103
105
  - spec/mechanize_spec.rb
@@ -128,6 +130,7 @@ specification_version: 4
128
130
  summary: A DSL for web clawler.
129
131
  test_files:
130
132
  - spec/botch_spec.rb
133
+ - spec/delegator_spec.rb
131
134
  - spec/faraday_spec.rb
132
135
  - spec/filter_spec.rb
133
136
  - spec/mechanize_spec.rb