noprocast 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Rob Watson
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ noprocast
2
+ =========
3
+
4
+ A gem to stop you procastinating. Noprocast automatically adds and removes items from your /etc/hosts, rendering addictive websites useless.
5
+
6
+ Installation
7
+ ------------
8
+
9
+ gem install noprocast
10
+
11
+ Usage
12
+ -----
13
+
14
+ `noprocast status` check if noprocast is enabled or not
15
+
16
+ `noprocast edit` edit noprocast's list of banned websites
17
+
18
+ `noprocast on` enable noprocast
19
+
20
+ `noprocast off` disable noprocast
21
+
22
+ Notes
23
+ -----
24
+
25
+ Noprocast saves a backup of your /etc/hosts file in /etc/.hosts.noprocastbackup the first time it runs. Just in case.
26
+
27
+ Contact
28
+ -------
29
+
30
+ rfwatson at gmail
31
+
data/Rakefile ADDED
@@ -0,0 +1,45 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "noprocast"
8
+ gem.summary = %Q{Give procastination a swift kick in the balls.}
9
+ gem.description = %Q{Block access to addictive websites in one command-line swoop.}
10
+ gem.email = "rfwatson@gmail.com"
11
+ gem.homepage = "http://github.com/rfwatson/noprocast"
12
+ gem.authors = ["Rob Watson"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'spec/rake/spectask'
22
+ Spec::Rake::SpecTask.new(:spec) do |spec|
23
+ spec.libs << 'lib' << 'spec'
24
+ spec.spec_files = FileList['spec/**/*_spec.rb']
25
+ end
26
+
27
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
28
+ spec.libs << 'lib' << 'spec'
29
+ spec.pattern = 'spec/**/*_spec.rb'
30
+ spec.rcov = true
31
+ end
32
+
33
+ task :spec => :check_dependencies
34
+
35
+ task :default => :spec
36
+
37
+ require 'rake/rdoctask'
38
+ Rake::RDocTask.new do |rdoc|
39
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
+
41
+ rdoc.rdoc_dir = 'rdoc'
42
+ rdoc.title = "noprocast #{version}"
43
+ rdoc.rdoc_files.include('README*')
44
+ rdoc.rdoc_files.include('lib/**/*.rb')
45
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
data/bin/noprocast ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib', 'noprocast')
4
+
5
+ begin
6
+ case ARGV.first
7
+ when 'on', 'reload'
8
+ Noprocast.activate!
9
+ when 'off'
10
+ Noprocast.deactivate!
11
+ when 'status'
12
+ puts Noprocast.status_message
13
+ when 'edit'
14
+ if Process.uid != File.stat(Noprocast.deny_file_path).uid
15
+ puts "Can't edit this file as it belongs to another user (hint: don't use sudo)"
16
+ exit
17
+ end
18
+ Noprocast.edit!
19
+ if Noprocast.active?
20
+ puts "Saved. Now: noprocast reload"
21
+ else
22
+ puts "Saved. Now: noprocast on"
23
+ end
24
+ when 'help', '-h', '--help', nil
25
+ puts "Usage: [sudo] noprocast [on|off|status|edit]"
26
+ end
27
+ rescue Errno::EACCES
28
+ puts "Permission denied: try sudo noprocast"
29
+ end
data/lib/noprocast.rb ADDED
@@ -0,0 +1,65 @@
1
+ require 'fileutils'
2
+
3
+ class Noprocast
4
+ class << self
5
+ def default_hosts
6
+ ['news.ycombinator.com', 'twitter.com', 'facebook.com', 'reddit.com']
7
+ end
8
+
9
+ def deny_file_path
10
+ File.expand_path("~/.noprocast")
11
+ end
12
+
13
+ def current_hosts
14
+ setup_deny_file_if_required!
15
+ File.read(deny_file_path).split(/\n/).select { |line| line.match(/[a-zA-Z0-9]/) }.map(&:strip)
16
+ end
17
+
18
+ def hosts_file_content
19
+ File.read("/etc/hosts")
20
+ end
21
+
22
+ def activate!
23
+ backup_hosts_file_if_required!
24
+ deactivate! # ensure that /etc/hosts is clean
25
+ File.open("/etc/hosts", 'a') do |file|
26
+ file << "\n\n# noprocast start\n#{current_hosts.map { |host| "127.0.0.1 #{host}" }.join("\n")}\n# noprocast end"
27
+ end
28
+ end
29
+
30
+ def deactivate!
31
+ clean_hosts = hosts_file_content.gsub(/(\n\n)?\# noprocast start.*\# noprocast end/m, '')
32
+ File.open("/etc/hosts", 'w') do |file|
33
+ file << clean_hosts
34
+ end
35
+ end
36
+
37
+ def active?
38
+ hosts_file_content.match(/\# noprocast start/)
39
+ end
40
+
41
+ def status_message
42
+ active? ? "noprocast enabled for #{current_hosts.size} hosts" : "noprocast disabled"
43
+ end
44
+
45
+ def backup_hosts_file_if_required!
46
+ unless File.exists?("/etc/.hosts.noprocastbackup")
47
+ FileUtils.cp("/etc/hosts", "/etc/.hosts.noprocastbackup")
48
+ end
49
+ end
50
+
51
+ def setup_deny_file_if_required!
52
+ unless File.exists?(deny_file_path)
53
+ File.open(deny_file_path, 'w') do |file|
54
+ file << default_hosts.join("\n")
55
+ end
56
+ end
57
+ end
58
+
59
+ def edit!
60
+ editor = ENV['EDITOR'] || 'vi'
61
+ system "#{editor} #{deny_file_path}"
62
+ end
63
+ end
64
+ end
65
+
data/noprocast.gemspec ADDED
@@ -0,0 +1,58 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{noprocast}
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Rob Watson"]
12
+ s.date = %q{2010-11-10}
13
+ s.default_executable = %q{noprocast}
14
+ s.description = %q{Block access to addictive websites in one command-line swoop.}
15
+ s.email = %q{rfwatson@gmail.com}
16
+ s.executables = ["noprocast"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.md"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ ".gitignore",
24
+ "LICENSE",
25
+ "README.md",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "bin/noprocast",
29
+ "lib/noprocast.rb",
30
+ "noprocast.gemspec",
31
+ "spec/noprocast_spec.rb",
32
+ "spec/spec.opts",
33
+ "spec/spec_helper.rb"
34
+ ]
35
+ s.homepage = %q{http://github.com/rfwatson/noprocast}
36
+ s.rdoc_options = ["--charset=UTF-8"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.3.7}
39
+ s.summary = %q{Give procastination a swift kick in the balls.}
40
+ s.test_files = [
41
+ "spec/noprocast_spec.rb",
42
+ "spec/spec_helper.rb"
43
+ ]
44
+
45
+ if s.respond_to? :specification_version then
46
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
+ s.specification_version = 3
48
+
49
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
50
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
51
+ else
52
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
53
+ end
54
+ else
55
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
56
+ end
57
+ end
58
+
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Noprocast" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'noprocast'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: noprocast
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 1
10
+ version: 0.1.1
11
+ platform: ruby
12
+ authors:
13
+ - Rob Watson
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-11-10 00:00:00 +00:00
19
+ default_executable: noprocast
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 13
30
+ segments:
31
+ - 1
32
+ - 2
33
+ - 9
34
+ version: 1.2.9
35
+ type: :development
36
+ version_requirements: *id001
37
+ description: Block access to addictive websites in one command-line swoop.
38
+ email: rfwatson@gmail.com
39
+ executables:
40
+ - noprocast
41
+ extensions: []
42
+
43
+ extra_rdoc_files:
44
+ - LICENSE
45
+ - README.md
46
+ files:
47
+ - .document
48
+ - .gitignore
49
+ - LICENSE
50
+ - README.md
51
+ - Rakefile
52
+ - VERSION
53
+ - bin/noprocast
54
+ - lib/noprocast.rb
55
+ - noprocast.gemspec
56
+ - spec/noprocast_spec.rb
57
+ - spec/spec.opts
58
+ - spec/spec_helper.rb
59
+ has_rdoc: true
60
+ homepage: http://github.com/rfwatson/noprocast
61
+ licenses: []
62
+
63
+ post_install_message:
64
+ rdoc_options:
65
+ - --charset=UTF-8
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ hash: 3
83
+ segments:
84
+ - 0
85
+ version: "0"
86
+ requirements: []
87
+
88
+ rubyforge_project:
89
+ rubygems_version: 1.3.7
90
+ signing_key:
91
+ specification_version: 3
92
+ summary: Give procastination a swift kick in the balls.
93
+ test_files:
94
+ - spec/noprocast_spec.rb
95
+ - spec/spec_helper.rb