dynamoid-paperclip 0.0.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.
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+
19
+ # For RubyMine:
20
+ .idea/*
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dynamoid-paperclip.gemspec
4
+ gem 'dynamoid'
5
+ gem 'paperclip', '~> 3.0'
6
+
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Stefan Neculai
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,109 @@
1
+ Dynamoid::Paperclip - Making Paperclip play nice with Dynamoid ODM
2
+ ================================================================
3
+
4
+ As the title suggests: `Dynamoid::Paperclip` makes it easy to hook up [Paperclip](https://github.com/thoughtbot/paperclip) with [Dynamoid](https://github.com/Veraticus/Dynamoid).
5
+
6
+ This is actually easier and faster to set up than when using Paperclip and the ActiveRecord ORM.
7
+ This example assumes you are using **Ruby on Rails 3** and **Bundler**. However it doesn't require either.
8
+
9
+
10
+ Setting it up
11
+ -------------
12
+
13
+ Simply define the `dynamoid-paperclip` gem inside your `Gemfile`. Additionally, you can define the `aws-sdk` gem if you want to upload your files to Amazon S3. *You do not need to explicitly define the `paperclip` gem itself, since this is handled by `dynamoid-paperclip`.*
14
+
15
+ **Rails.root/Gemfile - Just define the following:**
16
+
17
+ gem 'dynamoid-paperclip'
18
+ gem 'aws-sdk'
19
+
20
+ Next let's assume we have a User model and we want to allow our users to upload an avatar.
21
+
22
+ **Rails.root/app/models/user.rb - include the Dynamoid::Paperclip module and invoke the provided class method**
23
+
24
+ class User
25
+ include Dynamoid::Document
26
+ include Dynamoid::Paperclip
27
+
28
+ has_dynamoid_attached_file :avatar
29
+ end
30
+
31
+
32
+ That's it
33
+ --------
34
+
35
+ That's all you have to do. Users can now upload avatars. Unlike ActiveRecord, Dynamoid doesn't use migrations, so we don't need to define the Paperclip columns in a separate file. Invoking the `has_dynamoid_attached_file` method will automatically define the necessary `:avatar` fields for you in the background.
36
+
37
+
38
+ A more complex example
39
+ ----------------------
40
+
41
+ Just like Paperclip, Dynamoid::Paperclip takes a second argument (hash of options) for the `has_dynamoid_attached_file` method, so you can do more complex things such as in the following example.
42
+
43
+ class User
44
+ include Dynamoid::Document
45
+ embeds_many :pictures
46
+ end
47
+
48
+ class Picture
49
+ include Dynamoid::Document
50
+ include Dynamoid::Paperclip
51
+
52
+ embedded_in :user, :inverse_of => :pictures
53
+
54
+ has_dynamoid_attached_file :attachment,
55
+ :path => ':attachment/:id/:style.:extension',
56
+ :storage => :s3,
57
+ :url => ':s3_alias_url',
58
+ :s3_host_alias => 'something.cloudfront.net',
59
+ :s3_credentials => File.join(Rails.root, 'config', 's3.yml'),
60
+ :styles => {
61
+ :original => ['1920x1680>', :jpg],
62
+ :small => ['100x100#', :jpg],
63
+ :medium => ['250x250', :jpg],
64
+ :large => ['500x500>', :jpg]
65
+ },
66
+ :convert_options => { :all => '-background white -flatten +matte' }
67
+ end
68
+
69
+ @user.pictures.each do |picture|
70
+ <%= picture.attachment.url %>
71
+ end
72
+
73
+ Note on embedded documents: if you plan to save or update the parent document, you MUST add cascade_callbacks: true to your
74
+ embeds_XXX statement. Otherwise, your data will be updated but the paperclip functions will not run to copy/update your file.
75
+
76
+ In the above example:
77
+
78
+ ```ruby
79
+ class User
80
+ ...
81
+ embeds_many :pictures, :cascade_callbacks => true
82
+ accepts_nested_attributes_for :pictures, ...
83
+ attr_accepted :pictures_attributes, ...
84
+ ...
85
+ end
86
+
87
+ @user.update_attributes({ ... :pictures => [...] })
88
+ ```
89
+
90
+
91
+ There you go
92
+ ------------
93
+
94
+ Quite a lot of people have been looking for a solution to use Paperclip with Dynamoid so I hope this helps!
95
+
96
+ If you need more information on either [Dynamoid](https://github.com/Veraticus/Dynamoid) or [Paperclip](https://github.com/thoughtbot/paperclip) I suggest checking our their official documentation and website.
97
+
98
+
99
+ Credits
100
+ ------------
101
+
102
+ dynamoid-paperclip borrows code, structure, and even its name very liberally from [mongoid-paperclip](https://github.com/meskyanichi/mongoid-paperclip). Without mongoid-paperclip to crib, from none of this would have been possible, so many thanks to everyone who contributed to mongoid-paperclip.
103
+
104
+
105
+ License
106
+ -------
107
+
108
+ Dynamoid::Paperclip is released under the MIT license. See LICENSE for more information.
109
+
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dynamoid/paperclip/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dynamoid-paperclip"
8
+ spec.version = Dynamoid::Paperclip::VERSION
9
+ spec.authors = ["Stefan Neculai"]
10
+ spec.email = ["stefan.neculai@gmail.com"]
11
+ spec.description = 'Dynamoid::Paperclip enables you to use Paperclip with the Dynamoid for DynamoDB.'
12
+ spec.summary = 'Dynamoid::Paperclip enables you to use Paperclip with the Dynamoid for DynamoDB.'
13
+ spec.homepage = "https://github.com/stefanneculai/dynamoid-paperclip"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_dependency 'dynamoid'
25
+ spec.add_dependency 'paperclip', '~> 3.0'
26
+ end
@@ -0,0 +1,66 @@
1
+ # encoding: utf-8
2
+
3
+ require "dynamoid/paperclip/version"
4
+
5
+ begin
6
+ require 'paperclip'
7
+ rescue LoadError
8
+ puts "Dynamoid::Paperclip requires that you install the Paperclip gem."
9
+ exit
10
+ end
11
+
12
+ begin
13
+ require 'dynamoid'
14
+ rescue LoadError
15
+ puts "Dynamoid::Paperclip requires that you install the Dynamoid gem."
16
+ exit
17
+ end
18
+
19
+ ##
20
+ # The id of dynamoid is not integer, so correct the id_partition.
21
+ Paperclip.interpolates :id_partition do |attachment, style|
22
+ attachment.instance.id.to_s.scan(/.{4}/).join("/")
23
+ end
24
+
25
+ module Dynamoid
26
+ module Paperclip
27
+
28
+ ##
29
+ # Extends the model with the defined Class methods
30
+ def self.included(base)
31
+ base.extend(ClassMethods)
32
+ end
33
+
34
+ module ClassMethods
35
+
36
+ ##
37
+ # Adds Dynamoid::Paperclip's "#has_dynamoid_attached_file" class method to the model
38
+ # which includes Paperclip and Paperclip::Glue in to the model. Additionally
39
+ # it'll also add the required fields for Paperclip since DynamoDB is schemaless and doesn't
40
+ # have migrations.
41
+ def has_dynamoid_attached_file(field, options = {})
42
+
43
+ ##
44
+ # Include Paperclip and Paperclip::Glue for compatibility
45
+ unless self.ancestors.include?(::Paperclip)
46
+ include ::Paperclip
47
+ include ::Paperclip::Glue
48
+ end
49
+
50
+ ##
51
+ # Invoke Paperclip's #has_attached_file method and passes in the
52
+ # arguments specified by the user that invoked Dynamoid::Paperclip#has_dynamoid_attached_file
53
+ has_attached_file(field, options)
54
+
55
+ ##
56
+ # Define the necessary collection fields in Dynamoid for Paperclip
57
+ field(:"#{field}_file_name")
58
+ field(:"#{field}_content_type")
59
+ field(:"#{field}_file_size", :integer)
60
+ field(:"#{field}_updated_at", :datetime)
61
+ end
62
+ end
63
+
64
+ end
65
+ end
66
+
@@ -0,0 +1,5 @@
1
+ module Dynamoid
2
+ module Paperclip
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dynamoid-paperclip
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Stefan Neculai
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-06-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
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: dynamoid
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: paperclip
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '3.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: '3.0'
78
+ description: Dynamoid::Paperclip enables you to use Paperclip with the Dynamoid for
79
+ DynamoDB.
80
+ email:
81
+ - stefan.neculai@gmail.com
82
+ executables: []
83
+ extensions: []
84
+ extra_rdoc_files: []
85
+ files:
86
+ - .gitignore
87
+ - Gemfile
88
+ - LICENSE.txt
89
+ - README.md
90
+ - Rakefile
91
+ - dynamoid-paperclip.gemspec
92
+ - lib/dynamoid/paperclip.rb
93
+ - lib/dynamoid/paperclip/version.rb
94
+ homepage: https://github.com/stefanneculai/dynamoid-paperclip
95
+ licenses:
96
+ - MIT
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ! '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ! '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 1.8.25
116
+ signing_key:
117
+ specification_version: 3
118
+ summary: Dynamoid::Paperclip enables you to use Paperclip with the Dynamoid for DynamoDB.
119
+ test_files: []
120
+ has_rdoc: