cohesion 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/cohesion.gemspec +1 -0
- data/lib/cohesion.rb +59 -1
- data/lib/cohesion/railtie.rb +12 -0
- data/lib/cohesion/version.rb +1 -1
- data/lib/tasks/{check.rake → cohesion.rake} +8 -0
- metadata +17 -5
data/cohesion.gemspec
CHANGED
data/lib/cohesion.rb
CHANGED
@@ -1,10 +1,68 @@
|
|
1
1
|
require "cohesion/version"
|
2
2
|
require 'cobweb'
|
3
|
+
require 'ptools'
|
3
4
|
|
4
|
-
|
5
|
+
require 'cohesion/railtie' if defined?(Rails)
|
5
6
|
|
6
7
|
module Cohesion
|
7
8
|
class Check
|
9
|
+
|
10
|
+
def self.rails_text
|
11
|
+
root_path = Rails.root.to_s
|
12
|
+
Dir.glob("**/*").each do |filename|
|
13
|
+
unless File.directory?(filename) || File.binary?(filename) || filename.ends_with?(".rdb")
|
14
|
+
f = File.open(filename, "r")
|
15
|
+
content = f.read()
|
16
|
+
f.close
|
17
|
+
if content =~ /(https?:\/\/[a-zA-Z0-9\.\/\-_%&\?]+)/
|
18
|
+
print "Checking #{$1} "
|
19
|
+
begin
|
20
|
+
status_code = Cobweb.new(:raise_exceptions => true).head($1)[:status_code].to_i
|
21
|
+
if status_code != 200
|
22
|
+
puts " [#{status_code}] \e[31m\u2717\e[0m"
|
23
|
+
else
|
24
|
+
puts "\e[32m\u2713\e[0m"
|
25
|
+
end
|
26
|
+
rescue SocketError
|
27
|
+
status_code = 0
|
28
|
+
puts " [DNS Failed] \e[31m\u2717\e[0m"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.rails_object
|
36
|
+
root_path = Rails.root.to_s
|
37
|
+
#app_name = Rails.application.name
|
38
|
+
#puts "Checking #{app_name}..."
|
39
|
+
app = CobwebSample::Application
|
40
|
+
app.routes.default_url_options = { :host => 'xxx.com' }
|
41
|
+
|
42
|
+
Dir.glob("app/controllers/**/*").each do |filename|
|
43
|
+
controller_name = filename.gsub(".rb","").split("/")[-1].classify
|
44
|
+
unless controller_name == "ApplicationController"
|
45
|
+
puts "Processing #{controller_name}"
|
46
|
+
controller = controller_name.constantize.new
|
47
|
+
|
48
|
+
view = ActionView::Base.new(ActionController::Base.view_paths, {}, controller)
|
49
|
+
|
50
|
+
view.view_paths = ActionController::Base.view_paths
|
51
|
+
view.extend ApplicationHelper
|
52
|
+
view.controller = controller
|
53
|
+
view.class_eval do
|
54
|
+
include ApplicationHelper
|
55
|
+
include app.routes.url_helpers
|
56
|
+
end
|
57
|
+
begin
|
58
|
+
puts view.render(:template => '/tests/index.html.erb')
|
59
|
+
rescue => e
|
60
|
+
puts "Error rendering view: #{e.message}"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
8
66
|
def self.site(url)
|
9
67
|
errors = []
|
10
68
|
failures = []
|
data/lib/cohesion/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cohesion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
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:
|
12
|
+
date: 2013-01-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cobweb
|
16
|
-
requirement: &
|
16
|
+
requirement: &70231406124400 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,18 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70231406124400
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: ptools
|
27
|
+
requirement: &70231406123100 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70231406123100
|
25
36
|
description: Gem to test the cohesion of links within a rails site. The gem crawls
|
26
37
|
the site and checks that external and internal links are valid
|
27
38
|
email:
|
@@ -41,8 +52,9 @@ files:
|
|
41
52
|
- bin/cohesion
|
42
53
|
- cohesion.gemspec
|
43
54
|
- lib/cohesion.rb
|
55
|
+
- lib/cohesion/railtie.rb
|
44
56
|
- lib/cohesion/version.rb
|
45
|
-
- lib/tasks/
|
57
|
+
- lib/tasks/cohesion.rake
|
46
58
|
- script/rebuild
|
47
59
|
- spec/lib/cohesion_spec.rb
|
48
60
|
- spec/spec_helper.rb
|