photofy 0.2.2 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/photofy/core.rb +29 -3
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 01170cecbe978f73d3a6b5f1c9aad979149a89f2
4
- data.tar.gz: dd71457da82f23d3c9121e5ff2c60f86b716309b
3
+ metadata.gz: 7b77a6f420026f5be340cdae42a22fef7dacd205
4
+ data.tar.gz: ad949b60783be2bf604004e3da3f46d29d72a67c
5
5
  SHA512:
6
- metadata.gz: 38b61e941bb7cd41fc9bd4df289c3f0d14860b33e45e8004415b8c1374f2d8b75cbceb31c7c0280681ca1df97eb92d243258f871493dfe3f46eb205be0acf31f
7
- data.tar.gz: 67ac931b404622c32caf7cde528013d9165f8438b61283157a5b0e2bcb459c6095a2078a0057aa355b48fd11ca2e9c900f6b46df7445e14c287ce13db82437ca
6
+ metadata.gz: 6ab2fac1d174909231104eac8ef113267fcf331c9597ec92b2f93d23d20b3b11120a722e1f7b9b17a6aec9dfd93cb7ed89ddb5ed3a3c3153f7184e89a73bd33d
7
+ data.tar.gz: 67902b5c082d0ae0ef80b7da58cbe48acc90349671cd9120c457db4aa1ac56757185417cf75a2047b0d973717459e973d5b0c64b09a2f35cdc083891abb5affe
@@ -28,6 +28,7 @@ module Photofy
28
28
 
29
29
  #Example
30
30
  #photofy(:door)
31
+ #photofy(:door, message: "Some message to show as error when invalid file(w.r.t format) will be used in setter/assignment method")
31
32
  #photofy(:small_door, {parent_photo_field: :door})
32
33
  #photofy(:window, {image_processor: Proc.new { |img| img.scale(25, 25) }})
33
34
  #after_photofy :door, :ventilator, Proc.new { |img| img.scale(25, 25) }
@@ -48,11 +49,21 @@ module Photofy
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 = {})
52
+ (options ||={})[:message] ||= "Not from valid set of allowed file types"
53
+
51
54
  collect_photo_formats(photo_field, options)
52
55
 
56
+ self.validate "validate_#{photo_field}_field"
57
+
53
58
  @photo_fields ||=[]
54
59
  @photo_fields << photo_field
55
60
 
61
+ define_method "validate_#{photo_field}_field" do
62
+ (@photo_fields_errors ||={}).each do |field, message|
63
+ errors.add(field.to_sym, message)
64
+ end
65
+ end
66
+
56
67
  define_method 'initialize_photo_buffers' do
57
68
  @photo_file_buffer ||= {}
58
69
  @photo_file_ofn ||= {}
@@ -117,18 +128,33 @@ module Photofy
117
128
  send('initialize_photo_buffers')
118
129
 
119
130
  if file_upload.class == ActionDispatch::Http::UploadedFile
120
- return false unless self.class.photo_formats[photo_field].include?(File.extname(file_upload.original_filename).downcase)
131
+ unless self.class.photo_formats[photo_field].include?(File.extname(file_upload.original_filename).downcase)
132
+ (@photo_fields_errors ||= {})[photo_field.to_sym] = options[:message]
133
+ return false
134
+ else
135
+ (@photo_fields_errors ||= {}).delete(photo_field.to_sym)
136
+ end
121
137
  @photo_file_buffer[photo_field] = File.read(file_upload.path)
122
138
  @photo_file_ofn[photo_field] = File.basename(file_upload.original_filename)
123
139
 
124
140
  elsif file_upload.class == File
125
- return false unless self.class.photo_formats[photo_field].include?(File.extname(file_upload.path).downcase)
141
+ unless self.class.photo_formats[photo_field].include?(File.extname(file_upload.path).downcase)
142
+ (@photo_fields_errors ||= {})[photo_field.to_sym] = options[:message]
143
+ return false
144
+ else
145
+ (@photo_fields_errors ||= {}).delete(photo_field.to_sym)
146
+ end
126
147
  @photo_file_buffer[photo_field] = file_upload.read
127
148
  @photo_file_ofn[photo_field] = File.basename(file_upload.path)
128
149
 
129
150
  file_upload.rewind
130
151
  elsif file_upload.class == String
131
- #return false unless self.class.photo_formats[photo_field].include?(File.extname(file_upload).downcase)
152
+ #unless self.class.photo_formats[photo_field].include?(File.extname(file_upload).downcase)
153
+ # (@photo_fields_errors ||= {})[photo_field.to_sym] = options[:message]
154
+ # return false
155
+ #else
156
+ # (@photo_fields_errors ||= {}).delete(photo_field.to_sym)
157
+ #end
132
158
  @photo_file_buffer[photo_field] = file_upload
133
159
  #@photo_file_ofn[photo_field] = File.basename(file_upload.path) #As there is nothing like original_file_name for a string :)
134
160
  end
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.2.2
4
+ version: 0.3.1
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: 2014-08-05 00:00:00.000000000 Z
13
+ date: 2014-11-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: aws-sdk