paperclip-neo4j 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4ad0402253d77d6515dfa32cdff07cff36cd2231
4
+ data.tar.gz: 74f07db5b05951ef31b43b8b27e8c8c8e22062f3
5
+ SHA512:
6
+ metadata.gz: 3cadf773200f9b2620cb3eb7d039ce31401a55000d85298b30dc0a9bb21649997ac295a0165534a285852d96c9877ab7dfc36bfbe0ed144d1d28806a18ba9415
7
+ data.tar.gz: be84b74f50eb1de0587d257cb80c871526ce1efef4f5a06c87cb76ede52cc3c7377b1140a2276207702043fd786a31482bf32751bef14a78f36e1db22f17bbca
@@ -0,0 +1,49 @@
1
+ Neo4jrb::Paperclip - Making Paperclip play nice with Neo4j.rb
2
+ ================================================================
3
+ This gem is based on [neo4jrb-paperclip 0.0.4](https://github.com/l4u/neo4jrb-paperclip.git).
4
+
5
+ This gem is based on [mongoid-paperclip 0.0.4](https://github.com/meskyanichi/mongoid-paperclip).
6
+
7
+ As the title suggests: `Neo4jrb::Paperclip` makes it easy to hook up [Paperclip](https://github.com/thoughtbot/paperclip) with [Neo4j.rb](https://github.com/andreasronge/neo4j).
8
+
9
+ This is actually easier and faster to set up than when using Paperclip and the ActiveRecord ORM.
10
+ This example assumes you are using **Ruby on Rails 3** and **Bundler**. However it doesn't require either.
11
+
12
+
13
+ Setting it up
14
+ -------------
15
+
16
+ Make sure you are using JRuby. Simply define the `neo4jrb-paperclip` gem inside your `Gemfile`. Additionally, you can define the `aws-s3` 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 `neo4jrb-paperclip`.*
17
+
18
+ **Rails.root/Gemfile - Just define the following:**
19
+
20
+ gem "neo4jrb-paperclip", :require => "neo4jrb_paperclip"
21
+ gem "aws-s3", :require => "aws/s3"
22
+
23
+ Next let's assume we have a User model and we want to allow our users to upload an avatar.
24
+
25
+ **Rails.root/app/models/user.rb - include the Neo4jrb::Paperclip module and invoke the provided class method**
26
+
27
+ class User < Neo4j::Rails::Model
28
+ include Neo4jrb::Paperclip
29
+
30
+ has_neo4jrb_attached_file :avatar
31
+ end
32
+
33
+
34
+ That's it
35
+ --------
36
+
37
+ That's all you have to do. Users can now upload avatars. Unlike ActiveRecord, Neo4j doesn't use migrations normally, so we don't need to define the Paperclip columns in a separate file. Invoking the `has_neo4jrb_attached_file` method will automatically define the necessary `:avatar` fields for you in the background.
38
+
39
+ Known issues
40
+ ------------
41
+
42
+ File size returns 0 - [paperclip issue](https://github.com/thoughtbot/paperclip/issues/100)
43
+
44
+ Related Links
45
+ ------------
46
+
47
+ * [mongoid-paperclip](https://github.com/meskyanichi/mongoid-paperclip)
48
+ * [Neo4j.rb](https://github.com/andreasronge/neo4j)
49
+ * [Paperclip](https://github.com/thoughtbot/paperclip)
@@ -0,0 +1,112 @@
1
+ begin
2
+ require "paperclip"
3
+ rescue LoadError
4
+ puts "Neo4jrb::Paperclip requires that you install the Paperclip gem."
5
+ exit
6
+ end
7
+
8
+ ##
9
+ # mongoid criteria uses a different syntax.
10
+ module Paperclip
11
+ module Helpers
12
+ def each_instance_with_attachment(klass, name)
13
+ class_for(klass).unscoped.where("#{name}_file_name".to_sym.ne => nil).each do |instance|
14
+ yield(instance)
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ ##
21
+ # The Mongoid::Paperclip extension
22
+ # Makes Paperclip play nice with the Mongoid ODM
23
+ #
24
+ # Example:
25
+ #
26
+ # class User
27
+ # include Mongoid::Document
28
+ # include Mongoid::Paperclip
29
+ #
30
+ # has_mongoid_attached_file :avatar
31
+ # end
32
+ #
33
+ # The above example is all you need to do. This will load the Paperclip library into the User model
34
+ # and add the "has_mongoid_attached_file" class method. Provide this method with the same values as you would
35
+ # when using "vanilla Paperclip". The first parameter is a symbol [:field] and the second parameter is a hash of options [options = {}].
36
+ #
37
+ # Unlike Paperclip for ActiveRecord, since MongoDB does not use "schema" or "migrations", Mongoid::Paperclip automatically adds the neccesary "fields"
38
+ # to your Model (MongoDB collection) when you invoke the "#has_mongoid_attached_file" method. When you invoke "has_mongoid_attached_file :avatar" it will
39
+ # automatially add the following fields:
40
+ #
41
+ # field :avatar_file_name, :type => String
42
+ # field :avatar_content_type, :type => String
43
+ # field :avatar_file_size, :type => Integer
44
+ # field :avatar_updated_at, :type => DateTime
45
+ # field :avatar_fingerprint, :type => String
46
+ #
47
+ module Neo4jrb
48
+ module Paperclip
49
+
50
+ ##
51
+ # Extends the model with the defined Class methods
52
+ def self.included(base)
53
+ base.extend(ClassMethods)
54
+ end
55
+
56
+ module ClassMethods
57
+
58
+ ##
59
+ # Adds after_commit
60
+ def after_commit(*args, &block)
61
+ options = args.pop if args.last.is_a? Hash
62
+ if options
63
+ case options[:on]
64
+ when :create
65
+ after_create(*args, &block)
66
+ when :update
67
+ after_update(*args, &block)
68
+ when :destroy
69
+ after_destroy(*args, &block)
70
+ else
71
+ after_save(*args, &block)
72
+ end
73
+ else
74
+ after_save(*args, &block)
75
+ end
76
+ end
77
+ ##
78
+ # Adds Neo4jrb::Paperclip's "#has_neo4j_attached_file" class method to the model
79
+ # which includes Paperclip and Paperclip::Glue in to the model. Additionally
80
+ # it'll also add the required fields for Paperclip since MongoDB is schemaless and doesn't
81
+ # have migrations.
82
+ def has_neo4j_attached_file(field, options = {})
83
+ ##
84
+ # Include Paperclip and Paperclip::Glue for compatibility
85
+ unless self.ancestors.include?(::Paperclip)
86
+ include ::Paperclip
87
+ include ::Paperclip::Glue
88
+ end
89
+
90
+ ##
91
+ # Invoke Paperclip's #has_attached_file method and passes in the
92
+ # arguments specified by the user that invoked Neo4jrb::Paperclip#has_neo4j_attached_file
93
+ has_attached_file(field, options)
94
+
95
+ ##
96
+ # Define the necessary collection fields in Mongoid for Paperclip
97
+ property :"#{field}_file_name", :type => String
98
+ property :"#{field}_content_type", :type => String
99
+ property :"#{field}_file_size", :type => Integer
100
+ property :"#{field}_updated_at", :type => DateTime
101
+ property :"#{field}_fingerprint", :type => String
102
+ end
103
+
104
+ ##
105
+ # This method is deprecated
106
+ def has_attached_file(field, options = {})
107
+ raise "Neo4jrb::Paperclip#has_attached_file is deprecated, " +
108
+ "Use 'has_neo4jrb_attached_file' instead"
109
+ end
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+
3
+ Gem::Specification.new do |gem|
4
+
5
+ gem.name = 'paperclip-neo4j'
6
+ gem.version = '1.0.0'
7
+ # gem.platform = "ruby"
8
+ gem.authors = 'Kieran Lafferty'
9
+ gem.email = 'kieran.lafferty@gmail.com'
10
+ gem.homepage = 'https://github.com/KieranLafferty/paperclip-neo4j'
11
+ gem.summary = 'Allow paperclip to work with Neo4j'
12
+ gem.description = 'Allows paperclip to upload files nicely with Neo4j'
13
+
14
+ gem.files = `git ls-files`.split("\n")
15
+ gem.require_path = ["lib"]
16
+
17
+ gem.add_dependency 'paperclip'
18
+
19
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: paperclip-neo4j
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Kieran Lafferty
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: paperclip
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Allows paperclip to upload files nicely with Neo4j
28
+ email: kieran.lafferty@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - README.md
34
+ - lib/neo4jrb_paperclip.rb
35
+ - paperclip-neo4j.gemspec
36
+ homepage: https://github.com/KieranLafferty/paperclip-neo4j
37
+ licenses: []
38
+ metadata: {}
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubyforge_project:
55
+ rubygems_version: 2.2.2
56
+ signing_key:
57
+ specification_version: 4
58
+ summary: Allow paperclip to work with Neo4j
59
+ test_files: []