commonthread-fluffy 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,6 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
6
+ *.gem
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Ben Wyrosdick
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.rdoc ADDED
@@ -0,0 +1,7 @@
1
+ = fluffy
2
+
3
+ Description goes here.
4
+
5
+ == Copyright
6
+
7
+ Copyright (c) 2009 Ben Wyrosdick. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,64 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "fluffy"
8
+ gem.summary = %Q{TODO}
9
+ gem.email = "ben.wyrosdick@gmail.com"
10
+ gem.homepage = "http://github.com/commonthread/fluffy"
11
+ gem.authors = ["Ben Wyrosdick"]
12
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
13
+ end
14
+
15
+ rescue LoadError
16
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
17
+ end
18
+
19
+ require 'rake/testtask'
20
+ Rake::TestTask.new(:test) do |test|
21
+ test.libs << 'lib' << 'test'
22
+ test.pattern = 'test/**/*_test.rb'
23
+ test.verbose = true
24
+ end
25
+
26
+ begin
27
+ require 'rcov/rcovtask'
28
+ Rcov::RcovTask.new do |test|
29
+ test.libs << 'test'
30
+ test.pattern = 'test/**/*_test.rb'
31
+ test.verbose = true
32
+ end
33
+ rescue LoadError
34
+ task :rcov do
35
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
36
+ end
37
+ end
38
+
39
+ begin
40
+ require 'cucumber/rake/task'
41
+ Cucumber::Rake::Task.new(:features)
42
+ rescue LoadError
43
+ task :features do
44
+ abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
45
+ end
46
+ end
47
+
48
+ task :default => :test
49
+
50
+ require 'rake/rdoctask'
51
+ Rake::RDocTask.new do |rdoc|
52
+ if File.exist?('VERSION.yml')
53
+ config = YAML.load(File.read('VERSION.yml'))
54
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
55
+ else
56
+ version = ""
57
+ end
58
+
59
+ rdoc.rdoc_dir = 'rdoc'
60
+ rdoc.title = "fluffy #{version}"
61
+ rdoc.rdoc_files.include('README*')
62
+ rdoc.rdoc_files.include('lib/**/*.rb')
63
+ end
64
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.2
@@ -0,0 +1,9 @@
1
+ Feature: something something
2
+ In order to something something
3
+ A user something something
4
+ something something something
5
+
6
+ Scenario: something something
7
+ Given inspiration
8
+ When I create a sweet new gem
9
+ Then everyone should see how awesome I am
File without changes
@@ -0,0 +1,6 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
2
+ require 'fluffy'
3
+
4
+ require 'test/unit/assertions'
5
+
6
+ World(Test::Unit::Assertions)
data/fluffy.gemspec ADDED
@@ -0,0 +1,51 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{fluffy}
5
+ s.version = "0.0.2"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Ben Wyrosdick"]
9
+ s.date = %q{2009-07-17}
10
+ s.email = %q{ben.wyrosdick@gmail.com}
11
+ s.extra_rdoc_files = [
12
+ "LICENSE",
13
+ "README.rdoc"
14
+ ]
15
+ s.files = [
16
+ ".document",
17
+ ".gitignore",
18
+ "LICENSE",
19
+ "README.rdoc",
20
+ "Rakefile",
21
+ "VERSION",
22
+ "features/fluffy.feature",
23
+ "features/step_definitions/fluffy_steps.rb",
24
+ "features/support/env.rb",
25
+ "fluffy.gemspec",
26
+ "lib/fluffy.rb",
27
+ "lib/fluffy/s3_io.rb",
28
+ "lib/fluffy/s3_path.rb",
29
+ "test/fluffy_test.rb",
30
+ "test/test_helper.rb"
31
+ ]
32
+ s.homepage = %q{http://github.com/commonthread/fluffy}
33
+ s.rdoc_options = ["--charset=UTF-8"]
34
+ s.require_paths = ["lib"]
35
+ s.rubygems_version = %q{1.3.4}
36
+ s.summary = %q{Transparently write to S3 as if writing to the FS}
37
+ s.test_files = [
38
+ "test/fluffy_test.rb",
39
+ "test/test_helper.rb"
40
+ ]
41
+
42
+ if s.respond_to? :specification_version then
43
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
44
+ s.specification_version = 3
45
+
46
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
47
+ else
48
+ end
49
+ else
50
+ end
51
+ end
@@ -0,0 +1,101 @@
1
+ module Fluffy
2
+ class S3Io < IO
3
+ attr_accessor :s3_path, :s3, :bucket, :key, :data, :mode, :pos
4
+ attr_reader :read_mode, :write_mode
5
+
6
+ def initialize(s3_path, key, mode)
7
+ self.s3_path = s3_path
8
+ self.key = self.s3_path.bucket.key(File.join(s3_path.start_path, key).gsub(/^\W/, ''))
9
+ self.data = self.key.data || ''
10
+ self.mode = mode
11
+
12
+ case self.mode.gsub(/b/, '') # We ignore the binary flag at this time
13
+ when 'r', 'r+'
14
+ self.pos = 0
15
+ @read_mode = true
16
+ @write_mode = !!(self.mode =~ /\+/)
17
+ when 'w', 'w+'
18
+ self.data = ''
19
+ self.pos = 0
20
+ @read_mode = !!(self.mode =~ /\+/)
21
+ @write_mode = true
22
+ when 'a', 'a+'
23
+ self.pos = self.data.length
24
+ @read_mode = !!(self.mode =~ /\+/)
25
+ @write_mode = true
26
+ end
27
+ end
28
+
29
+ def eof
30
+ eof?
31
+ end
32
+
33
+ def eof?
34
+ self.pos >= self.data.length
35
+ end
36
+
37
+ def each(&block)
38
+ until self.eof?
39
+ yield(self.gets)
40
+ end
41
+ end
42
+
43
+ def each_line(&block)
44
+ self.each(block)
45
+ end
46
+
47
+ def read(length = nil)
48
+ if length
49
+ return nil if self.eof?
50
+ data = self.data[self.pos, length]
51
+ self.pos += length
52
+ else
53
+ data = self.data[self.pos .. -1]
54
+ self.pos = self.data.length
55
+ end
56
+
57
+ return data
58
+ end
59
+
60
+ def print(string = nil)
61
+ string ||= $_
62
+ string << $\ if $\
63
+ self.data[self.pos, string.length] = string
64
+ self.pos += string.length
65
+ return nil
66
+ end
67
+
68
+ def puts(*strings)
69
+ strings.each do |string|
70
+ string << "\n" unless string =~ /\n$/
71
+ self.print(string)
72
+ end
73
+ self.flush
74
+ return nil
75
+ end
76
+
77
+ def readline
78
+ self.gets
79
+ end
80
+
81
+ def readlines
82
+ return self.data.split("\n")
83
+ end
84
+
85
+ def gets(sep_string = "\n")
86
+ sep_string = "\n\n" if sep_string == ''
87
+
88
+ end_pos = self.data.index(sep_string, self.pos) || self.data.length
89
+
90
+ $_ = self.read(end_pos - self.pos + 1)
91
+ end
92
+
93
+ def close
94
+ flush
95
+ end
96
+
97
+ def flush
98
+ self.key.put(self.data)
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,14 @@
1
+ module Fluffy
2
+ class S3Path
3
+ attr_accessor :file_path, :access_key_id, :secret_access_key, :bucket, :start_path, :s3
4
+
5
+ def initialize(file_path, access_key_id, secret_access_key, bucket, start_path = '')
6
+ self.file_path = file_path
7
+ self.access_key_id = access_key_id
8
+ self.secret_access_key = secret_access_key
9
+ self.s3 = RightAws::S3.new(self.access_key_id, self.secret_access_key)
10
+ self.bucket = self.s3.bucket(bucket)
11
+ self.start_path = start_path
12
+ end
13
+ end
14
+ end
data/lib/fluffy.rb ADDED
@@ -0,0 +1,110 @@
1
+ require File.join(File.dirname(__FILE__), 'fluffy/s3_path')
2
+ require File.join(File.dirname(__FILE__), 'fluffy/s3_io')
3
+
4
+ require 'right_aws'
5
+
6
+ File.instance_eval do
7
+ @@s3_paths = []
8
+
9
+ def register_s3(file_path, access_key_id, secret_access_key, bucket, start_path = '')
10
+ File.s3_paths << Fluffy::S3Path.new(File.expand_path(file_path), access_key_id, secret_access_key, bucket, start_path)
11
+ end
12
+
13
+ def s3_paths
14
+ return @@s3_paths
15
+ end
16
+
17
+ alias :original_open :open
18
+
19
+ def open(filename, mode = 'r', &block)
20
+ Fluffy.cloud_runner(:open, filename) do |s3_path, key|
21
+ s3io = Fluffy::S3Io.new(s3_path, key, mode)
22
+
23
+ if block_given?
24
+ yield(s3io)
25
+ s3io.close
26
+ end
27
+
28
+ return s3io
29
+ end
30
+ end
31
+
32
+ alias :original_exists? :exists?
33
+
34
+ def exists?(filename)
35
+ Fluffy.cloud_runner(:exists?, filename) do |s3_path, key|
36
+ s3_path.bucket.key(key).exists?
37
+ end
38
+ end
39
+
40
+ def exist?(filename)
41
+ exists?(filename)
42
+ end
43
+
44
+ def file?(filename)
45
+ exists?(filename)
46
+ end
47
+
48
+ alias :original_unlink :unlink
49
+
50
+ def unlink(*filepaths)
51
+ filepaths.each do |filename|
52
+ Fluffy.cloud_runner(:unlink, filename) do |s3_path, key|
53
+ s3_path.bucket.key(key).delete
54
+ end
55
+ end
56
+ end
57
+ end
58
+
59
+ Dir.instance_eval do
60
+ alias :original_unlink :unlink
61
+
62
+ def unlink(dirpath)
63
+ Fluffy.cloud_runner(:unlink, dirpath) do |s3_path, key|
64
+ s3_path.bucket.key(key).delete
65
+ end
66
+ end
67
+
68
+ def rmdir(dirpath)
69
+ unlink(dirpath)
70
+ end
71
+
72
+ def delete(dirpath)
73
+ unlink(dirpath)
74
+ end
75
+ end
76
+
77
+ module Fluffy
78
+ def self.cloud_runner(method_name, filename, &block)
79
+ expanded_filename = File.expand_path(filename)
80
+ if s3_path = File.s3_paths.find {|path| expanded_filename =~ /^#{path.file_path}/}
81
+ starting_position = s3_path.file_path.length + 1
82
+ raise 'You must specify a key' unless expanded_filename.length > starting_position
83
+ key = expanded_filename[starting_position .. -1]
84
+ yield(s3_path, key)
85
+ else
86
+ self.send("original_#{method_name}", filename)
87
+ end
88
+ end
89
+ end
90
+
91
+ ## File
92
+ #
93
+ # lchmod
94
+ # lchown
95
+ # lstat
96
+ # chmod
97
+ # chown
98
+ # stat
99
+ # utime
100
+ # directory?
101
+ # rename
102
+ # unlink
103
+ # symlink
104
+
105
+ ## Dir
106
+ #
107
+ # []
108
+ # mkdir
109
+ # entries
110
+ # glob
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class FluffyTest < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'fluffy'
8
+
9
+ class Test::Unit::TestCase
10
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: commonthread-fluffy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Ben Wyrosdick
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-07-17 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: ben.wyrosdick@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.rdoc
25
+ files:
26
+ - .document
27
+ - .gitignore
28
+ - LICENSE
29
+ - README.rdoc
30
+ - Rakefile
31
+ - VERSION
32
+ - features/fluffy.feature
33
+ - features/step_definitions/fluffy_steps.rb
34
+ - features/support/env.rb
35
+ - fluffy.gemspec
36
+ - lib/fluffy.rb
37
+ - lib/fluffy/s3_io.rb
38
+ - lib/fluffy/s3_path.rb
39
+ - test/fluffy_test.rb
40
+ - test/test_helper.rb
41
+ has_rdoc: false
42
+ homepage: http://github.com/commonthread/fluffy
43
+ post_install_message:
44
+ rdoc_options:
45
+ - --charset=UTF-8
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: "0"
53
+ version:
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ version:
60
+ requirements: []
61
+
62
+ rubyforge_project:
63
+ rubygems_version: 1.2.0
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: Transparently write to S3 as if writing to the FS
67
+ test_files:
68
+ - test/fluffy_test.rb
69
+ - test/test_helper.rb