polygallery 0.0.7 → 0.0.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 40b6058f68d72353fc34e17997936f3b1096063f
4
- data.tar.gz: df9ed80c23c5ef9ef3bde7a272485e91c4390ca8
3
+ metadata.gz: 72813f5132c7b168ccabc2c5f262be7d29ef1bb2
4
+ data.tar.gz: 200c89fe2ea23f1a2fa0d59c271e31738587071b
5
5
  SHA512:
6
- metadata.gz: 1cfb242774808827303b01187ab2daab6cc620f3d3b20ff5482a22729a2486f60412ef60a1a45d85212724791e58d533ab35ec833c8bb3dfcebe0f5538a7b735
7
- data.tar.gz: 659c46c8f5bd5e817da3c11439b15afbf4e9a251670e0ecb7ae0529309ef3ed5c8b79e98d4cb820912a2309f30c41d280cda77a3002f7b08c971e00878d5b950
6
+ metadata.gz: da025e187f685c868b63417c2ebf3ec40ac57d91139480de6d12e694a07030dc3300db4e4ffab9b511d7dc901063f243524df3617493f9a5065cf54db899de58
7
+ data.tar.gz: 01fbbc77fdf06e12a4091ad9541aadd1b9ffb9512827d8ffc87adb920067b099df0badcf04a9b9e250e6865976cb7d4abfc36a935c907709657234697a3b8655
@@ -5,6 +5,6 @@ module Polygallery::StrongParams
5
5
  end
6
6
 
7
7
  def polygallery_params
8
- [:id, :title, :_destroy, {:photos_attributes => [:photo, :title, :caption, :_destroy]}]
8
+ [:id, :title, :_destroy, {:photos_attributes => [:id, :photo, :title, :caption, :_destroy]}]
9
9
  end
10
10
  end
@@ -8,7 +8,7 @@ module Polygallery
8
8
  },
9
9
  :nested_attributes => {
10
10
  :gallery => {:reject_if => :all_blank},
11
- :photo => {:reject_if => lambda{|attributes| attributes['photo'].nil? }}
11
+ :photo => {:reject_if => lambda{|attributes| attributes['photo'].nil? }, :allow_destroy => true}
12
12
  },
13
13
  :validates => {},
14
14
  :paperclip => {
@@ -1,15 +1,9 @@
1
1
  module Polygallery
2
2
  class Photo < ActiveRecord::Base
3
3
 
4
- belongs_to :gallery, :class_name => 'Polygallery::Gallery'
5
- has_attached_file :photo,
6
- :styles => ->(p) { p.instance.paperclip_settings[:styles] },
7
- :default_url => ->(p) { p.instance.paperclip_settings[:default_url] }
8
- validates_attachment_content_type :photo, :content_type => /\Aimage\/.*\Z/
9
- # validates_attachment_presence :photo # TODO: make this a setting
10
-
11
4
  attr_accessor :photo_to_upload
12
5
  before_save :process_photo_to_upload
6
+ after_initialize :init_attachment
13
7
 
14
8
  def paperclip_settings
15
9
  if gallery.present?
@@ -24,5 +18,14 @@ module Polygallery
24
18
  self.photo = File.open(photo_to_upload) if photo_to_upload.present?
25
19
  end
26
20
 
21
+ def init_attachment
22
+ self.class.belongs_to :gallery, :class_name => 'Polygallery::Gallery'
23
+ self.class.has_attached_file :photo,
24
+ :styles => paperclip_settings[:styles],
25
+ :default_url => paperclip_settings[:default_url]
26
+ self.class.validates_attachment_content_type :photo, :content_type => /\Aimage\/.*\Z/
27
+ # self.class.validates_attachment_presence :photo # TODO: make this a setting
28
+ end
29
+
27
30
  end
28
31
  end
@@ -24,19 +24,11 @@ module Polygallery
24
24
  after_initialize do
25
25
  send("#{title}_settings=".to_sym, settings) if send("#{title}_settings".to_sym).nil?
26
26
  send("build_#{title.to_s}".to_sym) if send(title.to_sym).nil?
27
+ send(title.to_sym).send(:galleryable=, self)
27
28
  end
28
29
  include HasPolygallery::LocalInstanceMethods
29
30
  end
30
31
 
31
- def has_polyphotos(title='photos')
32
- has_many title.to_sym, :class_name => 'Polygallery::Photo'
33
- accepts_nested_attributes_for title.to_sym, Gallery::DEFAULTS[:nested_attributes][:photo] # TODO: get the actual settings object somehow
34
- attr_accessor :photos_to_upload
35
- after_initialize do
36
- send(title.to_sym).build unless send(title.to_sym).any?
37
- end
38
- end
39
-
40
32
  def polygalleries
41
33
  self.reflect_on_all_associations(:has_one).select{|a| a.foreign_key == 'galleryable_id'}.map(&:name)
42
34
  end
@@ -0,0 +1,29 @@
1
+ module Polygallery
2
+ module HasPolyphotos
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ end
7
+
8
+ module ClassMethods
9
+ def has_polyphotos(title='photos', options={})
10
+ has_many title.to_sym, :class_name => 'Polygallery::Photo', :before_add => :set_nest, :dependent => :destroy
11
+ accepts_nested_attributes_for title.to_sym, Gallery::DEFAULTS[:nested_attributes][:photo] # TODO: get the actual settings object somehow
12
+ attr_accessor :photos_to_upload
13
+ after_initialize do
14
+ send(title.to_sym).build unless send(title.to_sym).any?
15
+ # send(title.to_sym).each {|p| p.gallery_id ||= self.id }
16
+ end
17
+ include HasPolyphotos::LocalInstanceMethods
18
+ end
19
+ end
20
+
21
+ module LocalInstanceMethods
22
+ def set_nest(photo)
23
+ photo.gallery ||= self
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ ActiveRecord::Base.send :include, Polygallery::HasPolyphotos
@@ -1,3 +1,3 @@
1
1
  module Polygallery
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
data/lib/polygallery.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "polygallery/engine"
2
2
  require "polygallery/has_polygallery"
3
+ require "polygallery/has_polyphotos"
3
4
  require "polygallery/railtie" if defined? Rails
4
5
 
5
6
  module Polygallery
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polygallery
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - MacKinley Smith
@@ -179,6 +179,7 @@ files:
179
179
  - lib/polygallery/engine.rb
180
180
  - lib/polygallery/glue.rb
181
181
  - lib/polygallery/has_polygallery.rb
182
+ - lib/polygallery/has_polyphotos.rb
182
183
  - lib/polygallery/railtie.rb
183
184
  - lib/polygallery/validators.rb
184
185
  - lib/polygallery/validators/polygallery_presence_validator.rb