has-attached 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'rails'
4
+ gem 'aws-sdk'
5
+ gem 'paperclip'
6
+ gem 'flash_cookie_session'
7
+
8
+ group :development do
9
+ gem "jeweler"
10
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,115 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ actionmailer (3.2.8)
5
+ actionpack (= 3.2.8)
6
+ mail (~> 2.4.4)
7
+ actionpack (3.2.8)
8
+ activemodel (= 3.2.8)
9
+ activesupport (= 3.2.8)
10
+ builder (~> 3.0.0)
11
+ erubis (~> 2.7.0)
12
+ journey (~> 1.0.4)
13
+ rack (~> 1.4.0)
14
+ rack-cache (~> 1.2)
15
+ rack-test (~> 0.6.1)
16
+ sprockets (~> 2.1.3)
17
+ activemodel (3.2.8)
18
+ activesupport (= 3.2.8)
19
+ builder (~> 3.0.0)
20
+ activerecord (3.2.8)
21
+ activemodel (= 3.2.8)
22
+ activesupport (= 3.2.8)
23
+ arel (~> 3.0.2)
24
+ tzinfo (~> 0.3.29)
25
+ activeresource (3.2.8)
26
+ activemodel (= 3.2.8)
27
+ activesupport (= 3.2.8)
28
+ activesupport (3.2.8)
29
+ i18n (~> 0.6)
30
+ multi_json (~> 1.0)
31
+ arel (3.0.2)
32
+ aws-sdk (1.6.3)
33
+ httparty (~> 0.7)
34
+ json (~> 1.4)
35
+ nokogiri (>= 1.4.4)
36
+ uuidtools (~> 2.1)
37
+ builder (3.0.0)
38
+ cocaine (0.2.1)
39
+ erubis (2.7.0)
40
+ flash_cookie_session (1.1.3)
41
+ rails (~> 3.0)
42
+ git (1.2.5)
43
+ hike (1.2.1)
44
+ httparty (0.8.3)
45
+ multi_json (~> 1.0)
46
+ multi_xml
47
+ i18n (0.6.0)
48
+ jeweler (1.8.4)
49
+ bundler (~> 1.0)
50
+ git (>= 1.2.5)
51
+ rake
52
+ rdoc
53
+ journey (1.0.4)
54
+ json (1.7.4)
55
+ mail (2.4.4)
56
+ i18n (>= 0.4.0)
57
+ mime-types (~> 1.16)
58
+ treetop (~> 1.4.8)
59
+ mime-types (1.19)
60
+ multi_json (1.3.6)
61
+ multi_xml (0.5.1)
62
+ nokogiri (1.5.5)
63
+ paperclip (3.1.4)
64
+ activemodel (>= 3.0.0)
65
+ activerecord (>= 3.0.0)
66
+ activesupport (>= 3.0.0)
67
+ cocaine (>= 0.0.2)
68
+ mime-types
69
+ polyglot (0.3.3)
70
+ rack (1.4.1)
71
+ rack-cache (1.2)
72
+ rack (>= 0.4)
73
+ rack-ssl (1.3.2)
74
+ rack
75
+ rack-test (0.6.1)
76
+ rack (>= 1.0)
77
+ rails (3.2.8)
78
+ actionmailer (= 3.2.8)
79
+ actionpack (= 3.2.8)
80
+ activerecord (= 3.2.8)
81
+ activeresource (= 3.2.8)
82
+ activesupport (= 3.2.8)
83
+ bundler (~> 1.0)
84
+ railties (= 3.2.8)
85
+ railties (3.2.8)
86
+ actionpack (= 3.2.8)
87
+ activesupport (= 3.2.8)
88
+ rack-ssl (~> 1.3.2)
89
+ rake (>= 0.8.7)
90
+ rdoc (~> 3.4)
91
+ thor (>= 0.14.6, < 2.0)
92
+ rake (0.9.2.2)
93
+ rdoc (3.12)
94
+ json (~> 1.4)
95
+ sprockets (2.1.3)
96
+ hike (~> 1.2)
97
+ rack (~> 1.0)
98
+ tilt (~> 1.1, != 1.3.0)
99
+ thor (0.15.4)
100
+ tilt (1.3.3)
101
+ treetop (1.4.10)
102
+ polyglot
103
+ polyglot (>= 0.3.1)
104
+ tzinfo (0.3.33)
105
+ uuidtools (2.1.3)
106
+
107
+ PLATFORMS
108
+ ruby
109
+
110
+ DEPENDENCIES
111
+ aws-sdk
112
+ flash_cookie_session
113
+ jeweler
114
+ paperclip
115
+ rails
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # has-attached
2
+
3
+ ActiveRecordSchema attachments with Paperclip
4
+
5
+ ## Installation
6
+
7
+ ``` rb
8
+ gem "has-attached"
9
+ ```
10
+
11
+ ```
12
+ rails g has-attached:install
13
+ ```
14
+ generates `config/s3.yml` and `config/styles.yml`
15
+
16
+ ``` rb
17
+ class Photo
18
+ has_attached :image
19
+
20
+ end
21
+ ```
22
+
23
+ ``` yml
24
+ # config/styles.yml
25
+ styles:
26
+ photo:
27
+ image:
28
+ large: "800x800"
29
+
30
+ ```
31
+
32
+ ---
33
+
34
+ Copyright (c) 2012 mcasimir
35
+
36
+ MIT License
37
+
38
+ Permission is hereby granted, free of charge, to any person obtaining
39
+ a copy of this software and associated documentation files (the
40
+ "Software"), to deal in the Software without restriction, including
41
+ without limitation the rights to use, copy, modify, merge, publish,
42
+ distribute, sublicense, and/or sell copies of the Software, and to
43
+ permit persons to whom the Software is furnished to do so, subject to
44
+ the following conditions:
45
+
46
+ The above copyright notice and this permission notice shall be
47
+ included in all copies or substantial portions of the Software.
48
+
49
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
50
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
51
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
52
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
53
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
54
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
55
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "has-attached"
18
+ gem.homepage = "http://github.com/mcasimir/kaminari-bootstrap"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{ActiveRecordSchema attachments with Paperclip}
21
+ gem.description = %Q{ActiveRecordSchema attachments with Paperclip}
22
+ gem.email = "maurizio.cas@gmail.com"
23
+ gem.authors = ["mcasimir"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+
29
+ task :push do
30
+ message = ENV["message"] || "commit #{Time.now}"
31
+ `git add . && git commit -a -m '#{message}' && git push`
32
+ end
33
+
34
+ task "release:patch" do
35
+ Rake::Task["gemspec"].invoke
36
+ Rake::Task["version:bump:patch"]
37
+ Rake::Task["push"].invoke
38
+ Rake::Task["release"].invoke
39
+ end
40
+
41
+ task "release:minor" do
42
+ Rake::Task["gemspec"].invoke
43
+ Rake::Task["version:bump:minor"]
44
+ Rake::Task["push"].invoke
45
+ Rake::Task["release"].invoke
46
+ end
47
+
48
+ task "release:major" do
49
+ Rake::Task["gemspec"].invoke
50
+ Rake::Task["version:bump:major"]
51
+ Rake::Task["push"].invoke
52
+ Rake::Task["release"].invoke
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
@@ -0,0 +1,59 @@
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 = "has-attached"
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["mcasimir"]
12
+ s.date = "2012-08-13"
13
+ s.description = "ActiveRecordSchema attachments with Paperclip"
14
+ s.email = "maurizio.cas@gmail.com"
15
+ s.extra_rdoc_files = [
16
+ "README.md"
17
+ ]
18
+ s.files = [
19
+ "Gemfile",
20
+ "Gemfile.lock",
21
+ "README.md",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "has-attached.gemspec",
25
+ "lib/generators/has-attached/install_generator.rb",
26
+ "lib/has-attached.rb",
27
+ "lib/has-attached/engine.rb"
28
+ ]
29
+ s.homepage = "http://github.com/mcasimir/kaminari-bootstrap"
30
+ s.licenses = ["MIT"]
31
+ s.require_paths = ["lib"]
32
+ s.rubygems_version = "1.8.24"
33
+ s.summary = "ActiveRecordSchema attachments with Paperclip"
34
+
35
+ if s.respond_to? :specification_version then
36
+ s.specification_version = 3
37
+
38
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
39
+ s.add_runtime_dependency(%q<rails>, [">= 0"])
40
+ s.add_runtime_dependency(%q<aws-sdk>, [">= 0"])
41
+ s.add_runtime_dependency(%q<paperclip>, [">= 0"])
42
+ s.add_runtime_dependency(%q<flash_cookie_session>, [">= 0"])
43
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
44
+ else
45
+ s.add_dependency(%q<rails>, [">= 0"])
46
+ s.add_dependency(%q<aws-sdk>, [">= 0"])
47
+ s.add_dependency(%q<paperclip>, [">= 0"])
48
+ s.add_dependency(%q<flash_cookie_session>, [">= 0"])
49
+ s.add_dependency(%q<jeweler>, [">= 0"])
50
+ end
51
+ else
52
+ s.add_dependency(%q<rails>, [">= 0"])
53
+ s.add_dependency(%q<aws-sdk>, [">= 0"])
54
+ s.add_dependency(%q<paperclip>, [">= 0"])
55
+ s.add_dependency(%q<flash_cookie_session>, [">= 0"])
56
+ s.add_dependency(%q<jeweler>, [">= 0"])
57
+ end
58
+ end
59
+
@@ -0,0 +1,24 @@
1
+ module HasAttached
2
+ class InstallGenerator < Rails::Generators::NamedBase
3
+
4
+ source_root File.expand_path('../templates', __FILE__)
5
+
6
+ def generate_config
7
+
8
+ create_file "config/s3.yml", <<-CONTENT
9
+ production:
10
+ bucket: BUCKET_NAME
11
+ access_key_id: ACCESS_KEY_ID
12
+ secret_access_key: SECRET_ACCESS_KEY
13
+ CONTENT
14
+
15
+ create_file "config/styles.yml", <<-CONTENT
16
+ styles:
17
+ photo:
18
+ large: "800x600"
19
+ CONTENT
20
+
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,8 @@
1
+ require 'rails'
2
+
3
+ module HasAttached
4
+ class Engine < Rails::Engine
5
+
6
+
7
+ end
8
+ end
@@ -0,0 +1,69 @@
1
+ # Author:: Maurizio Casimirri (mailto:maurizio.cas@gmail.com)
2
+ # Copyright:: Copyright (c) 2012 Maurizio Casimirri
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+
23
+ require 'aws-sdk'
24
+ require 'paperclip'
25
+ require 'flash_cookie_session'
26
+ require 'has-attached/engine'
27
+
28
+ module HasAttached
29
+ extend ActiveSupport::Concern
30
+
31
+ module ClassMethods
32
+
33
+ def has_attached(name, options = {})
34
+
35
+ options[:url] ||= "/attachments/:class/:id/:attachment/:style/:basename.:extension"
36
+ options[:path] ||= ":rails_root/public/attachments/:class/:id/:attachment/:style/:basename.:extension"
37
+
38
+ @all_styles ||= (YAML.load_file(Rails.root.join("config", "styles.yml")) rescue {"styles" => {}})["styles"]
39
+
40
+ options[:styles] = @all_styles.fetch(self.name.underscore, {}).fetch(name, {})
41
+
42
+ if Rails.env.production? && Rails.application.config.respond_to?(:upload_attachments_to_s3) && Rails.application.config.upload_attachments_to_s3
43
+ options[:storage] = 's3'
44
+ options[:s3_credentials] = Rails.root.join("config", "s3.yml")
45
+ else
46
+ options[:storage] = 'filesystem'
47
+ end
48
+ has_attached_file(name, options)
49
+
50
+ field :"#{name}_file_name"
51
+ field :"#{name}_content_type"
52
+ field :"#{name}_file_size", :as => :integer
53
+ field :"#{name}_updated_at", :as => :datetime
54
+
55
+ validate do |record|
56
+ if record.send(name) && !record.send(name).errors.empty?
57
+ file_name = record.send(:"#{name}_file_name")
58
+ record.errors.add name, "Paperclip returned errors for file '#{file_name}' - check ImageMagick installation or image source file."
59
+ false
60
+ end
61
+ end
62
+
63
+ end
64
+
65
+ end # ~ ClassMethods
66
+
67
+ end
68
+
69
+ ActiveRecord::Base.send :include, HasAttached
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: has-attached
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - mcasimir
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: aws-sdk
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: paperclip
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: flash_cookie_session
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: jeweler
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ description: ActiveRecordSchema attachments with Paperclip
95
+ email: maurizio.cas@gmail.com
96
+ executables: []
97
+ extensions: []
98
+ extra_rdoc_files:
99
+ - README.md
100
+ files:
101
+ - Gemfile
102
+ - Gemfile.lock
103
+ - README.md
104
+ - Rakefile
105
+ - VERSION
106
+ - has-attached.gemspec
107
+ - lib/generators/has-attached/install_generator.rb
108
+ - lib/has-attached.rb
109
+ - lib/has-attached/engine.rb
110
+ homepage: http://github.com/mcasimir/kaminari-bootstrap
111
+ licenses:
112
+ - MIT
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ! '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ segments:
124
+ - 0
125
+ hash: 2316443620797932418
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubyforge_project:
134
+ rubygems_version: 1.8.24
135
+ signing_key:
136
+ specification_version: 3
137
+ summary: ActiveRecordSchema attachments with Paperclip
138
+ test_files: []