cylon 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.bundle/config ADDED
@@ -0,0 +1,2 @@
1
+ ---
2
+ BUNDLE_DISABLE_SHARED_GEMS: "1"
data/.rvmrc ADDED
@@ -0,0 +1,2 @@
1
+ rvm use 1.9.2@cylon
2
+ rvm_gemset_create_on_use_flag=1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source :rubygems
2
+
3
+ group :test do
4
+ gem "rspec", '2.4.0'
5
+ gem "rack-test"
6
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,22 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.2)
5
+ rack (1.2.1)
6
+ rack-test (0.5.7)
7
+ rack (>= 1.0)
8
+ rspec (2.4.0)
9
+ rspec-core (~> 2.4.0)
10
+ rspec-expectations (~> 2.4.0)
11
+ rspec-mocks (~> 2.4.0)
12
+ rspec-core (2.4.0)
13
+ rspec-expectations (2.4.0)
14
+ diff-lcs (~> 1.1.2)
15
+ rspec-mocks (2.4.0)
16
+
17
+ PLATFORMS
18
+ ruby
19
+
20
+ DEPENDENCIES
21
+ rack-test
22
+ rspec (= 2.4.0)
data/Rakefile.rb ADDED
@@ -0,0 +1,10 @@
1
+ require "rubygems"
2
+ require "bundler/setup"
3
+
4
+ #
5
+ # The rspec tasks
6
+ #
7
+ require 'rspec/core'
8
+ require 'rspec/core/rake_task'
9
+ task :default => :spec
10
+ RSpec::Core::RakeTask.new(:spec)
data/lib/cylon.rb ADDED
@@ -0,0 +1,11 @@
1
+ require "rubygems"
2
+ require "bundler/setup"
3
+
4
+ module Cylon
5
+ autoload :Rack, 'cylon/rack'
6
+
7
+ end
8
+
9
+ if defined?(Rails::Engine)
10
+ require 'cylon/rails'
11
+ end
data/lib/cylon/rack.rb ADDED
@@ -0,0 +1,16 @@
1
+ module Cylon
2
+ class Rack
3
+
4
+ def initialize(app)
5
+ @app = app
6
+ end
7
+
8
+ def call(env)
9
+ if env["PATH_INFO"] == "/robots.txt" && RACK_ENV != "production"
10
+ [200, {"Content-Type" => "text/plain"}, ["User-Agent: *\nDisallow: /"]]
11
+ else
12
+ @app.call(env)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,4 @@
1
+ class Cylon::Rails < Rails::Engine
2
+
3
+ config.app_middleware.use Cylon::Rack
4
+ end
data/spec/rack_spec.rb ADDED
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Cylon Rack Middleware" do
4
+ include Rack::Test::Methods
5
+ let(:app) { Cylon::Rack.new(Cylon::TestingRackApp.new) }
6
+
7
+ before :each do
8
+ Object.send(:remove_const, :RACK_ENV)
9
+ RACK_ENV = "test"
10
+ end
11
+
12
+ it "should not be indexable" do
13
+ get '/robots.txt'
14
+ last_response.should be_ok
15
+ last_response.body.should eql("User-Agent: *\nDisallow: /")
16
+ end
17
+
18
+ it "should not change the content if we are not in /robots.txt" do
19
+ get '/'
20
+ last_response.body.should_not eql("User-Agent: *\nDisallow: /")
21
+ end
22
+
23
+ it "should also not match in subdirectories" do
24
+ get '/testing/robots.txt'
25
+ last_response.body.should_not eql("User-Agent: *\nDisallow: /")
26
+ end
27
+
28
+ it "should be indexable if we are in production" do
29
+ Object.send(:remove_const, :RACK_ENV)
30
+ RACK_ENV = "production"
31
+ get '/robots.txt'
32
+ last_response.should be_ok
33
+ last_response.body.should_not eql("User-Agent: *\nDisallow: /")
34
+ end
35
+ end
@@ -0,0 +1,13 @@
1
+ RACK_ENV = "test"
2
+
3
+ require 'rspec'
4
+ require 'rack/test'
5
+
6
+ require 'cylon'
7
+
8
+ class Cylon::TestingRackApp
9
+
10
+ def call(env)
11
+ [200, {"Content-Type" => "text/plain"}, ["Hello world!"]]
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cylon
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Damien Mathieu
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-01-15 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Rack middleware and Rails Engine to avoid indexing your application in staging
22
+ email: 42@dmathieu.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - .bundle/config
31
+ - .rvmrc
32
+ - Gemfile
33
+ - Gemfile.lock
34
+ - Rakefile.rb
35
+ - lib/cylon.rb
36
+ - lib/cylon/rack.rb
37
+ - lib/cylon/rails.rb
38
+ - spec/rack_spec.rb
39
+ - spec/spec_helper.rb
40
+ has_rdoc: true
41
+ homepage: http://github.com/dmathieu/cylon
42
+ licenses: []
43
+
44
+ post_install_message:
45
+ rdoc_options: []
46
+
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ segments:
55
+ - 0
56
+ version: "0"
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ requirements: []
66
+
67
+ rubyforge_project: cylon
68
+ rubygems_version: 1.3.7
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: Rack middleware and Rails Engine to avoid indexing your application in staging
72
+ test_files: []
73
+