neo4jrb-paperclip 0.0.1-jruby

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,43 @@
1
+ Neo4jrb::Paperclip - Making Paperclip play nice with Neo4j.rb
2
+ ================================================================
3
+
4
+ This gem is based on [mongoid-paperclip 0.0.4](https://github.com/meskyanichi/mongoid-paperclip).
5
+
6
+ As the title suggests: `Mongoid::Paperclip` makes it easy to hook up [Paperclip](https://github.com/thoughtbot/paperclip) with [Neo4j.rb](https://github.com/andreasronge/neo4j).
7
+
8
+ This is actually easier and faster to set up than when using Paperclip and the ActiveRecord ORM.
9
+ This example assumes you are using **Ruby on Rails 3** and **Bundler**. However it doesn't require either.
10
+
11
+
12
+ Setting it up
13
+ -------------
14
+
15
+ 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`.*
16
+
17
+ **Rails.root/Gemfile - Just define the following:**
18
+
19
+ gem "neo4jrb-paperclip", :require => "neo4jrb_paperclip"
20
+ gem "aws-s3", :require => "aws/s3"
21
+
22
+ Next let's assume we have a User model and we want to allow our users to upload an avatar.
23
+
24
+ **Rails.root/app/models/user.rb - include the Neo4jrb::Paperclip module and invoke the provided class method**
25
+
26
+ class User < Neo4j::Rails::Model
27
+ include Neo4jrb::Paperclip
28
+
29
+ has_neo4jrb_attached_file :avatar
30
+ end
31
+
32
+
33
+ That's it
34
+ --------
35
+
36
+ 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.
37
+
38
+ Related Links
39
+ ------------
40
+
41
+ [mongoid-paperclip](https://github.com/meskyanichi/mongoid-paperclip)
42
+ [Neo4j.rb](https://github.com/andreasronge/neo4j)
43
+ [Paperclip](https://github.com/thoughtbot/paperclip)
@@ -0,0 +1,90 @@
1
+ # encoding: utf-8
2
+
3
+ begin
4
+ require "paperclip"
5
+ rescue LoadError
6
+ puts "Neo4jrb::Paperclip requires that you install the Paperclip gem."
7
+ exit
8
+ end
9
+
10
+ ##
11
+ # Use Neo4j's logger.
12
+ module Paperclip
13
+ class << self
14
+ def logger
15
+ Neo4j::Config[:logger]
16
+ end
17
+ end
18
+ end
19
+
20
+
21
+ ##
22
+ # The Neo4jrb::Paperclip extension
23
+ # Makes Paperclip play nice with the Neo4j Models
24
+ #
25
+ # Example:
26
+ #
27
+ # class User <
28
+ # include Neo4jrb::Paperclip
29
+ #
30
+ # has_neo4jrb_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_neo4jrb_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", Neo4jrb::Paperclip automatically adds the neccesary "fields"
38
+ # to your Model (MongoDB collection) when you invoke the "#has_neo4jrb_attached_file" method. When you invoke "has_neo4jrb_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 => Fixnum
44
+ # field :avatar_updated_at, :type => DateTime
45
+ #
46
+ module Neo4jrb
47
+ module Paperclip
48
+
49
+ ##
50
+ # Extends the model with the defined Class methods
51
+ def self.included(base)
52
+ base.extend(ClassMethods)
53
+ end
54
+
55
+ module ClassMethods
56
+
57
+ ##
58
+ # Adds Neo4jrb::Paperclip's "#has_neo4jrb_attached_file" class method to the model
59
+ # which includes Paperclip and Paperclip::Glue in to the model. Additionally
60
+ # it'll also add the required fields for Paperclip since MongoDB is schemaless and doesn't
61
+ # have migrations.
62
+ def has_neo4jrb_attached_file(field, options = {})
63
+
64
+ ##
65
+ # Include Paperclip and Paperclip::Glue for compatibility
66
+ include ::Paperclip
67
+ include ::Paperclip::Glue
68
+
69
+ ##
70
+ # Invoke Paperclip's #has_attached_file method and passes in the
71
+ # arguments specified by the user that invoked Neo4jrb::Paperclip#has_neo4jrb_attached_file
72
+ has_attached_file(field, options)
73
+
74
+ ##
75
+ # Define the necessary collection fields in Neo4jrb for Paperclip
76
+ property :"#{field}_file_name", :type => String
77
+ property :"#{field}_content_type", :type => String
78
+ property :"#{field}_file_size", :type => Fixnum
79
+ property :"#{field}_updated_at", :type => DateTime
80
+ end
81
+
82
+ ##
83
+ # This method is deprecated
84
+ def has_attached_file(field, options = {})
85
+ raise "Neo4jrb::Paperclip#has_attached_file is deprecated, " +
86
+ "Use 'has_neo4jrb_attached_file' instead"
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+
3
+ Gem::Specification.new do |gem|
4
+
5
+ gem.name = 'neo4jrb-paperclip'
6
+ gem.version = '0.0.1'
7
+ gem.platform = "jruby"
8
+ gem.authors = 'Leo Lou'
9
+ gem.email = 'louyuhong@gmail.com'
10
+ gem.homepage = 'https://github.com/l4u/neo4jrb-paperclip'
11
+ gem.summary = 'Neo4jrb::Paperclip enables you to use Paperclip with Neo4j.rb'
12
+ gem.description = 'Neo4jrb::Paperclip enables you to use Paperclip with Neo4j.rb'
13
+
14
+ gem.files = %x[git ls-files].split("\n")
15
+ gem.test_files = %x[git ls-files -- {spec}/*].split("\n")
16
+ gem.require_path = 'lib'
17
+
18
+ gem.add_dependency 'paperclip', ['~> 2.3.6']
19
+
20
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: neo4jrb-paperclip
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: jruby
7
+ authors:
8
+ - Leo Lou
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-03-17 00:00:00 +08:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: paperclip
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ~>
23
+ - !ruby/object:Gem::Version
24
+ version: 2.3.6
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ description: Neo4jrb::Paperclip enables you to use Paperclip with Neo4j.rb
28
+ email: louyuhong@gmail.com
29
+ executables: []
30
+
31
+ extensions: []
32
+
33
+ extra_rdoc_files: []
34
+
35
+ files:
36
+ - README.md
37
+ - lib/neo4jrb_paperclip.rb
38
+ - neo4jrb-paperclip.gemspec
39
+ has_rdoc: true
40
+ homepage: https://github.com/l4u/neo4jrb-paperclip
41
+ licenses: []
42
+
43
+ post_install_message:
44
+ rdoc_options: []
45
+
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: "0"
60
+ requirements: []
61
+
62
+ rubyforge_project:
63
+ rubygems_version: 1.5.1
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: Neo4jrb::Paperclip enables you to use Paperclip with Neo4j.rb
67
+ test_files: []
68
+