carrierwave-neo4j 2.0.0

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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5507ccab191bfca681514fde9d25ad62c56ff8ab
4
+ data.tar.gz: b849d9e4f6b4b73c7e985454f6f09fc10235e9b5
5
+ SHA512:
6
+ metadata.gz: 0911192167258d8be9d4ecf37857dc056725627706c30b2d853c0b6d4e10b8c38cd9fe3d0d90e0b143cc2ef5a8656fe1f0220d1ccac7aa9eeaa0ece0a39cd3ac
7
+ data.tar.gz: 4fd214ca10c2f7a0950156760d3bf7a25b45dc2b618026a27118184dc47a9603632e1ef577f4c78dccfc57256178ae103ee0137d3f16f1471cd1fad391b7878e
@@ -0,0 +1,8 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ db/*
6
+ .idea
7
+
8
+ .ruby-version
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --backtrace
@@ -0,0 +1 @@
1
+ carrierwave-neo4j
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in carrierwave_neo4j.gemspec
4
+ gemspec
5
+
6
+ gem 'database_cleaner', github: 'dpisarewski/database_cleaner', branch: 'neo4j'
@@ -0,0 +1,21 @@
1
+ ## CarrierWave for Neo4j
2
+
3
+ This gem adds support for Neo4j 3.0+ to CarrierWave, see the CarrierWave documentation for more detailed usage instructions.
4
+
5
+ ### Installation Instructions
6
+
7
+ Add to your Gemfile:
8
+
9
+ ```ruby
10
+ gem 'carrierwave-neo4j', require: 'carrierwave/neo4j', github: 'dpisarewski/carrierwave-neo4j'
11
+ ```
12
+ Use it like this:
13
+
14
+ ```ruby
15
+ class Asset
16
+ include Neo4j::ActiveNode
17
+
18
+ property :attachment, type: String
19
+ mount_uploader :attachment, AttachmentUploader
20
+ end
21
+ ```
@@ -0,0 +1,15 @@
1
+ = CarrierWave for Neo4j
2
+
3
+ This gem adds support for Neo4j to CarrierWave, see the CarrierWave documentation for more detailed usage instructions.
4
+
5
+ == Installation Instructions
6
+
7
+ gem install carrierwave-neo4j
8
+
9
+ Use it like this:
10
+
11
+ require "carrierwave/neo4j"
12
+
13
+ Using bundler:
14
+
15
+ gem "carrierwave-neo4j", :require => "carrierwave/neo4j"
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "carrierwave/neo4j/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "carrierwave-neo4j"
7
+ s.version = CarrierWave::Neo4j::VERSION
8
+ s.authors = ["Rodrigo Navarro"]
9
+ s.email = ["navarro@manapot.com.br"]
10
+ s.homepage = "https://github.com/reu/carrierwave-neo4j"
11
+ s.summary = %q{Neo4j support for Carrierwave}
12
+ s.description = %q{Neo4j support for Carrierwave}
13
+
14
+ s.rubyforge_project = "carrierwave_neo4j"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {spec}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_dependency("activesupport", ">= 3.0" )
22
+ s.add_dependency("neo4j", ">= 1.1")
23
+ s.add_dependency("carrierwave", "~> 0.5")
24
+ s.add_development_dependency("rspec", "~> 2.0")
25
+ end
@@ -0,0 +1,75 @@
1
+ require "carrierwave/neo4j/version"
2
+ require "neo4j"
3
+ require "carrierwave"
4
+ require "carrierwave/validations/active_model"
5
+ require "carrierwave/neo4j/uploader_converter"
6
+ require "active_support/concern"
7
+
8
+ module CarrierWave
9
+ module Neo4j
10
+ extend ActiveSupport::Concern
11
+
12
+ module ClassMethods
13
+ include CarrierWave::Mount
14
+ ##
15
+ # See +CarrierWave::Mount#mount_uploader+ for documentation
16
+ #
17
+ def mount_uploader(column, uploader = nil, options = {}, &block)
18
+ super
19
+
20
+ serialize column, ::CarrierWave::Uploader::Base
21
+
22
+ include CarrierWave::Validations::ActiveModel
23
+
24
+ validates_integrity_of column if uploader_option(column.to_sym, :validate_integrity)
25
+ validates_processing_of column if uploader_option(column.to_sym, :validate_processing)
26
+
27
+ after_save :"store_#{column}!"
28
+ before_save :"write_#{column}_identifier"
29
+ after_destroy :"remove_#{column}!"
30
+
31
+ class_eval <<-RUBY, __FILE__, __LINE__+1
32
+ def #{column}=(new_file)
33
+ column = _mounter(:#{column}).serialization_column
34
+ send(:attribute_will_change!, :#{column})
35
+ super
36
+ end
37
+
38
+ def remote_#{column}_url=(url)
39
+ column = _mounter(:#{column}).serialization_column
40
+ send(:attribute_will_change!, :#{column})
41
+ super
42
+ end
43
+
44
+ def remove_#{column}!
45
+ super
46
+ write_uploader(_mounter(:#{column}).serialization_column, nil)
47
+ end
48
+
49
+ def _mounter(column)
50
+ @_mounters ||= {}
51
+ @_mounters[column] ||= CarrierWave::Mount::Mounter.new(self, column)
52
+ end
53
+
54
+ def read_uploader(name)
55
+ send(:attribute, name.to_s)
56
+ end
57
+
58
+ def write_uploader(name, value)
59
+ send(:attribute=, name.to_s, value)
60
+ end
61
+
62
+ def reload_from_database
63
+ if reloaded = self.class.load_entity(neo_id)
64
+ send(:attributes=, reloaded.attributes.reject{ |k,v| v.is_a?(::CarrierWave::Uploader::Base) })
65
+ end
66
+ reloaded
67
+ end
68
+ RUBY
69
+ end
70
+ end
71
+
72
+ end
73
+ end
74
+
75
+ Neo4j::ActiveNode.send :include, CarrierWave::Neo4j
@@ -0,0 +1,26 @@
1
+ module CarrierWave::Neo4j
2
+ module TypeConverters
3
+ class UploaderConverter
4
+ class << self
5
+ def convert_type
6
+ ::CarrierWave::Uploader::Base
7
+ end
8
+
9
+ def to_db(value)
10
+ value.identifier
11
+ end
12
+
13
+ def to_ruby(value)
14
+ value
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ mod = case Neo4j::VERSION.split('.').first.to_i
22
+ when 3 then Neo4j
23
+ when 4 then Neo4j::Shared
24
+ end
25
+
26
+ mod::TypeConverters.send :include, CarrierWave::Neo4j::TypeConverters
@@ -0,0 +1,5 @@
1
+ module CarrierWave
2
+ module Neo4j
3
+ VERSION = "2.0.0"
4
+ end
5
+ end
Binary file
@@ -0,0 +1,124 @@
1
+ require "spec_helper"
2
+
3
+ def reset_class(uploader = DefaultUploader)
4
+ User.class_eval do
5
+ mount_uploader :image, uploader
6
+ end
7
+ User
8
+ end
9
+
10
+ class User
11
+ include Neo4j::ActiveNode
12
+ property :image, type: String
13
+ end
14
+
15
+ class DefaultUploader < CarrierWave::Uploader::Base; end
16
+
17
+ class PngUploader < CarrierWave::Uploader::Base
18
+ def extension_white_list
19
+ %w(png)
20
+ end
21
+ end
22
+
23
+ class ProcessingErrorUploader < CarrierWave::Uploader::Base
24
+ process :end_on_an_era
25
+
26
+ def end_on_an_era
27
+ raise CarrierWave::ProcessingError, "Bye Tarja"
28
+ end
29
+ end
30
+
31
+ describe CarrierWave::Neo4j do
32
+ let(:user_class) { reset_class }
33
+ let(:user_class_png) { reset_class(PngUploader) }
34
+ let(:user_class_error) { reset_class(ProcessingErrorUploader) }
35
+ let(:user) { user_class.new }
36
+
37
+ after do
38
+ User.destroy_all
39
+ end
40
+
41
+ describe "#image" do
42
+ let(:record) { user_class.new }
43
+ subject { record.image }
44
+
45
+ context "when nothing is assigned" do
46
+ it { should be_blank }
47
+ end
48
+
49
+ context "when an empty string is assigned" do
50
+ before do
51
+ record.image = ""
52
+ record.save
53
+ record.reload
54
+ end
55
+
56
+ it { should be_blank }
57
+ end
58
+
59
+ context "when a filename is stored" do
60
+ before do
61
+ record.image = File.open(file_path("tarja.jpg"))
62
+ record.save
63
+ record.reload
64
+ end
65
+
66
+ it { should be_an_instance_of DefaultUploader }
67
+ its(:current_path) { should == public_path("uploads/tarja.jpg") }
68
+ end
69
+ end
70
+
71
+ describe "#save" do
72
+ context "when remove_image? is true" do
73
+ let(:record) { user_class.new }
74
+
75
+ before do
76
+ record.image = File.open(file_path("tarja.jpg"))
77
+ record.save
78
+
79
+ record.remove_image = true
80
+ record.save
81
+ record.reload
82
+ end
83
+
84
+ subject { record }
85
+
86
+ its(:image) { should be_blank }
87
+ end
88
+
89
+ context "when validating integrity" do
90
+ subject do
91
+ user = user_class_png.new
92
+ user.image = File.open(file_path("tarja.jpg"))
93
+ user
94
+ end
95
+
96
+ it { should_not be_valid }
97
+ end
98
+
99
+ context "when validating processing" do
100
+ subject do
101
+ user = user_class_error.new
102
+ user.image = File.open(file_path("tarja.jpg"))
103
+ user
104
+ end
105
+
106
+ it { should_not be_valid }
107
+ end
108
+ end
109
+
110
+ describe "#destroy" do
111
+ let(:record) { user_class.new }
112
+
113
+ before do
114
+ record.image = File.open(file_path("tarja.jpg"))
115
+ record.save
116
+ end
117
+
118
+ it "also destroys the image" do
119
+ expect { record.destroy }.to change {
120
+ File.exist? public_path("uploads/tarja.jpg")
121
+ }.from(true).to(false)
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,29 @@
1
+ require "rubygems"
2
+ require "bundler/setup"
3
+ require "rspec"
4
+
5
+ require "carrierwave"
6
+ require "carrierwave/neo4j"
7
+ require "database_cleaner"
8
+
9
+ def file_path(*paths)
10
+ File.expand_path(File.join(File.dirname(__FILE__), "fixtures", *paths))
11
+ end
12
+
13
+ def public_path(*paths)
14
+ File.expand_path(File.join(File.dirname(__FILE__), "public", *paths))
15
+ end
16
+
17
+ CarrierWave.root = public_path
18
+ DatabaseCleaner[:neo4j, connection: {type: :server_db, path: 'http://localhost:7475'}].strategy = :transaction
19
+
20
+ RSpec.configure do |config|
21
+ config.before(:each) do
22
+ DatabaseCleaner.start
23
+ end
24
+
25
+ config.after(:each) do
26
+ DatabaseCleaner.clean
27
+ end
28
+ end
29
+
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: carrierwave-neo4j
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Rodrigo Navarro
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: neo4j
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '1.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '1.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: carrierwave
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.5'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.0'
69
+ description: Neo4j support for Carrierwave
70
+ email:
71
+ - navarro@manapot.com.br
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".ruby-gemset"
79
+ - Gemfile
80
+ - README.md
81
+ - README.rdoc
82
+ - Rakefile
83
+ - carrierwave-neo4j.gemspec
84
+ - lib/carrierwave/neo4j.rb
85
+ - lib/carrierwave/neo4j/uploader_converter.rb
86
+ - lib/carrierwave/neo4j/version.rb
87
+ - spec/fixtures/tarja.jpg
88
+ - spec/neo4j_spec.rb
89
+ - spec/spec_helper.rb
90
+ homepage: https://github.com/reu/carrierwave-neo4j
91
+ licenses: []
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project: carrierwave_neo4j
109
+ rubygems_version: 2.4.3
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: Neo4j support for Carrierwave
113
+ test_files: []
114
+ has_rdoc: