has_media 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -0,0 +1,9 @@
1
+ class Video < Medium
2
+ set_table_name 'media'
3
+
4
+ mount_uploader :file, VideoUploader
5
+
6
+ def self.handle_content_type?(content_type)
7
+ content_type.starts_with? 'audio/'
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ # encoding: utf-8
2
+
3
+ class VideoUploader < MediumUploader
4
+
5
+ # Choose what kind of storage to use for this uploader
6
+ storage :file
7
+ end
@@ -19,13 +19,14 @@ class Medium < ActiveRecord::Base
19
19
  :image => 'png',
20
20
  :audio => 'mp3',
21
21
  :pdf => 'pdf',
22
+ :video => 'flv'
22
23
  }
23
24
 
24
25
  # Allowed MIME types for upload
25
26
  # need custom configuration
26
27
  # TODO: add errors if not type of file
27
28
  @@mime_types = {
28
- :video => ['video/mpeg', 'video/mp4', 'video/quicktime', 'video/x-ms-wmv', 'video/x-flv', 'video/x-msvideo'],
29
+ :video => HasMedia.videos_content_types,
29
30
  :image => HasMedia.images_content_types,
30
31
  :audio => ['audio/mpeg', 'audio/x-ms-wma', 'audio/x-wav'],
31
32
  :flash => ['application/x-shockwave-flash'],
@@ -50,9 +51,10 @@ class Medium < ActiveRecord::Base
50
51
  return name.downcase
51
52
  end
52
53
 
54
+ # FIXME : get medium types from available classes, use has_media.medium_types
53
55
  def self.new_from_value(object, value, context, encode, only)
54
56
  only ||= ""
55
- medium_types = [Image, Audio, Pdf]
57
+ medium_types = HasMedia.medium_types
56
58
  if only != "" and klass = Kernel.const_get(only.capitalize)
57
59
  medium_types = [klass]
58
60
  end
@@ -143,7 +145,7 @@ class Medium < ActiveRecord::Base
143
145
  end
144
146
 
145
147
  def file_extension
146
- EXTENSIONS[type.downcase.to_sym]
148
+ EXTENSIONS[type.to_s.downcase.to_sym]
147
149
  end
148
150
 
149
151
  private
data/lib/has_media.rb CHANGED
@@ -7,6 +7,7 @@ module HasMedia
7
7
 
8
8
  VERSION = "0.0.1"
9
9
 
10
+ @@medium_types = []
10
11
  @@store_dir = '/tmp'
11
12
  @@directory_uri = ''
12
13
  @@custom_models_path = nil
@@ -42,7 +43,21 @@ module HasMedia
42
43
  'image/gi_',
43
44
  'image/x-citrix-pjpeg'
44
45
  ]
46
+ @@videos_content_types = [
47
+ 'video/mpeg',
48
+ 'video/mp4',
49
+ 'video/quicktime',
50
+ 'video/x-ms-wmv',
51
+ 'video/x-flv',
52
+ 'video/x-msvideo'
53
+ ]
45
54
 
55
+ def self.medium_types=(value)
56
+ @@medium_types = value
57
+ end
58
+ def self.medium_types
59
+ @@medium_types
60
+ end
46
61
  def self.directory_path=(value)
47
62
  @@store_dir = value
48
63
  end
@@ -70,6 +85,9 @@ module HasMedia
70
85
  def self.images_content_types
71
86
  @@images_content_types
72
87
  end
88
+ def self.videos_content_types
89
+ @@videos_content_types
90
+ end
73
91
  def self.errors_messages
74
92
  @@errors_messages
75
93
  end
@@ -23,6 +23,7 @@ describe "HasMedia" do
23
23
  end
24
24
  HasMedia.directory_path = 'tmp'
25
25
  HasMedia.directory_uri = '/media'
26
+ HasMedia.medium_types = [Image, Video, Pdf, Audio]
26
27
  end
27
28
 
28
29
  before :each do
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_media
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 2
9
+ version: 0.1.2
5
10
  platform: ruby
6
11
  authors:
7
12
  - klacointe
@@ -10,49 +15,65 @@ autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
17
 
13
- date: 2010-04-16 00:00:00 +02:00
18
+ date: 2010-06-09 00:00:00 +02:00
14
19
  default_executable:
15
20
  dependencies:
16
21
  - !ruby/object:Gem::Dependency
17
22
  name: rspec
18
- type: :development
19
- version_requirement:
20
- version_requirements: !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
21
25
  requirements:
22
26
  - - ">="
23
27
  - !ruby/object:Gem::Version
28
+ segments:
29
+ - 1
30
+ - 2
31
+ - 9
24
32
  version: 1.2.9
25
- version:
33
+ type: :development
34
+ version_requirements: *id001
26
35
  - !ruby/object:Gem::Dependency
27
36
  name: carrierwave
28
- type: :runtime
29
- version_requirement:
30
- version_requirements: !ruby/object:Gem::Requirement
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
31
39
  requirements:
32
40
  - - ">="
33
41
  - !ruby/object:Gem::Version
42
+ segments:
43
+ - 0
44
+ - 4
45
+ - 2
34
46
  version: 0.4.2
35
- version:
47
+ type: :runtime
48
+ version_requirements: *id002
36
49
  - !ruby/object:Gem::Dependency
37
50
  name: activerecord
38
- type: :runtime
39
- version_requirement:
40
- version_requirements: !ruby/object:Gem::Requirement
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
41
53
  requirements:
42
54
  - - ">="
43
55
  - !ruby/object:Gem::Version
56
+ segments:
57
+ - 2
58
+ - 3
59
+ - 4
44
60
  version: 2.3.4
45
- version:
61
+ type: :runtime
62
+ version_requirements: *id003
46
63
  - !ruby/object:Gem::Dependency
47
64
  name: activesupport
48
- type: :runtime
49
- version_requirement:
50
- version_requirements: !ruby/object:Gem::Requirement
65
+ prerelease: false
66
+ requirement: &id004 !ruby/object:Gem::Requirement
51
67
  requirements:
52
68
  - - ">="
53
69
  - !ruby/object:Gem::Version
70
+ segments:
71
+ - 2
72
+ - 3
73
+ - 4
54
74
  version: 2.3.4
55
- version:
75
+ type: :runtime
76
+ version_requirements: *id004
56
77
  description: Media Managment Library for ActiveRecord and Carrierwave
57
78
  email: kevinlacointe@gmail.com
58
79
  executables: []
@@ -72,9 +93,11 @@ files:
72
93
  - examples/models/audio.rb
73
94
  - examples/models/image.rb
74
95
  - examples/models/pdf.rb
96
+ - examples/models/video.rb
75
97
  - examples/uploaders/audio_uploader.rb
76
98
  - examples/uploaders/image_uploader.rb
77
99
  - examples/uploaders/pdf_uploader.rb
100
+ - examples/uploaders/video_uploader.rb
78
101
  - generators/has_media/has_media_generator.rb
79
102
  - generators/has_media/templates/create_media.rb
80
103
  - generators/has_media/templates/create_media_links.rb
@@ -105,29 +128,33 @@ required_ruby_version: !ruby/object:Gem::Requirement
105
128
  requirements:
106
129
  - - ">="
107
130
  - !ruby/object:Gem::Version
131
+ segments:
132
+ - 0
108
133
  version: "0"
109
- version:
110
134
  required_rubygems_version: !ruby/object:Gem::Requirement
111
135
  requirements:
112
136
  - - ">="
113
137
  - !ruby/object:Gem::Version
138
+ segments:
139
+ - 0
114
140
  version: "0"
115
- version:
116
141
  requirements: []
117
142
 
118
143
  rubyforge_project:
119
- rubygems_version: 1.3.5
144
+ rubygems_version: 1.3.6
120
145
  signing_key:
121
146
  specification_version: 3
122
147
  summary: Media Managment Library for ActiveRecord and Carrierwave
123
148
  test_files:
124
149
  - spec/spec_helper.rb
125
- - spec/fixtures/models/image.rb
126
- - spec/fixtures/uploaders/uploader_with_exception.rb
127
150
  - spec/has_media_spec.rb
128
- - examples/models/pdf.rb
129
- - examples/models/image.rb
130
- - examples/models/audio.rb
151
+ - spec/fixtures/uploaders/uploader_with_exception.rb
152
+ - spec/fixtures/models/image.rb
131
153
  - examples/uploaders/image_uploader.rb
132
154
  - examples/uploaders/pdf_uploader.rb
155
+ - examples/uploaders/video_uploader.rb
133
156
  - examples/uploaders/audio_uploader.rb
157
+ - examples/models/image.rb
158
+ - examples/models/pdf.rb
159
+ - examples/models/audio.rb
160
+ - examples/models/video.rb