attached 0.3.4 → 0.3.5

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.
@@ -13,7 +13,7 @@ The gem is tested with Ruby 1.9.2 and Rails 3.0.6 but may well work with other v
13
13
  == Optional
14
14
 
15
15
  brew install imagemagick
16
- port install imagemagick
16
+ brew install lame
17
17
 
18
18
  == Examples
19
19
 
@@ -71,20 +71,20 @@ View:
71
71
  === Validations
72
72
 
73
73
  # app/models/person.rb
74
- validates_attached_presence :avatar
75
- validates_attached_size :avatar, :in => 2.kilobytes..2.megabytes
76
- validates_attached_extension :avatar, :in => %w(jpe jpg jpeg png)
74
+ validates_attached_presence :file
75
+ validates_attached_size :file, :in => 2.kilobytes..2.megabytes
76
+ validates_attached_extension :file, :in => %w(jpe jpg jpeg png)
77
77
 
78
78
  ==== Storage
79
79
 
80
- # app/models/person.rb
81
- has_attached :avatar, :medium => :aws, :credentials => "#{Rails.root}/config/aws.yml"
80
+ # app/models/user.rb
81
+ has_attached :file, :medium => :aws, :credentials => "#{Rails.root}/config/aws.yml"
82
82
 
83
- # app/models/person.rb
84
- has_attached :avatar, :medium => :google, :credentials => "#{Rails.root}/config/google.yml"
83
+ # app/models/user.rb
84
+ has_attached :file, :medium => :google, :credentials => "#{Rails.root}/config/google.yml"
85
85
 
86
- # app/models/person.rb
87
- has_attached :avatar, :medium => :rackspace, :credentials => "#{Rails.root}/config/rackspace.yml"
86
+ # app/models/user.rb
87
+ has_attached :file, :medium => :rackspace, :credentials => "#{Rails.root}/config/rackspace.yml"
88
88
 
89
89
  # config/initializers/attached.rb
90
90
  Attached::Attachment.options[:medium] = :aws
@@ -100,24 +100,31 @@ View:
100
100
 
101
101
  === Processor
102
102
 
103
- # app/models/person.rb
104
- has_attached :avatar, :processor => :image, :styles => {
105
- :small => { :size => '200x200<', :extension => 'png' },
106
- :large => { :size => '400x400>', :extension => 'png' },
107
- :default => { :size => '300x300#' },
103
+ # app/models/image.rb
104
+ has_attached :file, :processor => :image, :styles => {
105
+ :small => { :size => '200x200<', :extension => '.jpg', :quality => 90 },
106
+ :large => { :size => '400x400>', :extension => '.jpg', :quality => 90 },
107
+ :default => { :size => '300x300#', :extension => '.jpg', :quality => 90 },
108
+ }
109
+
110
+ # app/models/audio.rb
111
+ has_attached :file, :processor => :audio, :styles => {
112
+ :full => { :preset => '320kbps', :extension => '.wav' },
113
+ :large => { :preset => '256kbps', :extension => '.wav' },
114
+ :small => { :preset => '128kbps', :extension => '.wav' },
108
115
  }
109
116
 
110
117
  === Aliases
111
118
 
112
119
  # app/initializer/attached.rb
113
- Attached::Attachment.options[:alias] = http://c0378198.cdn2.cloudfiles.rackspacecloud.com/
120
+ Attached::Attachment.options[:alias] = http://storage.ksylvest.com/
114
121
 
115
122
  # app/initializer/attached.rb
116
123
  Attached::Attachment.options[:aliases] = %w(
117
- http://d1kf5um3mxa8kv.cloudfront.net/
118
- http://d3d5wf186mp1rv.cloudfront.net/
119
- http://d2wmfkw6rydl1g.cloudfront.net/
120
- http://d1gqpdc40l7s16.cloudfront.net/
124
+ http://a.storage.ksylvest.com/
125
+ http://b.storage.ksylvest.com/
126
+ http://c.storage.ksylvest.com/
127
+ http://d.storage.ksylvest.com/
121
128
  )
122
129
 
123
130
  == Copyright
@@ -9,6 +9,7 @@ module Attached
9
9
  attr_reader :path
10
10
  attr_reader :extension
11
11
  attr_reader :preset
12
+ attr_reader :attachment
12
13
 
13
14
 
14
15
  # Create a processor.
@@ -27,7 +28,7 @@ module Attached
27
28
  @preset = options[:preset]
28
29
  @extension = options[:extension]
29
30
 
30
- @extension ||= File.extname(self.file.path)
31
+ @extension ||= self.attachment.extension
31
32
  end
32
33
 
33
34
 
@@ -50,7 +51,7 @@ module Attached
50
51
  result.binmode
51
52
 
52
53
  begin
53
-
54
+
54
55
  parameters = []
55
56
 
56
57
  parameters << "--preset #{self.preset}" if self.preset
@@ -65,7 +66,9 @@ module Attached
65
66
  raise Errno::ENOENT if $?.exitstatus == 127
66
67
 
67
68
  rescue Errno::ENOENT
69
+
68
70
  raise "command 'lame' not found: ensure LAME is installed"
71
+
69
72
  end
70
73
 
71
74
  unless $?.exitstatus == 0
@@ -11,6 +11,7 @@ module Attached
11
11
 
12
12
  attr_reader :width
13
13
  attr_reader :height
14
+ attr_reader :quality
14
15
  attr_reader :operation
15
16
 
16
17
 
@@ -28,6 +29,7 @@ module Attached
28
29
  @path = self.file.path
29
30
 
30
31
  @size = options[:size]
32
+ @quality = options[:quality]
31
33
  @extension = options[:extension]
32
34
 
33
35
  @width, @height, @operation = @size.match(/(\d*)x?(\d*)(.*)/)[1..3] if @size
@@ -36,7 +38,7 @@ module Attached
36
38
  @height ||= options[:height]
37
39
  @operation ||= options[:operation]
38
40
 
39
- @extension ||= File.extname(self.file.path)
41
+ @extension ||= self.attachment.extension
40
42
 
41
43
  @width = Integer(self.width) if self.width
42
44
  @height = Integer(self.height) if self.height
@@ -76,6 +78,8 @@ module Attached
76
78
  end
77
79
  end
78
80
 
81
+ parameters << "-quality #{quality}" if quality
82
+
79
83
  parameters << result.path
80
84
 
81
85
  parameters = parameters.join(" ").squeeze(" ")
@@ -58,10 +58,14 @@ module Attached
58
58
  # * path - The path to save.
59
59
 
60
60
  def save(file, path)
61
+ file = File.open(file.path)
62
+
61
63
  directory = connection.directories.get(self.bucket)
62
64
  directory ||= connection.directories.create(self.permissions.merge(:key => self.bucket))
63
65
 
64
- directory.files.create(self.options(path).merge(self.permissions.merge(:key => path, :body => file.read)))
66
+ directory.files.create(self.options(path).merge(self.permissions.merge(:key => path, :body => file)))
67
+
68
+ file.close
65
69
  end
66
70
 
67
71
 
@@ -58,10 +58,14 @@ module Attached
58
58
  # * path - The path to save.
59
59
 
60
60
  def save(file, path)
61
+ file = File.open(file.path)
62
+
61
63
  directory = connection.directories.get(self.bucket)
62
64
  directory ||= connection.directories.create(self.permissions.merge(:key => self.bucket))
63
65
 
64
- directory.files.create(self.options(path).merge(self.permissions.merge(:key => path, :body => file.read)))
66
+ directory.files.create(self.options(path).merge(self.permissions.merge(:key => path, :body => file)))
67
+
68
+ file.close
65
69
  end
66
70
 
67
71
 
@@ -57,10 +57,14 @@ module Attached
57
57
  # * path - The path to save.
58
58
 
59
59
  def save(file, path)
60
+ file = File.open(file.path)
61
+
60
62
  directory = connection.directories.get(self.container)
61
63
  directory ||= connection.directories.create(self.permissions.merge(:key => self.container))
62
64
 
63
- directory.files.create(self.options(path).merge(self.permissions.merge(:key => path, :body => file.read)))
65
+ directory.files.create(self.options(path).merge(self.permissions.merge(:key => path, :body => file)))
66
+
67
+ file.close
64
68
  end
65
69
 
66
70
 
@@ -1,3 +1,3 @@
1
1
  module Attached
2
- VERSION = "0.3.4"
2
+ VERSION = "0.3.5"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: attached
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.3.4
5
+ version: 0.3.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Kevin Sylvestre
@@ -10,7 +10,8 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-04-13 00:00:00 Z
13
+ date: 2011-05-15 00:00:00 -04:00
14
+ default_executable:
14
15
  dependencies:
15
16
  - !ruby/object:Gem::Dependency
16
17
  name: fog
@@ -65,6 +66,7 @@ files:
65
66
  - LICENSE
66
67
  - Gemfile
67
68
  - Rakefile
69
+ has_rdoc: true
68
70
  homepage: http://github.com/ksylvest/attached
69
71
  licenses: []
70
72
 
@@ -88,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
90
  requirements: []
89
91
 
90
92
  rubyforge_project:
91
- rubygems_version: 1.7.2
93
+ rubygems_version: 1.6.2
92
94
  signing_key:
93
95
  specification_version: 3
94
96
  summary: An attachment library designed with cloud processors in mind