photofy 0.6.1 → 0.6.2

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/photofy/core.rb +19 -1
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a52ce7b29743b3206b06d5f9e4cc7675942410a7
4
- data.tar.gz: c9d927a0fe18e9cdf4a504468a76560c69a28e3c
3
+ metadata.gz: 3eeb46e4f59275c262df5d229ea5ed24fe66e35e
4
+ data.tar.gz: 5fd89fe9e0c5f893766f625963448037f6a07776
5
5
  SHA512:
6
- metadata.gz: 83f4520d79373a4986eedfd27ee7936d1a692a808e89d59a6d233bd7607389784fa66df1e062826a8401857b0eb6b9f3545e124536abf45a18c7502946dc405f
7
- data.tar.gz: 4d42053a929877b537be04c3265847540b101e9a84a7481c71533e77257a8ae9857125ba8ca69d6ebd0a63a413cf75122c4ddf620c41577bfbe71231c026bc16
6
+ metadata.gz: 88da2540accc9bf35010a2b5310f67e09a527f476100e97f935d823f92b2e8999aebeb30525cd1c78debc7b5c4f8f7e08b274167e476f34dfaabca600925c1f4
7
+ data.tar.gz: e4bc8ed743d5926e505c1d1d0a29fb780c139e6d0630e67a9d2f3b32f0a3bc54842dfbf1795e5c7e1a55012398e8a5bbc931640afb12a60a02a9639528e38eb0
@@ -43,12 +43,13 @@ module Photofy
43
43
  #collage_persisted? >> true if provided file/data is stored on disk,
44
44
  #collage_store! >> to store provided file/data on disk,
45
45
  #collage_destroy! >> to store destroy stored file/data from disk
46
+ #collage_mark_for_deletion >> to mark delete which will be carried on after save
46
47
  #
47
48
  #Options:
48
49
  #image_processor: a proc for image processing like Proc.new { |img| img.scale(25, 25) }
49
50
  #parent_photo_field: a parent photo field name to be used as source
50
51
  def photofy(photo_field, options = {})
51
- (options ||={})[:message] ||= "Not from valid set of allowed file types"
52
+ (options ||={})[:message] ||= 'not from valid set of allowed file types'
52
53
 
53
54
  collect_photo_formats(photo_field, options)
54
55
 
@@ -66,6 +67,7 @@ module Photofy
66
67
  define_method 'initialize_photo_buffers' do
67
68
  @photo_file_buffer ||= {}
68
69
  @photo_file_ofn ||= {}
70
+ @photo_file_delete_marker ||= {}
69
71
  end
70
72
 
71
73
  define_method "#{photo_field}_path" do
@@ -262,7 +264,23 @@ module Photofy
262
264
  end
263
265
  end
264
266
 
267
+ # to mark photo_field for deletion upon save(highest precedence than setter)
268
+ define_method "#{photo_field}_mark_for_deletion" do
269
+ (@photo_file_delete_marker ||= {})[photo_field.to_sym] = true
270
+ end
271
+
272
+ # Deletes all photo_fields marked for deletion
273
+ define_method 'delete_marked_photo_fields' do
274
+ (@photo_file_delete_marker ||= {}).each do |photo_field, marked|
275
+ if marked
276
+ send("#{photo_field}_destroy!")
277
+ @photo_file_delete_marker[photo_field] = false
278
+ end
279
+ end
280
+ end
281
+
265
282
  send(:after_save, "#{photo_field}_store!".to_sym)
283
+ send(:after_save, :delete_marked_photo_fields) #Makes it last ro execute among callbacks hence it deletes (with utmost importance)
266
284
  send(:after_destroy, "#{photo_field}_destroy!".to_sym)
267
285
 
268
286
  @@photofied_flag = true
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: photofy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Praveen Kumar Sinha
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-09-07 00:00:00.000000000 Z
13
+ date: 2017-09-15 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description: |2
16
16
  A simple gem to add accessors on rails models for file upload of pictures/assets (which will be persisted on remote media's disk on object save).