fuckery 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,8 @@
1
+ Copyright (c) 2011 Josh Cheek and Jim Suchy
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8
+
@@ -0,0 +1,28 @@
1
+ Fuckery
2
+ -------
3
+
4
+ When I want to play with some idea or try something out quickly,
5
+ lets say in Sinatra, I go to my deleteme folder and create a new
6
+ project named sinatra-fuckery. The problem is that some of these
7
+ are worth hanging onto, at least for a little while, but they get
8
+ lost in all the folders there. Fuckery would be a gem that manages
9
+ these projects for you. Examples of things you could do
10
+
11
+ Current features
12
+ ----------------
13
+
14
+ $ fuckery new example # create a dir in ~/.fuckery named "example" unless overridden with env var FUCKERY_HOME
15
+ $ fuckery list # lists the fuckeries you've made
16
+ $ fuckery delete example # get rid of it forever
17
+
18
+ Future features
19
+ ---------------
20
+
21
+ `fuckery new example` might cd you into there.
22
+
23
+ $ fuckery new example --template rspec # same, but create a basic skeleton like Bones or Hoe or Jeweler (though not gem oriented)
24
+ $ fuckery list --archived # lists the fuckeries you've archived
25
+ $ fuckery archive example # move example from active fuckeries list to archived list (ie keep it, but don't show it to me all the time)
26
+ $ fuckery unarchive example # move example from archived to active
27
+ $ fuckery export example # copy the fuckery out of its segregated area and drop it in the current dir (like `gem unpack`)
28
+
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $: << File.expand_path('../../lib', __FILE__)
4
+
5
+ require 'fuckery'
6
+
7
+ begin
8
+ command = Fuckery.command_for ARGV
9
+ command.execute
10
+ rescue Exception => e
11
+ $stderr.puts e.message
12
+ exit 1
13
+ end
@@ -0,0 +1,32 @@
1
+ require 'fileutils'
2
+ require 'fuckery/commands/archive'
3
+ require 'fuckery/commands/new'
4
+ require 'fuckery/commands/list'
5
+ require 'fuckery/commands/delete'
6
+
7
+ module Fuckery
8
+ UnsupportedCommandError = Class.new StandardError
9
+ AlreadyExistsError = Class.new StandardError
10
+ DoesNotExistError = Class.new StandardError
11
+
12
+ def self.command_for(argv)
13
+ command_name = argv.shift
14
+ klass = Commands.const_get command_name.capitalize
15
+ klass.new(*argv)
16
+ rescue NameError => e
17
+ raise UnsupportedCommandError.new("#{command_name.inspect} is not a known command")
18
+ end
19
+
20
+ def self.fuckeries_directory
21
+ ENV['FUCKERY_HOME'] || default_directory
22
+ end
23
+
24
+ def self.fuckery_directory(name)
25
+ "#{fuckeries_directory}/#{name}"
26
+ end
27
+
28
+ def self.default_directory
29
+ "#{ENV['HOME']}/.fuckery"
30
+ end
31
+
32
+ end
@@ -0,0 +1,6 @@
1
+ module Fuckery
2
+ module Commands
3
+ class Archive
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,27 @@
1
+ module Fuckery
2
+ module Commands
3
+ class Delete
4
+ attr_reader :name
5
+
6
+ def initialize(name)
7
+ @name = name
8
+ end
9
+
10
+ def execute
11
+ if directory_exists?
12
+ FileUtils.rm_rf directory
13
+ else
14
+ raise DoesNotExistError.new("#{name.inspect} is not currently a fuckery (check your spelling)")
15
+ end
16
+ end
17
+
18
+ def directory_exists?
19
+ Dir.exists? directory
20
+ end
21
+
22
+ def directory
23
+ Fuckery.fuckery_directory(name)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,13 @@
1
+ module Fuckery
2
+ module Commands
3
+ class List
4
+ def fuckeries
5
+ Dir.entries(Fuckery.fuckeries_directory) - [".", ".."]
6
+ end
7
+
8
+ def execute(stdout=$stdout)
9
+ fuckeries.each {|fuckery| stdout.puts fuckery}
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,18 @@
1
+ module Fuckery
2
+ module Commands
3
+ class New
4
+ attr_accessor :name
5
+
6
+ def initialize(name)
7
+ self.name = name
8
+ end
9
+
10
+ def execute
11
+ dir_name = Fuckery.fuckery_directory(name)
12
+ raise Fuckery::AlreadyExistsError.new("Fuckery already exists at #{dir_name}") if Dir.exists?(dir_name)
13
+ FileUtils.mkdir_p dir_name
14
+ end
15
+
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,27 @@
1
+ require 'fuckery'
2
+ require 'fakefs/safe'
3
+
4
+ module Fuckery
5
+ module Commands
6
+ describe Delete do
7
+ context 'when the fuckery exists' do
8
+ it 'deletes the fuckery from the dir' do
9
+ FakeFS do
10
+ FileUtils.mkdir_p Fuckery.fuckery_directory('example')
11
+
12
+ Delete.new('example').execute
13
+
14
+ Dir.should_not exist Fuckery.fuckery_directory('example')
15
+ end
16
+ end
17
+ end
18
+
19
+ context 'when the fuckery does not exist' do
20
+ it 'raises a DoesNotExistError' do
21
+ -> { Delete.new("doesnotexist").execute }.should raise_error(DoesNotExistError, /\bdoesnotexist\b/)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+
@@ -0,0 +1,43 @@
1
+ require 'stringio'
2
+ require 'set'
3
+ require 'fuckery'
4
+ require 'fakefs/safe'
5
+
6
+ class FakeIO < StringIO
7
+ def to_s
8
+ rewind
9
+ read
10
+ end
11
+ end
12
+
13
+ module Fuckery::Commands
14
+ describe List do
15
+
16
+ def fake_stdout
17
+ @fake_stdout ||= FakeIO.new
18
+ end
19
+
20
+ before do
21
+ FakeFS::FileSystem.clear
22
+ FakeFS do
23
+ New.new('foo').execute
24
+ New.new('bar').execute
25
+ end
26
+ end
27
+
28
+ it 'knows which directories are active' do
29
+ FakeFS do
30
+ fuckeries = Set[*List.new.fuckeries]
31
+ fuckeries.should == Set['foo', 'bar']
32
+ end
33
+ end
34
+
35
+ it 'lists the fuckeries in the fuckeries_directory' do
36
+ FakeFS { List.new.execute fake_stdout }
37
+ fake_stdout.to_s.should match /\bfoo\b/
38
+ fake_stdout.to_s.should match /\bbar\b/
39
+ end
40
+
41
+ it 'lists nothing if the fuckeries dir is not initialized'
42
+ end
43
+ end
@@ -0,0 +1,37 @@
1
+ require 'fuckery'
2
+ require 'fakefs/safe'
3
+
4
+ module Fuckery::Commands
5
+ describe New do
6
+ before { FakeFS::FileSystem.clear }
7
+
8
+ it 'raises an error when the fuckery already exists' do
9
+ FakeFS do
10
+ FileUtils.mkdir_p Fuckery.fuckery_directory('example')
11
+ -> { New.new('example').execute }.should raise_error Fuckery::AlreadyExistsError
12
+ end
13
+ end
14
+
15
+ context 'when the FUCKERY_HOME env var IS set' do
16
+ it 'creates the directory if it does not exist' do
17
+ FakeFS do
18
+ ENV['FUCKERY_HOME'] = "/path/to/fuckery"
19
+ New.new('example').execute
20
+
21
+ File.should be_directory "/path/to/fuckery/example"
22
+ File.should_not be_directory "#{Fuckery.default_directory}/example"
23
+ end
24
+ end
25
+ end
26
+
27
+ context 'when the FUCKERY_HOME env var IS NOT set' do
28
+ it 'creates the .fuckery home directory unless an environment variable is set' do
29
+ FakeFS do
30
+ ENV.delete 'FUCKERY_HOME'
31
+ New.new('example').execute
32
+ File.should be_directory "#{Fuckery.default_directory}/example"
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,26 @@
1
+ require 'fuckery'
2
+
3
+ describe 'fuckery' do
4
+
5
+ describe 'command_for' do
6
+ it "contructs Lists" do
7
+ command = Fuckery.command_for %w[list]
8
+ command.should be_an_instance_of Fuckery::Commands::List
9
+ end
10
+
11
+ it 'constructs the Archives' do
12
+ command = Fuckery.command_for %w[archive]
13
+ command.should be_an_instance_of Fuckery::Commands::Archive
14
+ end
15
+
16
+ it 'constructs News' do
17
+ command = Fuckery.command_for %w[new example]
18
+ command.should be_an_instance_of Fuckery::Commands::New
19
+ command.name.should == 'example'
20
+ end
21
+
22
+ it "raises UnsupportedCommand exception" do
23
+ -> { Fuckery.command_for %w[neverwillbesupported] }.should raise_error Fuckery::UnsupportedCommandError
24
+ end
25
+ end
26
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fuckery
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Josh Cheek
9
+ - Jim Suchy
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2011-10-14 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: fakefs
17
+ requirement: &70361774237040 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: 0.4.0
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: *70361774237040
26
+ description:
27
+ email: josh.cheek@gmail.com
28
+ executables:
29
+ - fuckery
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - MIT-License.txt
34
+ - Readme.md
35
+ - bin/fuckery
36
+ - spec/commands/delete_spec.rb
37
+ - spec/commands/list_spec.rb
38
+ - spec/commands/new_spec.rb
39
+ - spec/fuckery_spec.rb
40
+ - lib/fuckery/commands/archive.rb
41
+ - lib/fuckery/commands/delete.rb
42
+ - lib/fuckery/commands/list.rb
43
+ - lib/fuckery/commands/new.rb
44
+ - lib/fuckery.rb
45
+ homepage:
46
+ licenses: []
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubyforge_project:
65
+ rubygems_version: 1.8.10
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: Sandbox for throwaway code.
69
+ test_files: []