pebbles-productivity10x-switch_hosts 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm 1.9.3
data/.travis.yml ADDED
@@ -0,0 +1 @@
1
+ rvm: 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pebbles-productivity10x-switch_hosts.gemspec
4
+ gemspec
5
+
6
+ gem "rake"
7
+ gem "rspec"
8
+ gem "thor"
9
+
10
+ gem "guard", :require => false
11
+ gem "guard-rspec", :require => false
12
+ gem "ruby_gntp", :require => false
data/Guardfile ADDED
@@ -0,0 +1,24 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec' do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+
9
+ # Rails example
10
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
13
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
14
+ watch('config/routes.rb') { "spec/routing" }
15
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
16
+
17
+ # Capybara request specs
18
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
19
+
20
+ # Turnip features and steps
21
+ watch(%r{^spec/acceptance/(.+)\.feature$})
22
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
23
+ end
24
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 niku
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # Pebbles::Productivity10x::SwitchHosts
2
+
3
+ For up productivity 10x, deny needless host at work.
4
+
5
+ ## Installation
6
+
7
+ $ gem install pebbles-productivity10x-switch_hosts
8
+
9
+ ## Usage
10
+
11
+ execute as Administrator
12
+
13
+ $ pebbles-productivity10x-switch_hosts deny
14
+
15
+ or use sudo (because this script copies `hosts` file)
16
+
17
+ $ sudo pebbles-productivity10x-switch_hosts deny
18
+
19
+ and re-open your browser, access twitter.com
20
+
21
+ If you back to free access,
22
+
23
+ $ pebbles-productivity10x-switch_hosts allow
24
+
25
+ and re-open your browser.
26
+
27
+ ## Contributing
28
+
29
+ 1. Fork it
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require "rspec/core/rake_task"
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task :default => :spec
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'cli'
4
+
5
+ Pebbles::Productivity10x::CLI.start(ARGV)
data/lib/cli.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'thor'
2
+ require 'pebbles-productivity10x-switch_hosts'
3
+
4
+ module Pebbles
5
+ module Productivity10x
6
+ class CLI < Thor
7
+ desc 'allow limited host', ''
8
+ def allow
9
+ SwitchHosts.new.allow
10
+ end
11
+
12
+ desc 'deny limited host', ''
13
+ def deny
14
+ SwitchHosts.new.deny
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,77 @@
1
+ require "pebbles-productivity10x-switch_hosts/version"
2
+
3
+ require 'erb'
4
+ require 'fileutils'
5
+
6
+ module Pebbles
7
+ module Productivity10x
8
+ class SwitchHosts
9
+ module Default
10
+ HOSTS_PATH = if /windows/i =~ ENV['OS']
11
+ require 'win32/resolv'
12
+ Win32::Resolv.get_hosts_path
13
+ else
14
+ require 'resolv'
15
+ Resolv::Hosts::DefaultFileName
16
+ end
17
+ ORIGINAL_EXTNAME = '.original'
18
+ DENY_EXTNAME = '.deny'
19
+ TEMPLATE = ERB.new(<<__EOS__)
20
+ 127.0.0.1 <%= host %> # added by #{File.basename(__FILE__)}
21
+ __EOS__
22
+ DENY_HOSTS = %w(
23
+ twitter.com
24
+ api.twitter.com
25
+ facebook.com
26
+ ja-jp.facebook.com
27
+ www.facebook.com
28
+ slashdot.jp
29
+ )
30
+ end
31
+
32
+ def initialize opt = {}
33
+ @hosts_path = opt[:hosts_path] || Default::HOSTS_PATH
34
+ @original_extname = opt[:original_extname] || Default::ORIGINAL_EXTNAME
35
+ @deny_extname = opt[:deny_extname] || Default::DENY_EXTNAME
36
+ @template = opt[:template] || Default::TEMPLATE
37
+ end
38
+
39
+ def deny
40
+ use(deny_file)
41
+ end
42
+
43
+ def allow
44
+ use(original_file)
45
+ end
46
+
47
+ def hosts_file
48
+ File.new(@hosts_path)
49
+ end
50
+
51
+ def original_file
52
+ original_path = @hosts_path + @original_extname
53
+ unless File.exist?(original_path)
54
+ FileUtils.cp(hosts_file, original_path, preserve: true)
55
+ end
56
+ File.new original_path
57
+ end
58
+
59
+ def deny_file
60
+ deny_path = @hosts_path + @deny_extname
61
+ unless File.exist?(deny_path)
62
+ FileUtils.cp original_file, deny_path, preserve: true
63
+ File.open(deny_path, 'a') do |f|
64
+ f << "\n"
65
+ f << Default::DENY_HOSTS.map { |host| @template.result(binding) }.join
66
+ end
67
+ end
68
+ File.new deny_path
69
+ end
70
+
71
+ private
72
+ def use(source_file)
73
+ FileUtils.cp(source_file, hosts_file, preserve: true)
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,7 @@
1
+ module Pebbles
2
+ module Productivity10x
3
+ class SwitchHosts
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pebbles-productivity10x-switch_hosts/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "pebbles-productivity10x-switch_hosts"
8
+ gem.version = Pebbles::Productivity10x::SwitchHosts::VERSION
9
+ gem.authors = ["niku"]
10
+ gem.email = ["niku@niku.name"]
11
+ gem.description = %q{Write a gem description}
12
+ gem.summary = %q{Write a gem summary}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
@@ -0,0 +1,9 @@
1
+ require "spec_helper"
2
+
3
+ module Pebbles
4
+ module Productivity10x
5
+ describe SwitchHosts do
6
+ it{ fail "not implement yet." }
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,18 @@
1
+ require "pebbles-productivity10x-switch_hosts"
2
+ # This file was generated by the `rspec --init` command. Conventionally, all
3
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
4
+ # Require this file using `require "spec_helper"` to ensure that it is only
5
+ # loaded once.
6
+ #
7
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
8
+ RSpec.configure do |config|
9
+ config.treat_symbols_as_metadata_keys_with_true_values = true
10
+ config.run_all_when_everything_filtered = true
11
+ config.filter_run :focus
12
+
13
+ # Run specs in random order to surface order dependencies. If you find an
14
+ # order dependency and want to debug it, you can fix the order by providing
15
+ # the seed, which is printed after each run.
16
+ # --seed 1234
17
+ config.order = 'random'
18
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pebbles-productivity10x-switch_hosts
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - niku
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-04 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Write a gem description
15
+ email:
16
+ - niku@niku.name
17
+ executables:
18
+ - pebbles-productivity10x-switch_hosts
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - .gitignore
23
+ - .rspec
24
+ - .rvmrc
25
+ - .travis.yml
26
+ - Gemfile
27
+ - Guardfile
28
+ - LICENSE.txt
29
+ - README.md
30
+ - Rakefile
31
+ - bin/pebbles-productivity10x-switch_hosts
32
+ - lib/cli.rb
33
+ - lib/pebbles-productivity10x-switch_hosts.rb
34
+ - lib/pebbles-productivity10x-switch_hosts/version.rb
35
+ - pebbles-productivity10x-switch_hosts.gemspec
36
+ - spec/pebbles-productivity10x-switch_host_spec.rb
37
+ - spec/spec_helper.rb
38
+ homepage: ''
39
+ licenses: []
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubyforge_project:
58
+ rubygems_version: 1.8.23
59
+ signing_key:
60
+ specification_version: 3
61
+ summary: Write a gem summary
62
+ test_files:
63
+ - spec/pebbles-productivity10x-switch_host_spec.rb
64
+ - spec/spec_helper.rb