vidibus-tempfile 0.0.0

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
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source :rubygems
2
+
3
+ # Add dependencies to develop your gem here.
4
+ # Include everything needed to run rake, tests, features, etc.
5
+ group :development do
6
+ gem "bundler", "~> 1.0.0"
7
+ gem "jeweler", "~> 1.5.1"
8
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,16 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.5.1)
6
+ bundler (~> 1.0.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ rake (0.8.7)
10
+
11
+ PLATFORMS
12
+ ruby
13
+
14
+ DEPENDENCIES
15
+ bundler (~> 1.0.0)
16
+ jeweler (~> 1.5.1)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Andre Pankratz
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,56 @@
1
+ = vidibus-tempfile
2
+
3
+ The extended Temfile class allows temporary files with correct mime type and file extension. This is useful for processing temporary files. Parts of the Tempfile extensions were copied from Paperclip. Thank you!
4
+
5
+ This gem is part of the open source SOA framework Vidibus: http://vidibus.org
6
+
7
+
8
+ == Installation
9
+
10
+ Add the dependency to the Gemfile of your application:
11
+
12
+ gem "vidibus-tempfile"
13
+
14
+ Then call `bundle install` on your console.
15
+
16
+
17
+ == Usage
18
+
19
+ This is an example for extracting image stills from a video through a Tempfile:
20
+
21
+ # Extract video still using FFmpeg
22
+ def extract_image(video, seconds = 10)
23
+ basename = File.basename(video).gsub(/\.\w+$/,'')
24
+ tmpfile = Vidibus::Tempfile.new("#{basename}.jpg")
25
+ tmpfile.binmode
26
+ cmd = %(ffmpeg -itsoffset -#{seconds} -i "#{video}" -y -vcodec mjpeg -qscale 1 -vframes 1 -an -f rawvideo #{File.expand_path(tmpfile.path)} 2>/dev/null)
27
+ `#{cmd}`
28
+ tmp
29
+ end
30
+
31
+ The next example shows how to assign an image by setting its path:
32
+
33
+ class Image
34
+ include Mongoid::Document
35
+ include Paperclip
36
+
37
+ field :image_file_name
38
+ field :image_content_type
39
+ field :image_file_size, :type => Integer
40
+
41
+ has_attached_file :image
42
+
43
+ def image=(path)
44
+ self.write_attribute(:image, Vidibus::Tempfile.new(path))
45
+ end
46
+ end
47
+
48
+
49
+ == TODO
50
+
51
+ * Write specs
52
+
53
+
54
+ == Copyright
55
+
56
+ Copyright (c) 2010 Andre Pankratz. See LICENSE.txt for further details.
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ require "rubygems"
2
+ require "rake"
3
+ require "rake/rdoctask"
4
+ require "rspec"
5
+ require "rspec/core/rake_task"
6
+
7
+ begin
8
+ require "jeweler"
9
+ Jeweler::Tasks.new do |gem|
10
+ gem.name = "vidibus-tempfile"
11
+ gem.summary = %Q{Provides extended Tempfile}
12
+ gem.description = %Q{Adds mime type and file extension to Tempfile.}
13
+ gem.email = "andre@vidibus.com"
14
+ gem.homepage = "http://github.com/vidibus/vidibus-tempfile"
15
+ gem.authors = ["Andre Pankratz"]
16
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
+ end
18
+ Jeweler::GemcutterTasks.new
19
+ rescue LoadError
20
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
21
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1 @@
1
+ require "vidibus/tempfile"
@@ -0,0 +1,35 @@
1
+ module Vidibus
2
+ class Tempfile < ::Tempfile
3
+ def initialize(path, tmpdir = Dir::tmpdir)
4
+ @original_filename = File.basename(path)
5
+ @path = path
6
+ super(@original_filename, tmpdir)
7
+ fetch
8
+ end
9
+
10
+ def fetch
11
+ return unless File.file?(@path)
12
+ self.write(File.read(@path))
13
+ self.rewind
14
+ self
15
+ end
16
+
17
+ def original_filename
18
+ @original_filename
19
+ end
20
+
21
+ def content_type
22
+ mime = `file --mime -br #{self.path}`.strip
23
+ mime.gsub!(/^.*: */,"")
24
+ mime.gsub!(/(;|,).*$/,"")
25
+ mime
26
+ end
27
+
28
+ # Replaces Tempfile's +make_tmpname+ with one that honors file extensions.
29
+ # Copied from Paperclip
30
+ def make_tmpname(basename, n)
31
+ extension = File.extname(basename)
32
+ sprintf("%s,%d,%d%s", File.basename(basename, extension), $$, n.to_i, extension)
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,53 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{vidibus-tempfile}
8
+ s.version = "0.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Andre Pankratz"]
12
+ s.date = %q{2010-11-18}
13
+ s.description = %q{Adds mime type and file extension to Tempfile.}
14
+ s.email = %q{andre@vidibus.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "lib/vidibus-tempfile.rb",
29
+ "lib/vidibus/tempfile.rb",
30
+ "vidibus-tempfile.gemspec"
31
+ ]
32
+ s.homepage = %q{http://github.com/vidibus/vidibus-tempfile}
33
+ s.require_paths = ["lib"]
34
+ s.rubygems_version = %q{1.3.7}
35
+ s.summary = %q{Provides extended Tempfile}
36
+
37
+ if s.respond_to? :specification_version then
38
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
39
+ s.specification_version = 3
40
+
41
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
42
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
43
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
44
+ else
45
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
46
+ s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
47
+ end
48
+ else
49
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
50
+ s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
51
+ end
52
+ end
53
+
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vidibus-tempfile
3
+ version: !ruby/object:Gem::Version
4
+ hash: 31
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 0
10
+ version: 0.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Andre Pankratz
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-11-18 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ type: :development
23
+ prerelease: false
24
+ name: bundler
25
+ version_requirements: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ hash: 23
31
+ segments:
32
+ - 1
33
+ - 0
34
+ - 0
35
+ version: 1.0.0
36
+ requirement: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ type: :development
39
+ prerelease: false
40
+ name: jeweler
41
+ version_requirements: &id002 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ hash: 1
47
+ segments:
48
+ - 1
49
+ - 5
50
+ - 1
51
+ version: 1.5.1
52
+ requirement: *id002
53
+ description: Adds mime type and file extension to Tempfile.
54
+ email: andre@vidibus.com
55
+ executables: []
56
+
57
+ extensions: []
58
+
59
+ extra_rdoc_files:
60
+ - LICENSE.txt
61
+ - README.rdoc
62
+ files:
63
+ - .document
64
+ - .rspec
65
+ - Gemfile
66
+ - Gemfile.lock
67
+ - LICENSE.txt
68
+ - README.rdoc
69
+ - Rakefile
70
+ - VERSION
71
+ - lib/vidibus-tempfile.rb
72
+ - lib/vidibus/tempfile.rb
73
+ - vidibus-tempfile.gemspec
74
+ has_rdoc: true
75
+ homepage: http://github.com/vidibus/vidibus-tempfile
76
+ licenses: []
77
+
78
+ post_install_message:
79
+ rdoc_options: []
80
+
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ hash: 3
89
+ segments:
90
+ - 0
91
+ version: "0"
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ hash: 3
98
+ segments:
99
+ - 0
100
+ version: "0"
101
+ requirements: []
102
+
103
+ rubyforge_project:
104
+ rubygems_version: 1.3.7
105
+ signing_key:
106
+ specification_version: 3
107
+ summary: Provides extended Tempfile
108
+ test_files: []
109
+