shrine-reform 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 08b9c930726419a6f65bf00450411a0224398f57
4
+ data.tar.gz: f2f39944d224330eec594426049cfc477ff3444b
5
+ SHA512:
6
+ metadata.gz: 2f5810e424842367f891f37aea4d82c7fce1b108ba095f2442cf6d86565e0188d79ba8929362e22d18bf2984d53b3358d1a428d8ea347b677697b224c13a3117
7
+ data.tar.gz: 4095900e4e5bf8069bc43e1816cea0b825a69c3a40ae3a88d7e3170b42e55c2811cf435417e4017a1ec5a90d000f0aa276f5c0433885be9f72a7adbf9a453f8e
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Janko Marohnić
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Shrine::Plugins::Reform
2
+
3
+ Provides [Reform] integration for [Shrine].
4
+
5
+ ## Installation
6
+
7
+ ```ruby
8
+ gem "shrine-reform"
9
+ gem "shrine", github: "janko-m/shrine"
10
+ ```
11
+
12
+ ## Usage
13
+
14
+ The reform plugin can be loaded globally alongside the activerecord plugin.
15
+
16
+ ```rb
17
+ Shrine.plugin :activerecord
18
+ Shrine.plugin :reform
19
+ ```
20
+ ```rb
21
+ class Post < ActiveRecord::Base
22
+ include ImageUploader[:image]
23
+ end
24
+ ```
25
+ ```rb
26
+ class PostForm < Reform::Form
27
+ prepend ImageUploader[:image]
28
+ end
29
+ ```
30
+
31
+ Notice that the only difference from ActiveRecord is that a Reform attachment
32
+ module has to be *prepended* instead of included.
33
+
34
+ ## License
35
+
36
+ [MIT](LICENSE.txt)
37
+
38
+ [Reform]: https://github.com/apotonick/reform
39
+ [Shrine]: https://github.com/janko-m/shrine
@@ -0,0 +1,54 @@
1
+ require "reform"
2
+
3
+ class Shrine
4
+ module Plugins
5
+ module Reform
6
+ module AttachmentMethods
7
+ def initialize(*)
8
+ super
9
+ end
10
+
11
+ def prepended(form)
12
+ super
13
+
14
+ return unless form < ::Reform::Form
15
+
16
+ module_eval <<-RUBY, __FILE__, __LINE__ + 1
17
+ def prepopulate!(*)
18
+ super
19
+ @#{@name}_data = model.#{@name}_data
20
+ end
21
+
22
+ def sync(*)
23
+ super
24
+ model.#{@name} = @#{@name}_data if defined?(@#{@name}_data)
25
+ end
26
+ RUBY
27
+
28
+ form.class_eval <<-RUBY, __FILE__, __LINE__ + 1
29
+ property :#{@name}, virtual: true
30
+ attr_accessor :#{@name}_data
31
+
32
+ validate do
33
+ #{@name}_attacher.errors.each do |message|
34
+ errors.add :#{@name}, message
35
+ end
36
+ end
37
+ RUBY
38
+
39
+ form.send(:property, :"#{@name}_remote_url", virtual: true) if instance_methods.include?(:"#{@name}_remote_url")
40
+ form.send(:property, :"#{@name}_data_uri", virtual: true) if instance_methods.include?(:"#{@name}_data_uri")
41
+ form.send(:property, :"remove_#{@name}", virtual: true) if instance_methods.include?(:"remove_#{@name}")
42
+ form.send(:property, :"cached_#{@name}_data", virtual: true) if instance_methods.include?(:"cached_#{@name}_data")
43
+ end
44
+
45
+ def included(form)
46
+ super
47
+ raise Error, "Reform attachment modules have to be prepended instead of included" if form < ::Reform::Form
48
+ end
49
+ end
50
+ end
51
+
52
+ register_plugin(:reform, Reform)
53
+ end
54
+ end
@@ -0,0 +1,24 @@
1
+ Gem::Specification.new do |gem|
2
+ gem.name = "shrine-reform"
3
+ gem.version = "0.1.0"
4
+
5
+ gem.required_ruby_version = ">= 2.1"
6
+
7
+ gem.summary = "Provides Reform integration for Shrine."
8
+ gem.homepage = "https://github.com/janko-m/shrine-reform"
9
+ gem.authors = ["Janko Marohnić"]
10
+ gem.email = ["janko.marohnic@gmail.com"]
11
+ gem.license = "MIT"
12
+
13
+ gem.files = Dir["README.md", "LICENSE.txt", "lib/**/*.rb", "*.gemspec"]
14
+ gem.require_path = "lib"
15
+
16
+ gem.add_dependency "shrine"
17
+
18
+ gem.add_development_dependency "reform"
19
+ gem.add_development_dependency "activerecord", "~> 4.2"
20
+ gem.add_development_dependency "sqlite3"
21
+ gem.add_development_dependency "shrine-memory"
22
+ gem.add_development_dependency "rake"
23
+ gem.add_development_dependency "minitest"
24
+ end
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shrine-reform
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Janko Marohnić
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-05-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: shrine
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
+ - !ruby/object:Gem::Dependency
28
+ name: reform
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activerecord
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sqlite3
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: shrine-memory
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: minitest
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description:
112
+ email:
113
+ - janko.marohnic@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - LICENSE.txt
119
+ - README.md
120
+ - lib/shrine/plugins/reform.rb
121
+ - shrine-reform.gemspec
122
+ homepage: https://github.com/janko-m/shrine-reform
123
+ licenses:
124
+ - MIT
125
+ metadata: {}
126
+ post_install_message:
127
+ rdoc_options: []
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '2.1'
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ requirements: []
141
+ rubyforge_project:
142
+ rubygems_version: 2.5.1
143
+ signing_key:
144
+ specification_version: 4
145
+ summary: Provides Reform integration for Shrine.
146
+ test_files: []
147
+ has_rdoc: