photofy 0.2.2 → 0.3.1
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.
- checksums.yaml +4 -4
- data/lib/photofy/core.rb +29 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b77a6f420026f5be340cdae42a22fef7dacd205
|
4
|
+
data.tar.gz: ad949b60783be2bf604004e3da3f46d29d72a67c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ab2fac1d174909231104eac8ef113267fcf331c9597ec92b2f93d23d20b3b11120a722e1f7b9b17a6aec9dfd93cb7ed89ddb5ed3a3c3153f7184e89a73bd33d
|
7
|
+
data.tar.gz: 67902b5c082d0ae0ef80b7da58cbe48acc90349671cd9120c457db4aa1ac56757185417cf75a2047b0d973717459e973d5b0c64b09a2f35cdc083891abb5affe
|
data/lib/photofy/core.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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
|
-
#
|
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.
|
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-
|
13
|
+
date: 2014-11-06 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: aws-sdk
|