fluoride-analyzer 0.0.1 → 0.0.3

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: 29f99f8f8b407486d27622bb63af1b8bd604d87f
4
- data.tar.gz: b29dacf810a25eb37374ac88532f2c09217cdd65
3
+ metadata.gz: 346f52ff1fd2fb22d297f582892ed92065498073
4
+ data.tar.gz: 5a722a444c509742fa9af7cf4aae28f34e96fe99
5
5
  SHA512:
6
- metadata.gz: f6c30d82f0adbc6051ee083d9062233bd8a632832b343647acad1c97cd7a82fbb1308a11a4959be511ba29d648c859f84dd2964ffa05c8992d34bdabd8b14c93
7
- data.tar.gz: 7c618c9bf042e2319e0ccb95a0fb00338a82a0daa4088827b0573df89748f0b7f0340f2cba3bf44051158a0ea1dbcc7bbf67869bf469ea428121b50b58a2430f
6
+ metadata.gz: 43c36586731fa31f93d4ecab90333d0e22720fd679e63bdb653186d34fb05da860a5ccae7df3d72b479cc9896df445e02e5ff46703086f4de43961001187476c
7
+ data.tar.gz: 031192dc1b4b66d5bba7b6928c22dfd568049014a459208ab773c1dd14a0d9451af627b1d35ab3a0aa0c183a5ba3513de997076e019f55c45e89cdecf65d6df0
@@ -1,11 +1,13 @@
1
1
  require 'fluoride-analyzer'
2
2
  require 'rack'
3
3
  require 'yaml'
4
+ require 'fluoride-analyzer/patterner'
5
+
4
6
  #Also: Rails and ActionDispatch::Request
5
7
 
6
8
  module Fluoride::Analyzer
7
9
  class Parser
8
- attr_accessor :files, :limit, :target_path
10
+ attr_accessor :files, :limit
9
11
  attr_reader :exceptions, :results, :counts
10
12
 
11
13
  def initialize
@@ -19,7 +21,7 @@ module Fluoride::Analyzer
19
21
  @results = Hash.new do|results, pattern| #PATH PATTERN
20
22
  results[pattern] = Hash.new do |by_method, method| #METHOD
21
23
  by_method[method] = Hash.new do |records, status| #STATUS CODE
22
- records[status] = Hash.new do |record, key| #formatted record
24
+ records[status] = Hash.new do |record, key| #formatted record
23
25
  record[key] = []
24
26
  end
25
27
  end
@@ -93,115 +95,6 @@ module Fluoride::Analyzer
93
95
  { 'post_params' => form_hash }
94
96
  end
95
97
 
96
- RoutePattern = Struct.new(:route, :matches, :params, :path_spec, :segment_keys)
97
-
98
- class Patterner
99
- def self.for(rails_routes)
100
- if rails_routes.respond_to? :recognize_path
101
- Rails4.new(rails_routes)
102
- else
103
- Rails3.new(rails_routes)
104
- end
105
- end
106
-
107
- def base_env
108
- @base_env ||= {
109
- "HTTP_REFERER" => '',
110
- "HTTP_COOKIE" => '',
111
- "HTTP_AUTHORIZATION" => '',
112
- "REQUEST_METHOD" => "GET",
113
- 'HTTP_HOST' => '',
114
- 'SERVER_NAME' => '',
115
- 'SERVER_ADDR' => '',
116
- 'SERVER_PORT' => '80',
117
- "SCRIPT_NAME" => '',
118
- "QUERY_STRING" => '',
119
- 'rack.input' => '' #body
120
- }
121
- end
122
-
123
- def initialize(rails_routes)
124
- @rails_routes = rails_routes
125
- end
126
- attr_reader :rails_routes
127
-
128
- def build_request(result_env)
129
- ActionDispatch::Request.new(base_env.merge(request_env))
130
- end
131
-
132
- def route_map
133
- @route_map ||=
134
- begin
135
- ad_routes_array = rails_routes.routes
136
- rack_routes_array = rails_routes.set.instance_eval{ @routes }
137
- Hash[ rack_routes_array.zip(ad_routes_array) ]
138
- end
139
- end
140
-
141
- def route_set
142
- @route_set ||=
143
- begin
144
- set = rails_routes.set
145
- set
146
- end
147
- end
148
-
149
- class Rails3 < Patterner
150
- def build(env)
151
- req = build_request(env)
152
- route, matches, params = route_set.recognize(req)
153
-
154
- path_spec = :unrecognized
155
- segment_keys = {}
156
-
157
- if route_map.has_key?(route)
158
- rails_route = route_map[route]
159
- path_spec = rails_route.path
160
- segment_keys = rails_route.segment_keys
161
- end
162
-
163
- RoutePattern.new(route, matches, params, path_spec, segment_keys)
164
- end
165
- end
166
-
167
- class Rails4 < Patterner
168
- def route_set
169
- @route_set ||=
170
- begin
171
- set = Rails.application.routes.router
172
- set
173
- end
174
- end
175
-
176
- def build_request(request_env)
177
- ActionDispatch::Request.new(base_env.merge(request_env))
178
- end
179
-
180
- def build(env)
181
- req = build_request(env)
182
- pattern = nil
183
- route_set.recognize(req) do |route, matches, params|
184
- rails_route = route_map[route]
185
-
186
- path_spec = :unrecognized
187
- segment_keys = {}
188
-
189
- if route_map.has_key?(route)
190
- rails_route = route_map[route]
191
- path_spec = rails_route.path.spec.to_s
192
- segment_keys = rails_route.segment_keys
193
- end
194
-
195
- pattern = RoutePattern.new(route, matches, params, path_spec, segment_keys)
196
- end
197
- if pattern.nil?
198
- pattern = RoutePattern.new(nil,nil,nil,nil,nil)
199
- end
200
- pattern
201
- end
202
- end
203
- end
204
-
205
98
  def patterner
206
99
  @patterner ||= Patterner.for(Rails.application.routes)
207
100
  end
@@ -0,0 +1,110 @@
1
+ module Fluoride::Analyzer
2
+ RoutePattern = Struct.new(:route, :matches, :params, :path_spec, :segment_keys)
3
+
4
+ class Patterner
5
+ def self.for(rails_routes)
6
+ if rails_routes.respond_to? :recognize_path
7
+ Rails4.new(rails_routes)
8
+ else
9
+ Rails3.new(rails_routes)
10
+ end
11
+ end
12
+
13
+ def base_env
14
+ @base_env ||= {
15
+ "HTTP_REFERER" => '',
16
+ "HTTP_COOKIE" => '',
17
+ "HTTP_AUTHORIZATION" => '',
18
+ "REQUEST_METHOD" => "GET",
19
+ 'HTTP_HOST' => '',
20
+ 'SERVER_NAME' => '',
21
+ 'SERVER_ADDR' => '',
22
+ 'SERVER_PORT' => '80',
23
+ "SCRIPT_NAME" => '',
24
+ "QUERY_STRING" => '',
25
+ 'rack.input' => '' #body
26
+ }
27
+ end
28
+
29
+ def initialize(rails_routes)
30
+ @rails_routes = rails_routes
31
+ end
32
+ attr_reader :rails_routes
33
+
34
+ def build_request(result_env)
35
+ ActionDispatch::Request.new(base_env.merge(request_env))
36
+ end
37
+
38
+ def route_map
39
+ @route_map ||=
40
+ begin
41
+ ad_routes_array = rails_routes.routes
42
+ rack_routes_array = rails_routes.set.instance_eval{ @routes }
43
+ Hash[ rack_routes_array.zip(ad_routes_array) ]
44
+ end
45
+ end
46
+
47
+ def route_set
48
+ @route_set ||=
49
+ begin
50
+ set = rails_routes.set
51
+ set
52
+ end
53
+ end
54
+
55
+ class Rails3 < Patterner
56
+ def build(env)
57
+ req = build_request(env)
58
+ route, matches, params = route_set.recognize(req)
59
+
60
+ path_spec = :unrecognized
61
+ segment_keys = {}
62
+
63
+ if route_map.has_key?(route)
64
+ rails_route = route_map[route]
65
+ path_spec = rails_route.path
66
+ segment_keys = rails_route.segment_keys
67
+ end
68
+
69
+ RoutePattern.new(route, matches, params, path_spec, segment_keys)
70
+ end
71
+ end
72
+
73
+ class Rails4 < Patterner
74
+ def route_set
75
+ @route_set ||=
76
+ begin
77
+ set = Rails.application.routes.router
78
+ set
79
+ end
80
+ end
81
+
82
+ def build_request(request_env)
83
+ ActionDispatch::Request.new(base_env.merge(request_env))
84
+ end
85
+
86
+ def build(env)
87
+ req = build_request(env)
88
+ pattern = nil
89
+ route_set.recognize(req) do |route, matches, params|
90
+ rails_route = route_map[route]
91
+
92
+ path_spec = :unrecognized
93
+ segment_keys = {}
94
+
95
+ if route_map.has_key?(route)
96
+ rails_route = route_map[route]
97
+ path_spec = rails_route.path.spec.to_s
98
+ segment_keys = rails_route.segment_keys
99
+ end
100
+
101
+ pattern = RoutePattern.new(route, matches, params, path_spec, segment_keys)
102
+ end
103
+ if pattern.nil?
104
+ pattern = RoutePattern.new(nil,nil,nil,nil,nil)
105
+ end
106
+ pattern
107
+ end
108
+ end
109
+ end
110
+ end
@@ -3,12 +3,31 @@ require 'fluoride-analyzer'
3
3
  module Fluoride
4
4
  module Analyzer
5
5
  class Railtie < ::Rails::Railtie
6
- #config.fluoride.directory = "fluoride-collector"
6
+ config.fluoride_path = %w{
7
+ .
8
+ ~/.config/fluoride
9
+ ~/.fluoride
10
+ }
7
11
 
8
12
  rake_tasks do
9
- # load '/path/to/task'
10
- end
13
+ require 'fluoride-analyzer/tasklib'
14
+
15
+ configs = Valise::define do
16
+ config.fluoride_path.each do |path|
17
+ ro path
18
+ end
19
+ ro(from_here("../../../default_configs"))
20
+
21
+ handle "*.yaml", :yaml, :hash_merge
22
+ handle "*.yml", :yaml, :hash_merge
23
+ end
11
24
 
25
+ analyzer_config = configs.contents("analyzer.yml")
26
+
27
+ Fluoride::Analyzer::Tasklib.new do |task|
28
+ task.from_hash(analyzer_config)
29
+ end
30
+ end
12
31
  end
13
32
  end
14
33
  end
@@ -0,0 +1,67 @@
1
+ require 'fluoride-analyzer/request-templater'
2
+ require 'mattock'
3
+
4
+ module Fluoride::Analyzer
5
+ class Tasklib < ::Mattock::Tasklib
6
+ default_namespace "fluoride:analyzer"
7
+
8
+ setting :limit, nil
9
+ dir( :fluoride, "fluoride",
10
+ path( :results, "results.yml"),
11
+ dir( :request_recordings, "recorded-requests"),
12
+ dir( :request_specs, "spec/requests"))
13
+
14
+ setting :recordings_list
15
+
16
+ def resolve_configuration
17
+ super
18
+ resolve_paths
19
+ self.recordings_list ||= FileList[ "#{request_recordings.abspath}/*.yml" ]
20
+ end
21
+
22
+ def define
23
+ in_namespace do
24
+ directory request_specs.abspath
25
+
26
+ desc "Delete and rebuild request specs based on Fluoride collections"
27
+ task :rebuild_request_specs => [:clobber_request_specs, :template_request_specs]
28
+
29
+ task :clobber_request_specs do
30
+ sh("rm -rf #{request_specs.abspath}/*")
31
+ end
32
+
33
+ file results.abspath => [:environment] + recordings_list do |task|
34
+ parser = Fluoride::Analyzer::Parser.new
35
+
36
+ recordings_list.find_all do |prereq|
37
+ next unless File.file?(prereq) && __FILE__ != prereq
38
+ parser.parse_stream(File.read(prereq))
39
+ end
40
+
41
+ parser.limit = limit
42
+
43
+ File.open(results.abspath, "w") do |target_file|
44
+ target_file.write(YAML.dump(parser.formatted_results))
45
+ end
46
+
47
+ puts "Found #{parser.formatted_results.keys.length} unique requests"
48
+ end
49
+
50
+ desc "Produce request specs that reproduce Fluoride collections"
51
+ task :template_request_specs => [request_specs.abspath, results.abspath] do
52
+ templater = Fluoride::Analyzer::RequestTemplater.new
53
+
54
+ templater.template_string = File::read(File::expand_path(
55
+ "../../../default_config/templates/request_spec.erb", __FILE__))
56
+ templater.results = YAML.load(File.read(results.abspath))
57
+ templater.go do |filename, contents|
58
+ path = File.join(request_specs.abspath, filename)
59
+ File.open(path, "w") do |spec_file|
60
+ spec_file.write(contents)
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -2,26 +2,21 @@ require "action_controller/railtie"
2
2
  require 'fluoride-analyzer/rails'
3
3
 
4
4
  describe Fluoride::Analyzer::Railtie do
5
-
6
- def config(app)
7
-
8
- end
9
-
10
- let :rails_application do
5
+ let! :rails_application do
11
6
  Class.new(::Rails::Application).tap do |app|
12
7
  app.configure do
13
8
  config.active_support.deprecation = :stderr
14
9
  config.eager_load = false
15
10
  end
16
- config(app)
17
11
  app.initialize!
18
- end
12
+ end.load_tasks
19
13
  end
20
14
 
21
15
  after :each do
22
16
  Rails.application = nil #because Rails has ideas of it's own, silly thing
23
17
  end
24
18
 
25
- it "should add rake tasks"
26
-
19
+ it "should add rake tasks" do
20
+ expect(Rake::Task["fluoride:analyzer:rebuild_request_specs"]).not_to be_nil
21
+ end
27
22
  end
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluoride-analyzer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Judson Lester
8
8
  - Evan Down
9
+ - Patricia Ho
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2014-07-10 00:00:00.000000000 Z
13
+ date: 2015-01-13 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: mattock
@@ -42,32 +43,34 @@ dependencies:
42
43
  description: |2
43
44
  Part of the Fluoride suite - tools for making your black box a bit whiter
44
45
  email:
45
- - nyarly@gmail.com
46
+ - judson@lrdesign.com
46
47
  - evan@lrdesign.com
48
+ - patricia@lrdesign.com
47
49
  executables: []
48
50
  extensions: []
49
51
  extra_rdoc_files: []
50
52
  files:
51
- - lib/fluoride-analyzer/parser.rb
52
- - lib/fluoride-analyzer/exception-result.rb
53
- - lib/fluoride-analyzer/rails/railtie.rb
54
- - lib/fluoride-analyzer/group-context.rb
53
+ - lib/fluoride-analyzer.rb
55
54
  - lib/fluoride-analyzer/config.rb
56
- - lib/fluoride-analyzer/request-templater.rb
55
+ - lib/fluoride-analyzer/exception-result.rb
56
+ - lib/fluoride-analyzer/exchange-result.rb
57
57
  - lib/fluoride-analyzer/group-collapser.rb
58
- - lib/fluoride-analyzer/rails.rb
58
+ - lib/fluoride-analyzer/group-context.rb
59
+ - lib/fluoride-analyzer/parser.rb
59
60
  - lib/fluoride-analyzer/pattern-collapser.rb
61
+ - lib/fluoride-analyzer/pattern-context.rb
62
+ - lib/fluoride-analyzer/patterner.rb
63
+ - lib/fluoride-analyzer/rails.rb
64
+ - lib/fluoride-analyzer/rails/railtie.rb
65
+ - lib/fluoride-analyzer/request-processor.rb
66
+ - lib/fluoride-analyzer/request-templater.rb
60
67
  - lib/fluoride-analyzer/request.rb
61
- - lib/fluoride-analyzer/tasks.rake
62
68
  - lib/fluoride-analyzer/result-collection.rb
63
- - lib/fluoride-analyzer/request-processor.rb
64
- - lib/fluoride-analyzer/pattern-context.rb
65
- - lib/fluoride-analyzer/exchange-result.rb
66
- - lib/fluoride-analyzer.rb
67
- - spec/result-templater.rb
69
+ - lib/fluoride-analyzer/tasklib.rb
70
+ - spec-help/gem-test-suite.rb
68
71
  - spec/railtie_spec.rb
69
72
  - spec/result-parser.rb
70
- - spec-help/gem-test-suite.rb
73
+ - spec/result-templater.rb
71
74
  homepage: http://github.com/lrdesign/fluoride-analyzer
72
75
  licenses:
73
76
  - MIT
@@ -78,7 +81,7 @@ rdoc_options:
78
81
  - --main
79
82
  - doc/README
80
83
  - --title
81
- - fluoride-analyzer-0.0.1 Documentation
84
+ - fluoride-analyzer-0.0.3 Documentation
82
85
  require_paths:
83
86
  - lib/
84
87
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -93,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
96
  version: '0'
94
97
  requirements: []
95
98
  rubyforge_project:
96
- rubygems_version: 2.0.14
99
+ rubygems_version: 2.4.1
97
100
  signing_key:
98
101
  specification_version: 4
99
102
  summary: Analysis of recorded requests
@@ -1,46 +0,0 @@
1
- require 'fluoride-analyzer/request-templater'
2
-
3
- FLUORIDE_PATH = 'fluoride-collector'
4
- LIMIT = 2000
5
-
6
- directory 'spec/requests'
7
-
8
- task :parse_fluoride => 'paths.yml'
9
-
10
- task :rebuild_request_specs => [:clobber_request_specs, :template_request_specs]
11
-
12
- task :clobber_request_specs do
13
- sh("rm -rf spec/requests/*")
14
- end
15
-
16
- file 'results.yml' => FileList[ "#{FLUORIDE_PATH}/*.yml" ] do |task|
17
- Rake::Task[:environment].invoke
18
- parser = Fluoride::Analyzer::Parser.new
19
-
20
- task.prerequisites.find_all do |prereq|
21
- next unless File.file?(prereq) && __FILE__ != prereq
22
- parser.parse_stream(File.read(prereq))
23
- end
24
-
25
- #parser.limit = LIMIT #XXX Uncomment to limit number of files parsed
26
- parser.target_path = task.name
27
-
28
- File.open(task.name, "w") do |target_file|
29
- target_file.write(YAML.dump(parser.formatted_results))
30
- end
31
-
32
- puts "Found #{parser.formatted_results.keys.length} unique requests"
33
- end
34
-
35
- task :template_request_specs => ['spec/requests', 'results.yml'] do
36
- templater = Fluoride::Analyzer::RequestTemplater.new
37
-
38
- templater.template_string = File::read(File::expand_path("../../../templates/request_spec.erb", __FILE__))
39
- templater.results = YAML.load(File.read('results.yml'))
40
- templater.go do |filename, contents|
41
- path = File.join("spec/requests", filename)
42
- File.open(path, "w") do |spec_file|
43
- spec_file.write(contents)
44
- end
45
- end
46
- end