has_media 0.1.3 → 0.2.1

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/.gitignore CHANGED
@@ -20,3 +20,4 @@ pkg
20
20
 
21
21
  ## PROJECT::SPECIFIC
22
22
  uploads
23
+ doc
data/README.rdoc CHANGED
@@ -4,53 +4,83 @@ Media Managment Library for ActiveRecord and Carrierwave
4
4
 
5
5
  Easy way to link media (ie image, audio, video, pdf, ...) on other activerecords models
6
6
 
7
- Use branch rails2.3 for Rails 2.3.x and rails3 for Rails 3
7
+ Use branch rails2.3 for Rails 2.3.x (gem install has_media -v=v0.1.3)
8
8
 
9
- === Create migrations
9
+ Use branch rails3 for Rails 3 (gem install has_media)
10
10
 
11
- ./script/generate has_media
11
+ == Installation
12
12
 
13
- == Usage
13
+ === Rails 2.3.x
14
14
 
15
- has_one_medium :image, :only => :image
16
- has_many_media :images, :only => :image
15
+ see http://github.com/klacointe/has_media/tree/rails2.3
17
16
 
18
- has_one_medium :audio, :only => :audio
19
- has_many_media :audios, :only => :audio
17
+ === Rails 3
20
18
 
21
- has_one_medium :image_no_encode, :only => :image, :encode => false
19
+ - gem install has_media
20
+ - rails generate has_media:install
22
21
 
23
- has_one_medium :pdf, :encode => false
22
+ The generator will create :
23
+ - migration for activerecord
24
+ - initializer for HasMedia configuration
25
+ - locales files
24
26
 
25
27
  == Model and Uploaders
26
28
 
27
- You must defined model and uploader with the name given in the only option
29
+ You must defined model and uploader with the name given in the :only option
30
+
28
31
  Examples are in the /examples directory...
29
32
 
33
+ == Usage
34
+
35
+ Available methods are :
36
+ - has_one_medium : Link to one medium
37
+ - has_many_media : Link to many media
38
+
39
+ Available options are :
40
+ - only : restrict medium type to link on
41
+ - encode : if false is given, set the encode status of this medium
42
+ to NO_ENCODING instead of ENCODE_WAIT, default to true
43
+
44
+ Example :
45
+
46
+ class MyModelWithMedia < ActiveRecord::Base
47
+
48
+ has_one_medium :image, :only => :image
49
+ has_many_media :images, :only => :image
50
+
51
+ has_one_medium :audio, :only => :audio
52
+ has_many_media :audios, :only => :audio
53
+
54
+ has_one_medium :image_no_encode, :only => :image, :encode => false
55
+
56
+ has_one_medium :pdf, :encode => false
57
+
58
+ end
59
+
30
60
  == Configuration
31
61
 
32
- * Configuration take place in config/initializers/has_media.rb
62
+ Configuration take place in config/initializers/has_media.rb
33
63
 
34
- * Set the directory path to use to store media
64
+ # Set the directory path to use to store media
35
65
  HasMedia.directory_path = "media"
36
66
 
37
- * Set the base uri to access media
67
+ # Set the base uri to access media
38
68
  HasMedia.directory_uri = "/media"
39
69
 
40
- * Set custom error messages
70
+ # Set custom error messages
41
71
  HasMedia.errors_messages = {:type_error => I18n.t('has_media.errors.type_error')}
42
72
 
43
- * Set the allowed medium types for your application (used if no :only option given)
73
+ # Set the allowed medium types for your application (used if no :only option given)
44
74
  HasMedia.medium_types = [Image, Video, Audio]
45
75
 
46
- * Set the extension of encoded files to use for each medium types (used in file_uri and file_path)
76
+ # Set the extension of encoded files to use for each medium types (used in file_uri and file_path)
47
77
  HasMedia.encoded_extensions = {
48
78
  :image => 'png',
49
79
  :audio => 'ogg',
50
80
  :video => 'flv'
51
81
  }
52
82
 
53
- * Require you uploaders
83
+ # Require you uploaders
54
84
  Dir.glob(File.dirname(__FILE__) + '/../app/uploaders/*.rb').each do |uploader|
55
85
  require uploader
56
86
  end
@@ -68,13 +98,14 @@ Factory example using factory_girl :
68
98
  f.file {ActionController::TestUploadedFile.new(File.join(Rails.root, '/spec/factories/image.jpg'), 'image/jpeg')}
69
99
  end
70
100
 
71
- == TODO
72
- * Doc for testing (ActionController::TestUploadedFile is now obsolete in rails 3), add HasMediaTestHelper with stub_temp_file method
73
- * Generator for initializer
74
- * Add controller and views examples with overload system (form fields, display, ...)
75
- * Fix problem with migrations generator timestamps
76
- * Generator for models and uploaders (Type in Image, Video, Audio, Pdf) :
77
- rails generate has_media_model Type Name
101
+ == Todo
102
+ - Doc for testing (ActionController::TestUploadedFile is now obsolete in rails 3), add HasMediaTestHelper with stub_temp_file method
103
+ - Generator for initializer
104
+ - Add controller and views examples with overload system (form fields, display, ...)
105
+ - Fix problem with migrations generator timestamps
106
+ - Generator for models and uploaders (Type in Image, Video, Audio, Pdf) : rails generate has_media_model Type Name
107
+ - Document code
108
+ - add example app on github
78
109
 
79
110
  == Contributors
80
111
 
data/Rakefile CHANGED
@@ -15,11 +15,11 @@ begin
15
15
  gem.email = "kevinlacointe@gmail.com"
16
16
  gem.homepage = "http://github.com/klacointe/has_media"
17
17
  gem.authors = ["klacointe", "spk"]
18
- gem.add_development_dependency "rspec", "<=1.3.0"
19
- gem.add_dependency('carrierwave', '=0.4.5')
20
- gem.add_dependency('activerecord', '=2.3.8')
21
- gem.add_dependency('activesupport', '=2.3.8')
22
- gem.add_dependency('mime-types', '>=1.16')
18
+ gem.add_development_dependency "rspec", "~>2.0.0"
19
+ gem.add_dependency('carrierwave-rails3', '~>0.4.5')
20
+ gem.add_dependency('activerecord', '~>3.0.0')
21
+ gem.add_dependency('activesupport', '~>3.0.0')
22
+ gem.add_dependency('mime-types', '~>1.16')
23
23
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
24
24
  end
25
25
  rescue LoadError
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.2.1
@@ -0,0 +1,4 @@
1
+ en:
2
+ has_media:
3
+ errors:
4
+ type_error: "File type error"
data/has_media.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{has_media}
8
- s.version = "0.1.3"
8
+ s.version = "0.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["klacointe", "spk"]
12
- s.date = %q{2010-10-06}
12
+ s.date = %q{2010-11-02}
13
13
  s.description = %q{Media Managment Library for ActiveRecord and Carrierwave}
14
14
  s.email = %q{kevinlacointe@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -24,6 +24,7 @@ Gem::Specification.new do |s|
24
24
  "README.rdoc",
25
25
  "Rakefile",
26
26
  "VERSION",
27
+ "config/locales/en.yml",
27
28
  "examples/models/audio.rb",
28
29
  "examples/models/image.rb",
29
30
  "examples/models/pdf.rb",
@@ -32,10 +33,12 @@ Gem::Specification.new do |s|
32
33
  "examples/uploaders/image_uploader.rb",
33
34
  "examples/uploaders/pdf_uploader.rb",
34
35
  "examples/uploaders/video_uploader.rb",
35
- "generators/has_media/has_media_generator.rb",
36
- "generators/has_media/templates/create_media.rb",
37
- "generators/has_media/templates/create_media_links.rb",
38
36
  "has_media.gemspec",
37
+ "lib/generators/active_record/has_media_generator.rb",
38
+ "lib/generators/active_record/templates/migration.rb",
39
+ "lib/generators/has_media/install_generator.rb",
40
+ "lib/generators/templates/README",
41
+ "lib/generators/templates/has_media.rb",
39
42
  "lib/has_media.rb",
40
43
  "lib/has_media/models/media_link.rb",
41
44
  "lib/has_media/models/medium.rb",
@@ -58,17 +61,17 @@ Gem::Specification.new do |s|
58
61
  s.summary = %q{Media Managment Library for ActiveRecord and Carrierwave}
59
62
  s.test_files = [
60
63
  "spec/spec_helper.rb",
61
- "spec/fixtures/models/image.rb",
62
- "spec/fixtures/uploaders/uploader_with_exception.rb",
63
64
  "spec/has_media_spec.rb",
65
+ "spec/fixtures/uploaders/uploader_with_exception.rb",
66
+ "spec/fixtures/models/image.rb",
67
+ "examples/uploaders/image_uploader.rb",
68
+ "examples/uploaders/pdf_uploader.rb",
69
+ "examples/uploaders/video_uploader.rb",
70
+ "examples/uploaders/audio_uploader.rb",
64
71
  "examples/models/image.rb",
65
72
  "examples/models/pdf.rb",
66
73
  "examples/models/audio.rb",
67
- "examples/models/video.rb",
68
- "examples/uploaders/pdf_uploader.rb",
69
- "examples/uploaders/audio_uploader.rb",
70
- "examples/uploaders/video_uploader.rb",
71
- "examples/uploaders/image_uploader.rb"
74
+ "examples/models/video.rb"
72
75
  ]
73
76
 
74
77
  if s.respond_to? :specification_version then
@@ -76,24 +79,24 @@ Gem::Specification.new do |s|
76
79
  s.specification_version = 3
77
80
 
78
81
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
79
- s.add_development_dependency(%q<rspec>, ["<= 1.3.0"])
80
- s.add_runtime_dependency(%q<carrierwave>, ["= 0.4.5"])
81
- s.add_runtime_dependency(%q<activerecord>, ["= 2.3.8"])
82
- s.add_runtime_dependency(%q<activesupport>, ["= 2.3.8"])
83
- s.add_runtime_dependency(%q<mime-types>, [">= 1.16"])
82
+ s.add_development_dependency(%q<rspec>, ["~> 2.0.0"])
83
+ s.add_runtime_dependency(%q<carrierwave-rails3>, ["~> 0.4.5"])
84
+ s.add_runtime_dependency(%q<activerecord>, ["~> 3.0.0"])
85
+ s.add_runtime_dependency(%q<activesupport>, ["~> 3.0.0"])
86
+ s.add_runtime_dependency(%q<mime-types>, ["~> 1.16"])
84
87
  else
85
- s.add_dependency(%q<rspec>, ["<= 1.3.0"])
86
- s.add_dependency(%q<carrierwave>, ["= 0.4.5"])
87
- s.add_dependency(%q<activerecord>, ["= 2.3.8"])
88
- s.add_dependency(%q<activesupport>, ["= 2.3.8"])
89
- s.add_dependency(%q<mime-types>, [">= 1.16"])
88
+ s.add_dependency(%q<rspec>, ["~> 2.0.0"])
89
+ s.add_dependency(%q<carrierwave-rails3>, ["~> 0.4.5"])
90
+ s.add_dependency(%q<activerecord>, ["~> 3.0.0"])
91
+ s.add_dependency(%q<activesupport>, ["~> 3.0.0"])
92
+ s.add_dependency(%q<mime-types>, ["~> 1.16"])
90
93
  end
91
94
  else
92
- s.add_dependency(%q<rspec>, ["<= 1.3.0"])
93
- s.add_dependency(%q<carrierwave>, ["= 0.4.5"])
94
- s.add_dependency(%q<activerecord>, ["= 2.3.8"])
95
- s.add_dependency(%q<activesupport>, ["= 2.3.8"])
96
- s.add_dependency(%q<mime-types>, [">= 1.16"])
95
+ s.add_dependency(%q<rspec>, ["~> 2.0.0"])
96
+ s.add_dependency(%q<carrierwave-rails3>, ["~> 0.4.5"])
97
+ s.add_dependency(%q<activerecord>, ["~> 3.0.0"])
98
+ s.add_dependency(%q<activesupport>, ["~> 3.0.0"])
99
+ s.add_dependency(%q<mime-types>, ["~> 1.16"])
97
100
  end
98
101
  end
99
102
 
@@ -0,0 +1,27 @@
1
+ require 'rails/generators/active_record'
2
+
3
+ module ActiveRecord
4
+ module Generators
5
+ # Cannot inhérit from ActiveRecord::Generators::Base
6
+ # see http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/a507ce419076cda2
7
+ class HasMediaGenerator < Rails::Generators::Base
8
+ include Rails::Generators::Migration
9
+ source_root File.expand_path("../templates", __FILE__)
10
+
11
+ def copy_has_media_migration
12
+ migration_template "migration.rb", "db/migrate/has_media"
13
+ end
14
+
15
+ # Implement the required interface for Rails::Generators::Migration.
16
+ # taken from http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb
17
+ def self.next_migration_number(dirname)
18
+ if ActiveRecord::Base.timestamped_migrations
19
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
20
+ else
21
+ "%.3d" % (current_migration_number(dirname) + 1)
22
+ end
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -1,4 +1,4 @@
1
- class CreateMedia < ActiveRecord::Migration
1
+ class HasMedia < ActiveRecord::Migration
2
2
  def self.up
3
3
  create_table :media do |t|
4
4
  t.integer :width
@@ -16,9 +16,20 @@ class CreateMedia < ActiveRecord::Migration
16
16
  end
17
17
  add_index :media, :encode_status
18
18
  add_index :media, [:type, :context]
19
+
20
+ create_table :media_links do |t|
21
+ t.integer :medium_id # required
22
+ t.integer :mediated_id # required
23
+ t.string :mediated_type # required
24
+
25
+ t.timestamps
26
+ end
27
+ add_index :media_links, :medium_id
28
+ add_index :media_links, [:mediated_id, :mediated_type]
19
29
  end
20
30
 
21
31
  def self.down
22
32
  drop_table :media
33
+ drop_table :media_links
23
34
  end
24
35
  end
@@ -0,0 +1,24 @@
1
+ module HasMedia
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ include Rails::Generators::Migration
5
+ source_root File.expand_path("../../templates", __FILE__)
6
+
7
+ desc "Creates a HasMedia initializer, migration and copy locale files to your application."
8
+
9
+ def copy_initializer
10
+ template "has_media.rb", "config/initializers/has_media.rb"
11
+ end
12
+
13
+ def copy_locale
14
+ copy_file "../../../config/locales/en.yml", "config/locales/has_media.en.yml"
15
+ end
16
+
17
+ hook_for :orm, :as => "has_media"
18
+
19
+ def show_readme
20
+ readme "README" if behavior == :invoke
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,5 @@
1
+ ===============================================================================
2
+ Thanks for using HasMedia !
3
+
4
+ Documentation available at http://github.com/klacointe/has_media
5
+ ===============================================================================
@@ -0,0 +1,20 @@
1
+ # Set the directory path to use to store media
2
+ HasMedia.directory_path = "media"
3
+
4
+ # Set the base uri to access media
5
+ HasMedia.directory_uri = "/media"
6
+
7
+ # Set the allowed medium types for your application (used if no :only option given)
8
+ #HasMedia.medium_types = [Image, Video, Audio]
9
+
10
+ # Set the extension of encoded files to use for each medium types (used in file_uri and file_path)
11
+ #HasMedia.encoded_extensions = {
12
+ # :image => 'png',
13
+ # :audio => 'ogg',
14
+ # :video => 'flv'
15
+ #}
16
+
17
+ # Require you uploaders
18
+ Dir.glob(File.dirname(__FILE__) + '/../app/uploaders/*.rb').each do |uploader|
19
+ require uploader
20
+ end
@@ -31,7 +31,7 @@ class Medium < ActiveRecord::Base
31
31
  after_initialize :set_default_encoding_status
32
32
 
33
33
 
34
- named_scope :with_context, lambda {|context|
34
+ scope :with_context, lambda {|context|
35
35
  { :conditions => { :context => context.to_s} }
36
36
  }
37
37
 
data/spec/spec_helper.rb CHANGED
@@ -11,10 +11,9 @@ require 'action_dispatch/testing/test_process'
11
11
  require 'has_media'
12
12
 
13
13
  dbconfig = {
14
- :adapter => 'mysql',
15
- :database => 'has_media',
16
- :username => 'test',
17
- :password => 'test'
14
+ :adapter => 'sqlite3',
15
+ :database => ':memory:',
16
+ # :database => 'has_media.sqlite'
18
17
  }
19
18
 
20
19
  ActiveRecord::Base.establish_connection(dbconfig)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_media
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
+ - 2
8
9
  - 1
9
- - 3
10
- version: 0.1.3
10
+ version: 0.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - klacointe
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-10-06 00:00:00 +02:00
19
+ date: 2010-11-02 00:00:00 +01:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -25,23 +25,23 @@ dependencies:
25
25
  requirement: &id001 !ruby/object:Gem::Requirement
26
26
  none: false
27
27
  requirements:
28
- - - <=
28
+ - - ~>
29
29
  - !ruby/object:Gem::Version
30
- hash: 27
30
+ hash: 15
31
31
  segments:
32
- - 1
33
- - 3
32
+ - 2
34
33
  - 0
35
- version: 1.3.0
34
+ - 0
35
+ version: 2.0.0
36
36
  type: :development
37
37
  version_requirements: *id001
38
38
  - !ruby/object:Gem::Dependency
39
- name: carrierwave
39
+ name: carrierwave-rails3
40
40
  prerelease: false
41
41
  requirement: &id002 !ruby/object:Gem::Requirement
42
42
  none: false
43
43
  requirements:
44
- - - "="
44
+ - - ~>
45
45
  - !ruby/object:Gem::Version
46
46
  hash: 5
47
47
  segments:
@@ -57,14 +57,14 @@ dependencies:
57
57
  requirement: &id003 !ruby/object:Gem::Requirement
58
58
  none: false
59
59
  requirements:
60
- - - "="
60
+ - - ~>
61
61
  - !ruby/object:Gem::Version
62
- hash: 19
62
+ hash: 7
63
63
  segments:
64
- - 2
65
64
  - 3
66
- - 8
67
- version: 2.3.8
65
+ - 0
66
+ - 0
67
+ version: 3.0.0
68
68
  type: :runtime
69
69
  version_requirements: *id003
70
70
  - !ruby/object:Gem::Dependency
@@ -73,14 +73,14 @@ dependencies:
73
73
  requirement: &id004 !ruby/object:Gem::Requirement
74
74
  none: false
75
75
  requirements:
76
- - - "="
76
+ - - ~>
77
77
  - !ruby/object:Gem::Version
78
- hash: 19
78
+ hash: 7
79
79
  segments:
80
- - 2
81
80
  - 3
82
- - 8
83
- version: 2.3.8
81
+ - 0
82
+ - 0
83
+ version: 3.0.0
84
84
  type: :runtime
85
85
  version_requirements: *id004
86
86
  - !ruby/object:Gem::Dependency
@@ -89,7 +89,7 @@ dependencies:
89
89
  requirement: &id005 !ruby/object:Gem::Requirement
90
90
  none: false
91
91
  requirements:
92
- - - ">="
92
+ - - ~>
93
93
  - !ruby/object:Gem::Version
94
94
  hash: 47
95
95
  segments:
@@ -115,6 +115,7 @@ files:
115
115
  - README.rdoc
116
116
  - Rakefile
117
117
  - VERSION
118
+ - config/locales/en.yml
118
119
  - examples/models/audio.rb
119
120
  - examples/models/image.rb
120
121
  - examples/models/pdf.rb
@@ -123,10 +124,12 @@ files:
123
124
  - examples/uploaders/image_uploader.rb
124
125
  - examples/uploaders/pdf_uploader.rb
125
126
  - examples/uploaders/video_uploader.rb
126
- - generators/has_media/has_media_generator.rb
127
- - generators/has_media/templates/create_media.rb
128
- - generators/has_media/templates/create_media_links.rb
129
127
  - has_media.gemspec
128
+ - lib/generators/active_record/has_media_generator.rb
129
+ - lib/generators/active_record/templates/migration.rb
130
+ - lib/generators/has_media/install_generator.rb
131
+ - lib/generators/templates/README
132
+ - lib/generators/templates/has_media.rb
130
133
  - lib/has_media.rb
131
134
  - lib/has_media/models/media_link.rb
132
135
  - lib/has_media/models/medium.rb
@@ -177,14 +180,14 @@ specification_version: 3
177
180
  summary: Media Managment Library for ActiveRecord and Carrierwave
178
181
  test_files:
179
182
  - spec/spec_helper.rb
180
- - spec/fixtures/models/image.rb
181
- - spec/fixtures/uploaders/uploader_with_exception.rb
182
183
  - spec/has_media_spec.rb
184
+ - spec/fixtures/uploaders/uploader_with_exception.rb
185
+ - spec/fixtures/models/image.rb
186
+ - examples/uploaders/image_uploader.rb
187
+ - examples/uploaders/pdf_uploader.rb
188
+ - examples/uploaders/video_uploader.rb
189
+ - examples/uploaders/audio_uploader.rb
183
190
  - examples/models/image.rb
184
191
  - examples/models/pdf.rb
185
192
  - examples/models/audio.rb
186
193
  - examples/models/video.rb
187
- - examples/uploaders/pdf_uploader.rb
188
- - examples/uploaders/audio_uploader.rb
189
- - examples/uploaders/video_uploader.rb
190
- - examples/uploaders/image_uploader.rb
@@ -1,8 +0,0 @@
1
- class HasMediaGenerator < Rails::Generator::Base
2
- def manifest
3
- record do |m|
4
- m.migration_template('create_media.rb', 'db/migrate', :migration_file_name => 'create_media')
5
- m.migration_template('create_media_links.rb', 'db/migrate', :migration_file_name => 'create_media_links')
6
- end
7
- end
8
- end
@@ -1,17 +0,0 @@
1
- class CreateMediaLinks < ActiveRecord::Migration
2
- def self.up
3
- create_table :media_links do |t|
4
- t.integer :medium_id # required
5
- t.integer :mediated_id # required
6
- t.string :mediated_type # required
7
-
8
- t.timestamps
9
- end
10
- add_index :media_links, :medium_id
11
- add_index :media_links, [:mediated_id, :mediated_type]
12
- end
13
-
14
- def self.down
15
- drop_table :media_links
16
- end
17
- end