photofy 0.1.5 → 0.1.6

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 +7 -0
  2. data/lib/photofy.rb +43 -44
  3. metadata +18 -18
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 49e3ec95765a73b90e67cce0cd7bdb93715e8a29
4
+ data.tar.gz: dacaee79783ed98425ae22cf1cec3bf821f24d60
5
+ SHA512:
6
+ metadata.gz: 05b9c2eb56e049b069f7fe5646fee1189baf554890daaeaadcbe2976a487430ba48089c8e7c9b01f8fd2e5ef8c5e261e671599b641e516b765f23c6674ca41e7
7
+ data.tar.gz: dbfde9014503a0a2cd61a66531000a40121f2489ceee2fec4d66a2752fb86fb5d37e7bee55228373ae2d372490f9f32298b5a21a7353735e890fc98da37ac858
@@ -11,9 +11,8 @@ module Photofy
11
11
 
12
12
  module ClassMethods
13
13
  attr_accessor :photofield_flag
14
- attr_accessor :photo_field
14
+ attr_accessor :photofy_attr
15
15
  attr_accessor :photo_repository
16
- attr_accessor :photo_formats
17
16
 
18
17
  #Generates photo field from photo_field argument which can be used to store a post processed image(using rmagick) of originally uploaded.
19
18
  #Takes two arguments:
@@ -28,18 +27,18 @@ module Photofy
28
27
  #will give a 'portfolio' attribute which on save of main photo filed will scale it to 150 x 250 dimesnions
29
28
  #and also provide 're_photofy_portfolio!'(Proc.new{|img| img.scale(10, 20)}) to perform operation on other user defined events
30
29
  def after_photofy(photo_field, p = Proc.new { |img| puts "Rmagick image: #{img.inspect}" })
31
- define_method "#{photo_field}" do
32
- File.exist?(send("#{photo_field}_path")) ? File.read(send("#{photo_field}_path")) : nil
33
- end
30
+ #define_method "#{photo_field}" do
31
+ # File.exist?(send("#{photo_field}_path")) ? File.read(send("#{photo_field}_path")) : nil
32
+ #end
34
33
 
35
- define_method "#{photo_field}?" do
36
- send("#{photo_field}").nil? ? false : true
37
- end
34
+ #define_method "#{photo_field}?" do
35
+ # send("#{photo_field}").nil? ? false : true
36
+ #end
38
37
 
39
- define_method "#{photo_field}_path" do
40
- directoy_path = FileUtils.mkdir_p File.join(self.class.photo_repository, self.class.photo_field.to_s)
41
- File.join(directoy_path, "#{photo_field}_#{self.send(self.class.primary_key)}.jpg")
42
- end
38
+ #define_method "#{photo_field}_cover_path" do
39
+ # directoy_path = FileUtils.mkdir_p File.join(self.class.photo_repository, photo_field.to_s)
40
+ # File.join(directoy_path, "#{photo_field}_#{self.send(self.class.primary_key)}.jpg")
41
+ #end
43
42
 
44
43
  define_method "re_photofy_#{photo_field}!" do |proc|
45
44
  send("process_n_save_#{photo_field}", proc)
@@ -51,9 +50,8 @@ module Photofy
51
50
 
52
51
  define_method "process_n_save_#{photo_field}" do |proc|
53
52
  begin
54
- mphoto_f = self.class.photo_field
55
- if File.exist?(send("#{mphoto_f}_path"))
56
- img = Magick::Image.read(send("#{mphoto_f}_path")).first # path of Orignal image that has to be worked upon
53
+ if File.exist?(send("#{photo_field}_path"))
54
+ img = Magick::Image.read(send("#{photo_field}_path")).first # path of Orignal image that has to be worked upon
57
55
  img = proc.call(img)
58
56
  img.write(send("#{photo_field}_path"))
59
57
  end
@@ -76,9 +74,9 @@ module Photofy
76
74
  @photofield_flag.nil? ? false : @photofield_flag
77
75
  end
78
76
 
79
- def register_callbacks
80
- send(:after_save, "#{photo_field}_store!")
81
- send(:after_destroy, "#{photo_field}_destroy!")
77
+ def register_callbacks(photo_filed)
78
+ send(:after_save, "#{photo_filed}_store!")
79
+ send(:after_destroy, "#{photo_filed}_destroy!")
82
80
  end
83
81
 
84
82
  #Generates photo filed from photo_field arguments and provides methods like
@@ -92,57 +90,58 @@ module Photofy
92
90
  #collage_destroy! >> to store destroy stored file/data from disk
93
91
  def photofy(photo_filed, options = {})
94
92
  if options.is_a?(Hash)
95
- @photo_formats = options[:formats].is_a?(Array) ? options[:formats].collect { |x| x.starts_with?(".") ? x : ".#{x}" } : [".bmp", ".jpg", ".jpeg"]
93
+ @photofy_attr ||={}
94
+ @photofy_attr[photo_filed] ||={}
95
+ @photofy_attr[photo_filed][:formats] = options[:formats].is_a?(Array) ? options[:formats].collect { |x| x.starts_with?(".") ? x : ".#{x}" } : [".bmp", ".jpg", ".jpeg", '.png']
96
96
  else
97
97
  raise "InvalidArguments"
98
98
  end
99
+ register_callbacks(photo_filed)
99
100
 
100
- @photo_field = photo_filed
101
-
102
- register_callbacks
103
-
104
- define_method "#{@photo_field}" do
105
- @file_buffer.nil? ? (send("#{self.class.photo_field}_persisted?") ? File.read(send("#{self.class.photo_field}_path")) : nil) : @file_buffer
101
+ define_method "#{photo_filed}" do
102
+ self.class.photofy_attr[photo_filed][:file_buffer].nil? ?
103
+ (send("#{photo_filed}_persisted?") ? File.read(send("#{photo_filed}_path")) : nil)
104
+ : self.class.photofy_attr[photo_filed][:file_buffer]
106
105
  end
107
106
 
108
- define_method "#{@photo_field}?" do
109
- send("#{self.class.photo_field}").nil? ? false : true
107
+ define_method "#{photo_filed}?" do
108
+ send("#{photo_filed}").nil? ? false : true
110
109
  end
111
110
 
112
- define_method "#{@photo_field}=" do |file_upload|
111
+ define_method "#{photo_filed}=" do |file_upload|
113
112
  if file_upload.class == ActionDispatch::Http::UploadedFile
114
- return false unless self.class.photo_formats.include?(File.extname(file_upload.original_filename).downcase)
115
- @file_buffer = File.read(file_upload.path)
113
+ return false unless self.class.photofy_attr[photo_filed][:formats].include?(File.extname(file_upload.original_filename).downcase)
114
+ self.class.photofy_attr[photo_filed][:file_buffer] = File.read(file_upload.path)
116
115
  elsif file_upload.class == File
117
- return false unless self.class.photo_formats.include?(File.extname(file_upload.path).downcase)
118
- @file_buffer = file_upload.read
116
+ return false unless self.class.photofy_attr[photo_filed][:formats].include?(File.extname(file_upload.path).downcase)
117
+ self.class.photofy_attr[photo_filed][:file_buffer] = file_upload.read
119
118
  elsif file_upload.class == String
120
119
  #return false unless self.class.photo_formats.include?(File.extname(file_upload).downcase)
121
- @file_buffer = file_upload
120
+ self.class.photofy_attr[photo_filed][:file_buffer] = file_upload
122
121
  end
123
122
  end
124
123
 
125
- define_method "#{@photo_field}_path" do
126
- directoy_path = FileUtils.mkdir_p File.join(self.class.photo_repository, self.class.photo_field.to_s)
124
+ define_method "#{photo_filed}_path" do
125
+ directoy_path = FileUtils.mkdir_p File.join(self.class.photo_repository, photo_filed.to_s)
127
126
  File.join(directoy_path, self.send(self.class.primary_key).to_s)
128
127
  end
129
128
 
130
- define_method "#{@photo_field}_persisted?" do
131
- (@file_buffer.nil? and File.file?(send("#{self.class.photo_field}_path")))
129
+ define_method "#{photo_filed}_persisted?" do
130
+ (self.class.photofy_attr[photo_filed][:file_buffer].nil? and File.file?(send("#{photo_filed}_path")))
132
131
  end
133
132
 
134
- define_method "#{@photo_field}_store!" do
133
+ define_method "#{photo_filed}_store!" do
135
134
  return unless self.class.is_photofield?
136
- unless @file_buffer.nil?
137
- File.open(send("#{self.class.photo_field}_path"), "wb+") { |f| f.puts(@file_buffer) }
138
- @file_buffer = nil
135
+ unless self.class.photofy_attr[photo_filed][:file_buffer].nil?
136
+ File.open(send("#{photo_filed}_path"), "wb+") { |f| f.puts(self.class.photofy_attr[photo_filed][:file_buffer]) }
137
+ self.class.photofy_attr[photo_filed].delete(:file_buffer)
139
138
  end
140
139
  end
141
140
 
142
- define_method "#{@photo_field}_destroy!" do
141
+ define_method "#{photo_filed}_destroy!" do
143
142
  return unless self.class.is_photofield?
144
- @file_buffer = nil
145
- File.delete(send("#{self.class.photo_field}_path")) if File.exist?(send("#{self.class.photo_field}_path"))
143
+ self.class.photofy_attr[photo_filed].delete(:file_buffer)
144
+ File.delete(send("#{photo_filed}_path")) if File.exist?(send("#{photo_filed}_path"))
146
145
  end
147
146
 
148
147
  @photofield_flag = true
metadata CHANGED
@@ -1,26 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: photofy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
5
- prerelease:
4
+ version: 0.1.6
6
5
  platform: ruby
7
6
  authors:
8
7
  - Praveen Kumar Sinha
9
8
  - Annu Yadav
9
+ - sachin choudhary
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-05-18 00:00:00.000000000Z
13
+ date: 2014-03-06 00:00:00.000000000 Z
14
14
  dependencies: []
15
- description: ! "A gem to provide simple method to do file upload of pictures and provides
16
- getter setter methods of it and save on model object commit.\n #Generates photo
17
- filed from photo_field arguments and provides methods like\n #if photo_filed
18
- is \"collage\" then it provides methods on top of it as\n #collage >> Getter,\n
19
- \ #collage = >> Setter. Accepted inputs are file upload(ActionDispatch::Http::UploadedFile),
20
- filer handle and String(no format validation is ignored),\n #collage_path >>
21
- Getter of filepath,\n #collage_persisted? >> true if provided file/data is stored
22
- on disk,\n #collage_store! >> to store provided file/data on disk,\n #collage_destroy!
23
- >> to store destroy stored file/data from disk"
15
+ description: |-
16
+ A gem to provide simple method to do file upload of pictures and provides getter setter methods of it and save on model object commit.
17
+ #Generates photo filed from photo_field arguments and provides methods like
18
+ #if photo_filed is "collage" then it provides methods on top of it as
19
+ #collage >> Getter,
20
+ #collage = >> Setter. Accepted inputs are file upload(ActionDispatch::Http::UploadedFile), filer handle and String(no format validation is ignored),
21
+ #collage_path >> Getter of filepath,
22
+ #collage_persisted? >> true if provided file/data is stored on disk,
23
+ #collage_store! >> to store provided file/data on disk,
24
+ #collage_destroy! >> to store destroy stored file/data from disk
24
25
  email: praveen.kumar.sinha@gmail.com
25
26
  executables: []
26
27
  extensions: []
@@ -29,26 +30,25 @@ files:
29
30
  - lib/photofy.rb
30
31
  homepage: http://praveenkumarsinha.github.io/Photofy
31
32
  licenses: []
33
+ metadata: {}
32
34
  post_install_message:
33
35
  rdoc_options: []
34
36
  require_paths:
35
37
  - lib
36
38
  required_ruby_version: !ruby/object:Gem::Requirement
37
- none: false
38
39
  requirements:
39
- - - ! '>='
40
+ - - ">="
40
41
  - !ruby/object:Gem::Version
41
42
  version: '0'
42
43
  required_rubygems_version: !ruby/object:Gem::Requirement
43
- none: false
44
44
  requirements:
45
- - - ! '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  requirements: []
49
49
  rubyforge_project:
50
- rubygems_version: 1.8.10
50
+ rubygems_version: 2.2.1
51
51
  signing_key:
52
- specification_version: 3
52
+ specification_version: 4
53
53
  summary: Photofy
54
54
  test_files: []