crabfarm 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/crabfarm.rb +1 -0
- data/lib/crabfarm/base_state.rb +2 -1
- data/lib/crabfarm/cli.rb +8 -8
- data/lib/crabfarm/global_state.rb +4 -2
- data/lib/crabfarm/modes/console.rb +2 -1
- data/lib/crabfarm/modes/generator.rb +19 -10
- data/lib/crabfarm/modes/recorder.rb +1 -1
- data/lib/crabfarm/transition_service.rb +4 -4
- data/lib/crabfarm/utils/naming.rb +19 -0
- data/lib/crabfarm/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52ca9c7f98addbe26b5ff98ae502c9f0526d78dd
|
4
|
+
data.tar.gz: 8460bde2927f16b4bfb0231724b09d17da0b24dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 566ec3a924a621d53bb91b59628bf269de1794455800d7eabf9632076c970d44bd56c60a09fb0518e6aed8f7cf5a94eb4dd7cffc284da0fa4956808b8129fdcd
|
7
|
+
data.tar.gz: a52684de47189cb632e3a35cab4fd76980bc1e2021428c12344241fd266eef7984de92bcb6a1069f1422e66c6580f2cb5cd8a992ef9ae61aec600fb783687529
|
data/lib/crabfarm.rb
CHANGED
data/lib/crabfarm/base_state.rb
CHANGED
@@ -29,6 +29,7 @@ module Crabfarm
|
|
29
29
|
|
30
30
|
@dsl = Strategies.load(:browser_dsl, class_browser_dsl || Crabfarm.config.browser_dsl)
|
31
31
|
@builder = Strategies.load(:output_builder, class_output_builder || Crabfarm.config.output_builder)
|
32
|
+
@output = @builder.prepare
|
32
33
|
end
|
33
34
|
|
34
35
|
def browser(_name=nil)
|
@@ -40,7 +41,7 @@ module Crabfarm
|
|
40
41
|
end
|
41
42
|
|
42
43
|
def output
|
43
|
-
@output
|
44
|
+
@output
|
44
45
|
end
|
45
46
|
|
46
47
|
def output_as_json
|
data/lib/crabfarm/cli.rb
CHANGED
@@ -16,7 +16,7 @@ module Crabfarm
|
|
16
16
|
Support::GLI.generate_options c
|
17
17
|
|
18
18
|
c.action do |global_options,options,args|
|
19
|
-
next puts "This command can only be
|
19
|
+
next puts "This command can only be ran inside a crabfarm application" unless GlobalState.inside_crawler_app?
|
20
20
|
|
21
21
|
Crabfarm.config.set Support::GLI.parse_options options
|
22
22
|
|
@@ -50,7 +50,7 @@ module Crabfarm
|
|
50
50
|
Support::GLI.generate_options c
|
51
51
|
|
52
52
|
c.action do |global_options,options,args|
|
53
|
-
next puts "This command can only be
|
53
|
+
next puts "This command can only be ran inside a crabfarm application" unless GlobalState.inside_crawler_app?
|
54
54
|
|
55
55
|
Crabfarm.config.set Support::GLI.parse_options options
|
56
56
|
|
@@ -78,7 +78,7 @@ module Crabfarm
|
|
78
78
|
app.flag [:r, :remote]
|
79
79
|
|
80
80
|
app.action do |global_options,options,args|
|
81
|
-
next puts "This command cannot be
|
81
|
+
next puts "This command cannot be ran inside a crabfarm application" if GlobalState.inside_crawler_app?
|
82
82
|
|
83
83
|
require "crabfarm/modes/generator"
|
84
84
|
Crabfarm::Modes::Generator.generate_app(Dir.pwd, args[0], options[:remote])
|
@@ -88,7 +88,7 @@ module Crabfarm
|
|
88
88
|
c.desc "Generates a new crabfarm parser and parser spec"
|
89
89
|
c.command :parser do |parser|
|
90
90
|
parser.action do |global_options,options,args|
|
91
|
-
next puts "This command can only be
|
91
|
+
next puts "This command can only be ran inside a crabfarm application" unless GlobalState.inside_crawler_app?
|
92
92
|
|
93
93
|
require "crabfarm/modes/generator"
|
94
94
|
Crabfarm::Modes::Generator.generate_parser(GlobalState.app_path, args[0])
|
@@ -98,7 +98,7 @@ module Crabfarm
|
|
98
98
|
c.desc "Generates a new crabfarm state and parser spec"
|
99
99
|
c.command :state do |parser|
|
100
100
|
parser.action do |global_options,options,args|
|
101
|
-
next puts "This command can only be
|
101
|
+
next puts "This command can only be ran inside a crabfarm application" unless GlobalState.inside_crawler_app?
|
102
102
|
|
103
103
|
require "crabfarm/modes/generator"
|
104
104
|
Crabfarm::Modes::Generator.generate_state(GlobalState.app_path, args[0])
|
@@ -106,13 +106,13 @@ module Crabfarm
|
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
109
|
-
desc "Perform
|
109
|
+
desc "Perform a memento recording for use in tests"
|
110
110
|
command [:record, :r] do |c|
|
111
111
|
c.desc "Run recorder in playback mode"
|
112
112
|
c.switch [:p, :playback], :default_value => false
|
113
113
|
|
114
114
|
c.action do |global_options, options, args|
|
115
|
-
next puts "This command can only be
|
115
|
+
next puts "This command can only be ran inside a crabfarm application" unless GlobalState.inside_crawler_app?
|
116
116
|
|
117
117
|
require "crabfarm/modes/recorder"
|
118
118
|
Crabfarm::Modes::Recorder.start GlobalState.memento_path(args[0]), options[:playback]
|
@@ -128,7 +128,7 @@ module Crabfarm
|
|
128
128
|
c.switch :unsafe, :default_value => false
|
129
129
|
|
130
130
|
c.action do |global_options,options,args|
|
131
|
-
next puts "This command can only be
|
131
|
+
next puts "This command can only be ran inside a crabfarm application" unless GlobalState.inside_crawler_app?
|
132
132
|
|
133
133
|
options[:remote] = args[0]
|
134
134
|
|
@@ -10,11 +10,13 @@ module Crabfarm
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def memento_path(_name)
|
13
|
+
return nil if _name.nil?
|
13
14
|
File.join(app_path, 'spec/mementos', _name + '.json.gz')
|
14
15
|
end
|
15
16
|
|
16
|
-
def snapshot_path(
|
17
|
-
|
17
|
+
def snapshot_path(_file_name)
|
18
|
+
return nil if _file_name.nil?
|
19
|
+
File.join(app_path, 'spec/snapshots', _file_name)
|
18
20
|
end
|
19
21
|
|
20
22
|
extend self
|
@@ -35,21 +35,26 @@ module Crabfarm
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
def generate_state(_target,
|
39
|
-
|
38
|
+
def generate_state(_target, _class_name)
|
39
|
+
validate_class_name _class_name
|
40
|
+
|
41
|
+
route = Utils::Naming.route_from_constant _class_name
|
40
42
|
with_base_path _target do
|
41
|
-
binding = { state_class:
|
42
|
-
path('app', 'states'
|
43
|
-
path('spec', 'states'
|
43
|
+
binding = { state_class: _class_name }
|
44
|
+
path(*(['app', 'states'] + route[0...-1] + [route.last + '.rb'])).render('state.rb', binding)
|
45
|
+
path(*(['spec', 'states'] + route[0...-1] + [route.last + '_spec.rb'])).render('state_spec.rb', binding)
|
44
46
|
end
|
45
47
|
end
|
46
48
|
|
47
|
-
def generate_parser(_target,
|
48
|
-
|
49
|
+
def generate_parser(_target, _class_name)
|
50
|
+
validate_class_name _class_name
|
51
|
+
|
52
|
+
_class_name = _class_name + 'Parser'
|
53
|
+
route = Utils::Naming.route_from_constant _class_name
|
49
54
|
with_base_path _target do
|
50
|
-
binding = { parser_class:
|
51
|
-
path('app', 'parsers'
|
52
|
-
path('spec', 'parsers'
|
55
|
+
binding = { parser_class: _class_name }
|
56
|
+
path(*(['app', 'parsers'] + route[0...-1] + [route.last + '.rb'])).render('parser.rb', binding)
|
57
|
+
path(*(['spec', 'parsers'] + route[0...-1] + [route.last + '_spec.rb'])).render('parser_spec.rb', binding)
|
53
58
|
end
|
54
59
|
end
|
55
60
|
|
@@ -116,6 +121,10 @@ module Crabfarm
|
|
116
121
|
puts _op.rjust(10).color(_color) + ' ' + _message
|
117
122
|
end
|
118
123
|
|
124
|
+
def validate_class_name(_name)
|
125
|
+
raise Crabfarm::ArgumentError.new "Invalid class name '#{_name}'" unless Utils::Naming.is_constant_name? _name
|
126
|
+
end
|
127
|
+
|
119
128
|
extend self
|
120
129
|
end
|
121
130
|
end
|
@@ -26,7 +26,7 @@ module Crabfarm
|
|
26
26
|
driver = DefaultDriverFactory.new(driver_config).build_driver nil
|
27
27
|
|
28
28
|
begin
|
29
|
-
puts "Press Ctrl-C to stop capturing."
|
29
|
+
puts "Press Ctrl-C or close browser to stop #{_replay ? 'playback' : 'capturing'}."
|
30
30
|
loop do
|
31
31
|
driver.current_url
|
32
32
|
sleep 1.0
|
@@ -3,7 +3,7 @@ module Crabfarm
|
|
3
3
|
|
4
4
|
def self.apply_state(_context, _name, _params={})
|
5
5
|
state_class = if _name.is_a? String or _name.is_a? Symbol
|
6
|
-
|
6
|
+
load_class_from_uri _name
|
7
7
|
else _name end
|
8
8
|
|
9
9
|
_context.prepare
|
@@ -14,9 +14,9 @@ module Crabfarm
|
|
14
14
|
|
15
15
|
private
|
16
16
|
|
17
|
-
def self.
|
18
|
-
|
19
|
-
|
17
|
+
def self.load_class_from_uri(_uri)
|
18
|
+
class_name = Utils::Naming.decode_crabfarm_uri _uri
|
19
|
+
class_name.constantize
|
20
20
|
end
|
21
21
|
|
22
22
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Crabfarm
|
2
|
+
module Utils
|
3
|
+
module Naming
|
4
|
+
|
5
|
+
def self.is_constant_name?(_name)
|
6
|
+
/^([A-Z][A-Za-z0-9]*)(\:\:[A-Z][A-Za-z0-9]*)*$/ === _name
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.route_from_constant(_class_name)
|
10
|
+
_class_name.split('::').map(&:underscore)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.decode_crabfarm_uri(_uri)
|
14
|
+
_uri.to_s.split('/').map { |p| p.gsub(/[^A-Z0-9:]+/i, '_').camelize }.join('::')
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/crabfarm/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crabfarm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ignacio Baixas
|
@@ -433,6 +433,7 @@ files:
|
|
433
433
|
- lib/crabfarm/templates/state.rb.erb
|
434
434
|
- lib/crabfarm/templates/state_spec.rb.erb
|
435
435
|
- lib/crabfarm/transition_service.rb
|
436
|
+
- lib/crabfarm/utils/naming.rb
|
436
437
|
- lib/crabfarm/utils/port_discovery.rb
|
437
438
|
- lib/crabfarm/utils/processes.rb
|
438
439
|
- lib/crabfarm/version.rb
|