shrine-reform 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 08b9c930726419a6f65bf00450411a0224398f57
4
- data.tar.gz: f2f39944d224330eec594426049cfc477ff3444b
3
+ metadata.gz: 27a8fdd87a1f63696f2738360f6ba77862db4f3e
4
+ data.tar.gz: de85b092c1111cc8ef4df702eef64658adff38b3
5
5
  SHA512:
6
- metadata.gz: 2f5810e424842367f891f37aea4d82c7fce1b108ba095f2442cf6d86565e0188d79ba8929362e22d18bf2984d53b3358d1a428d8ea347b677697b224c13a3117
7
- data.tar.gz: 4095900e4e5bf8069bc43e1816cea0b825a69c3a40ae3a88d7e3170b42e55c2811cf435417e4017a1ec5a90d000f0aa276f5c0433885be9f72a7adbf9a453f8e
6
+ metadata.gz: 223536a013b503893ec801748763725d2f3804b889a9ceee87da3672ab173650ffbfafea8f0eaa9065c963febf77a7adc015d0494107592ada5634e109605f20
7
+ data.tar.gz: 76edc07d55be8e16517e6c84ce3d174d2537681ebd2d47f2e5fbfec2418fccbac1c6456d7260df644425e301d6fdeb61fbe962e800e96a0780a0b5e19945bbb4
data/README.md CHANGED
@@ -11,7 +11,7 @@ gem "shrine", github: "janko-m/shrine"
11
11
 
12
12
  ## Usage
13
13
 
14
- The reform plugin can be loaded globally alongside the activerecord plugin.
14
+ The reform plugin can be loaded globally alongside activerecord plugin.
15
15
 
16
16
  ```rb
17
17
  Shrine.plugin :activerecord
@@ -24,13 +24,10 @@ end
24
24
  ```
25
25
  ```rb
26
26
  class PostForm < Reform::Form
27
- prepend ImageUploader[:image]
27
+ include ImageUploader[:image]
28
28
  end
29
29
  ```
30
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
31
  ## License
35
32
 
36
33
  [MIT](LICENSE.txt)
@@ -8,11 +8,19 @@ class Shrine
8
8
  super
9
9
  end
10
10
 
11
- def prepended(form)
11
+ def included(form)
12
12
  super
13
13
 
14
14
  return unless form < ::Reform::Form
15
15
 
16
+ properties = [
17
+ :"#{@name}",
18
+ :"#{@name}_remote_url",
19
+ :"#{@name}_data_uri",
20
+ :"remove_#{@name}",
21
+ :"cached_#{@name}_data",
22
+ ]
23
+
16
24
  module_eval <<-RUBY, __FILE__, __LINE__ + 1
17
25
  def prepopulate!(*)
18
26
  super
@@ -26,7 +34,11 @@ class Shrine
26
34
  RUBY
27
35
 
28
36
  form.class_eval <<-RUBY, __FILE__, __LINE__ + 1
29
- property :#{@name}, virtual: true
37
+ def self.create_accessors(name, definition)
38
+ return if #{properties}.include?(name)
39
+ super
40
+ end
41
+
30
42
  attr_accessor :#{@name}_data
31
43
 
32
44
  validate do
@@ -36,15 +48,9 @@ class Shrine
36
48
  end
37
49
  RUBY
38
50
 
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
51
+ (properties & instance_methods).each do |name|
52
+ form.send(:property, name, virtual: true)
53
+ end
48
54
  end
49
55
  end
50
56
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = "shrine-reform"
3
- gem.version = "0.1.0"
3
+ gem.version = "0.1.1"
4
4
 
5
5
  gem.required_ruby_version = ">= 2.1"
6
6
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shrine-reform
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Janko Marohnić