klepto 0.2.7 → 0.2.8
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +7 -0
- data/lib/klepto/structure.rb +7 -6
- data/lib/klepto/version.rb +1 -1
- data/spec/lib/klepto/bot_spec.rb +28 -0
- metadata +12 -12
data/README.md
CHANGED
@@ -179,6 +179,13 @@ end
|
|
179
179
|
|
180
180
|
|
181
181
|
## Stuff I'm going to add.
|
182
|
+
* Ensure after(:each) work at resource/collection level as well
|
183
|
+
* Add after(:all)
|
184
|
+
* :if, :unless for as: (:collection|:resource) to. context should be captured node that block is run against
|
185
|
+
* Access to hash from within a block (for bulk assignment of other attributes) ?
|
186
|
+
* :default => value|Proc should be an option
|
187
|
+
* config.allow_rescue_in_block #should exceptions in blocks be auto rescued with nil as the return value
|
188
|
+
|
182
189
|
Async
|
183
190
|
--------
|
184
191
|
-> https://github.com/igrigorik/em-synchrony
|
data/lib/klepto/structure.rb
CHANGED
@@ -40,11 +40,8 @@ module Klepto
|
|
40
40
|
result = _context.first( options[:syntax], selector )
|
41
41
|
@_hash[meth] = Structure.build(result, self, &block)
|
42
42
|
elsif block
|
43
|
-
|
44
|
-
|
45
|
-
else
|
46
|
-
result = _context
|
47
|
-
end
|
43
|
+
result = selector ?
|
44
|
+
_context.send( options[:match], options[:syntax], selector ) : _context
|
48
45
|
|
49
46
|
if options[:match] == :all
|
50
47
|
@_hash[meth] = []
|
@@ -53,7 +50,11 @@ module Klepto
|
|
53
50
|
@_hash[meth] << block.call( node )
|
54
51
|
end
|
55
52
|
else
|
56
|
-
|
53
|
+
begin
|
54
|
+
@_hash[meth] = block.call( result )
|
55
|
+
rescue Exception => ex
|
56
|
+
@_hash[meth] = nil
|
57
|
+
end
|
57
58
|
end
|
58
59
|
else
|
59
60
|
result = _context.send( options[:match], options[:syntax], selector )
|
data/lib/klepto/version.rb
CHANGED
data/spec/lib/klepto/bot_spec.rb
CHANGED
@@ -152,6 +152,7 @@ describe Klepto::Bot do
|
|
152
152
|
end
|
153
153
|
|
154
154
|
it 'should store the data' do
|
155
|
+
User.first.name.should eq( @structure.first[:name] )
|
155
156
|
User.count.should be(1)
|
156
157
|
Tweet.count.should_not be(0)
|
157
158
|
end
|
@@ -173,6 +174,33 @@ describe Klepto::Bot do
|
|
173
174
|
end
|
174
175
|
end
|
175
176
|
|
177
|
+
describe 'handling an exception within a block' do
|
178
|
+
before(:each) do
|
179
|
+
@bot = Klepto::Bot.new("https://twitter.com/justinbieber"){
|
180
|
+
name 'h1.fullname'
|
181
|
+
username "span.screen-name"
|
182
|
+
|
183
|
+
tweets 'li.stream-item', :as => :collection do
|
184
|
+
twitter_id do |node|
|
185
|
+
node['data-item-id']
|
186
|
+
end
|
187
|
+
tweet '.content p', :css
|
188
|
+
permalink '.time a', :css, :attr => :href
|
189
|
+
timestamp '._timestamp' do |node|
|
190
|
+
raise Exception
|
191
|
+
end
|
192
|
+
end
|
193
|
+
}
|
194
|
+
@structure = @bot.resources
|
195
|
+
end
|
196
|
+
|
197
|
+
it 'should set the value to nil when an exception is raised' do
|
198
|
+
@structure.first[:name].should match(/Justin/i)
|
199
|
+
@structure.first[:tweets].first.keys.should include(:timestamp)
|
200
|
+
@structure.first[:tweets].first[:timestamp].should be(nil)
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
176
204
|
|
177
205
|
describe 'creating a bot with a node limit' do
|
178
206
|
before(:each) do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: klepto
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
12
|
+
date: 2013-04-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: poltergeist
|
16
|
-
requirement: &
|
16
|
+
requirement: &70119515079920 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - =
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 1.1.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70119515079920
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: capybara
|
27
|
-
requirement: &
|
27
|
+
requirement: &70119515077020 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - =
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 2.0.2
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70119515077020
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: nokogiri
|
38
|
-
requirement: &
|
38
|
+
requirement: &70119515074920 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 1.5.6
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70119515074920
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: activesupport
|
49
|
-
requirement: &
|
49
|
+
requirement: &70119515073060 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70119515073060
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: multi_json
|
60
|
-
requirement: &
|
60
|
+
requirement: &70119515069000 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: '1.0'
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70119515069000
|
69
69
|
description: Tearing up web pages into ActiveRecord resources
|
70
70
|
email:
|
71
71
|
- github@coryodaniel.com
|