Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

set_table_name ist deprecated

  • Loading branch information...
commit 023e0af4fd570edfd9bf89e955d4f8cb4dc0ac90 1 parent bf6b806
@TeaMoe authored
View
42 lib/digineo/image/base.rb
@@ -2,9 +2,9 @@
module Digineo
module Image
class Base < ActiveRecord::Base
- set_table_name :digineo_images
+ self.table_name = :digineo_images
store_full_sti_class = true
-
+
belongs_to :parentmodel, :polymorphic => true
belongs_to :gallery, :class_name => "Digineo::ImageGallery"
belongs_to :image_type, :class_name => "Digineo::ImageType"
@@ -12,15 +12,15 @@ class Base < ActiveRecord::Base
attr_accessor :file_url
attr_accessor :gallery_name
attr_accessor :image_type_name
-
+
before_create :should_be_avatar?
before_destroy :unset_avatar if :avatar
-
+
extend HasImages::Scope
-
+
scope_method :not_avatar, :conditions => "avatar=0"
scope_method :without_gallery, :conditions => "gallery_id IS NULL"
-
+
scope_method :image_type, lambda { |*types|
{ :conditions => "image_type_id IN (" + types.collect do |type|
begin
@@ -30,40 +30,40 @@ class Base < ActiveRecord::Base
end
end.compact.join(",") + ")"}
}
-
+
has_attached_file :file
-
+
after_save :set_gallery, :set_image_type
-
+
validates_attachment_presence :file, :unless => :file_url_provided?, :on => :create
validates_presence_of :parentmodel
before_validation :download_remote_file, :if => :file_url_provided?
-
+
validates_presence_of :file_remote_url, :if => :file_url_provided?, :message => 'is invalid or inaccessible'
-
+
# sets the avatar flag on this image
def set_avatar
parentmodel.avatar.unset_avatar if parentmodel.avatar
update_attribute(:avatar, true)
end
-
+
# removes avatar flag
def unset_avatar
update_attribute(:avatar, false)
end
-
+
def set_gallery
return if gallery_id or gallery_name.to_s.empty?
self.gallery_id = parentmodel.find_or_create_gallery(gallery_name).id
save
end
-
+
def set_image_type
return if image_type_id or image_type_name.to_s.empty?
self.image_type_id = ImageType.find_or_create_by_name(image_type_name).id
save
end
-
+
# def crop(params = {:style => :original})
#
# args = [params[:x1].to_i, params[:y1].to_i, params[:width].to_i, params[:height].to_i]
@@ -84,23 +84,23 @@ def set_image_type
# true
# end
# end
-
+
private
-
+
def should_be_avatar?
self.avatar = !parentmodel.avatar
true # returns true because it's called by before_create
end
-
+
def file_url_provided?
!self.file_url.blank?
end
-
+
def download_remote_file
self.file = do_download_remote_file
self.file_remote_url = file_url
end
-
+
def do_download_remote_file
io = open(URI.parse(file_url))
def io.original_filename; base_uri.path.split('/').last; end
@@ -109,4 +109,4 @@ def io.original_filename; base_uri.path.split('/').last; end
end
end
end
-end
View
13 lib/digineo/image_gallery.rb
@@ -1,17 +1,16 @@
class Digineo::ImageGallery < ActiveRecord::Base
-
- set_table_name :digineo_image_galleries
-
+
+ self.table_name = :digineo_image_galleries
+
belongs_to :parentmodel, :polymorphic => true
has_many :images, :class_name => 'Digineo::Image::Base', :foreign_key => :gallery_id
has_one :avatar, :foreign_key => :gallery_id, :class_name => "Digineo::Image::Base"
-
-
+
validates_presence_of :name
validates_uniqueness_of :name, :scope => [:parentmodel_id, :parentmodel_type]
-
+
def create_image_by_url(url, image_type = nil)
images.create!(:file_url => url, :parentmodel => parentmodel, :image_type => image_type)
end
-
+
end
View
15 lib/digineo/image_type.rb
@@ -1,14 +1,13 @@
-class Digineo::ImageType < ActiveRecord::Base
- set_table_name :digineo_image_types
-
+class Digineo::ImageType < ActiveRecord::Base
+ self.table_name = :digineo_image_types
+
has_many :images, :class_name => "Digineo::Image::Base"
-
+
validates_presence_of :name
validates_uniqueness_of :name
-
-end
+end
class Digineo::ImageType::Exception < Exception
-
-end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.