photofy 0.3.1 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +44 -0
  3. data/lib/photofy/core.rb +10 -11
  4. metadata +4 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7b77a6f420026f5be340cdae42a22fef7dacd205
4
- data.tar.gz: ad949b60783be2bf604004e3da3f46d29d72a67c
3
+ metadata.gz: 52ab5edb906bec6b8f3d9dc4d6382740671ca69b
4
+ data.tar.gz: a5f6b32dbdc932e35084c5f3f367b6da561c37a1
5
5
  SHA512:
6
- metadata.gz: 6ab2fac1d174909231104eac8ef113267fcf331c9597ec92b2f93d23d20b3b11120a722e1f7b9b17a6aec9dfd93cb7ed89ddb5ed3a3c3153f7184e89a73bd33d
7
- data.tar.gz: 67902b5c082d0ae0ef80b7da58cbe48acc90349671cd9120c457db4aa1ac56757185417cf75a2047b0d973717459e973d5b0c64b09a2f35cdc083891abb5affe
6
+ metadata.gz: c86f938112502f3f6bf340fea7c36eaf915ca5a530a65ff05509f8dbaa2290cf51418c7705086dbc9be74b8449cccbf816479fd6d6ad2eac7c9e74908174ed4d
7
+ data.tar.gz: fe44b3c6a2f6a6af4dc35a469d0ff0fd3eaa7c68bad31a2b3350028f9f40ed80fce866714a8502a09963ce4a5cc2fa7b1c93b5f0713835190366cffad225b9dc
@@ -0,0 +1,44 @@
1
+ ## Photofy
2
+ A simple ruby gem providing photo fields to rails model
3
+
4
+ ## Installation
5
+ Add this line to your application's Gemfile:
6
+
7
+ `gem 'photofy'`
8
+
9
+ And then execute:
10
+
11
+ `$ bundle`
12
+
13
+ Or install it yourself as:
14
+
15
+ `$ gem install photofy`
16
+
17
+
18
+ ## Usage
19
+ Add photo field(s) to model by adding lines like
20
+
21
+ `photofy(:collage)`
22
+
23
+ > * `collage` : Getter,
24
+ > * `collage?` : Returns true if assignment is having value other than nil else false,
25
+ > * `collage =` : Setter. Acceptable inputs are file upload(ActionDispatch::Http::UploadedFile), file and String(format validation is ignored),
26
+ > * `collage_path` : File path of assignment,
27
+ > * `collage_s3publicpath` : Public aws s3 url provider if (aws s3 is used as storage)
28
+ > * `collage_persisted?` : Gives true if provided file/data is stored on disk,
29
+ > * `collage_store!` : To store provided file/data on disk,
30
+ > * `collage_destroy!` : To destroy stored file/data from disk
31
+
32
+
33
+ `photofy(:collage_sec, {parent_photo_field: :collage})`
34
+ > Automatically creates a collage_sec photo field from :collage parent field
35
+
36
+ `photofy(:stamp, {image_processor: Proc.new { |img| img.scale(25, 25) }})`
37
+ > Process image to scale(refer imagemagick/rmagick for other image manipulations) of 25x25px when image is saved.
38
+
39
+ `after_photofy :collage, :post_card, Proc.new { |img| img.scale(450, 200) }`
40
+ > Creates 'post_card' photo field by taking source from 'collage' and scaling it to 450x200px.
41
+
42
+ Enables aws s3 as backend storage (may be in initializer).
43
+
44
+ `ActiveRecord::Base.photofy_s3_storage({access_key_id: 'xxxxxxxx',secret_access_key: 'xxxxxxxx'}, {bucket: 'test_bucket'})`
@@ -1,13 +1,12 @@
1
1
  module Photofy
2
2
  module Core
3
- attr_accessor :photofied_flag
4
- attr_accessor :photo_fields
5
- attr_accessor :photos_repository
6
- attr_accessor :photo_formats
3
+ cattr_accessor :photofied_flag
4
+ cattr_accessor :photo_fields
5
+ cattr_accessor :photo_formats
7
6
 
8
7
  #Getter to check if model is enabled with file_folder
9
8
  def is_photofied?
10
- @photofied_flag.nil? ? false : @photofied_flag
9
+ @@photofied_flag.nil? ? false : @@photofied_flag
11
10
  end
12
11
 
13
12
  #Generates photo field which can be used to store a post processed image(using rmagick) of parent photo field.
@@ -55,8 +54,8 @@ module Photofy
55
54
 
56
55
  self.validate "validate_#{photo_field}_field"
57
56
 
58
- @photo_fields ||=[]
59
- @photo_fields << photo_field
57
+ @@photo_fields ||=[]
58
+ @@photo_fields << photo_field
60
59
 
61
60
  define_method "validate_#{photo_field}_field" do
62
61
  (@photo_fields_errors ||={}).each do |field, message|
@@ -253,18 +252,18 @@ module Photofy
253
252
  send(:after_save, "#{photo_field}_store!")
254
253
  send(:after_destroy, "#{photo_field}_destroy!")
255
254
 
256
- @photofied_flag = true
255
+ @@photofied_flag = true
257
256
  end
258
257
 
259
258
  def photos_repository
260
- @photos_repository ||= FileUtils.mkdir_p(File.join(Rails.root, "photofy", self.name))[0]
259
+ FileUtils.mkdir_p(File.join(Rails.root, "photofy", self.name.underscore))[0]
261
260
  end
262
261
 
263
262
  #Collects valid photo formats specific to photo fields
264
263
  def collect_photo_formats(photo_field, options)
265
264
  if options.is_a?(Hash)
266
- @photo_formats ||= {}
267
- @photo_formats[photo_field] = options[:formats].is_a?(Array) ? options[:formats].collect { |x| x.starts_with?(".") ? x : ".#{x}" } : [".jpeg", ".jpg", ".gif", ".png", ".bmp"]
265
+ @@photo_formats ||= {}
266
+ @@photo_formats[photo_field] = options[:formats].is_a?(Array) ? options[:formats].collect { |x| x.starts_with?(".") ? x : ".#{x}" } : [".jpeg", ".jpg", ".gif", ".png", ".bmp"]
268
267
  else
269
268
  raise 'InvalidArguments'
270
269
  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.3.1
4
+ version: 0.3.5
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-11-06 00:00:00.000000000 Z
13
+ date: 2014-11-16 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: aws-sdk
@@ -34,23 +34,13 @@ dependencies:
34
34
  version: 1.49.0
35
35
  description: |2
36
36
  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.
37
-
38
- #Generates photo filed from photo_field arguments and provides methods like
39
- #if photo_filed is "collage" then it provides methods on top of it as
40
- #collage >> Getter,
41
- #collage? >> Returns true if assignment is having value other than nil else false,
42
- #collage = >> Setter. Acceptable inputs are file upload(ActionDispatch::Http::UploadedFile), filer handle and String(format validation is ignored),
43
- #collage_path >> File path of assignment,
44
- collage_s3publicpath >> Public aws s3 url provider if (aws s3 is used as storage),
45
- #collage_path_to_write >> File path of assignment to write (specific to writing. Used internally),
46
- #collage_persisted? >> true if provided file/data is stored on disk,
47
- #collage_store! >> to store provided file/data on disk,
48
- #collage_destroy! >> to store destroy stored file/data from disk
37
+ Refer documentation for more help.
49
38
  email: praveen.kumar.sinha@gmail.com
50
39
  executables: []
51
40
  extensions: []
52
41
  extra_rdoc_files: []
53
42
  files:
43
+ - README.md
54
44
  - lib/photofy.rb
55
45
  - lib/photofy/core.rb
56
46
  - lib/photofy/s3methods.rb