Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

support direct assignment of upload to contained item

- add assignment method
- store image width and height
  • Loading branch information...
commit 76b2265bb03468071bbfbccaf816c88ef595b385 1 parent bba9295
@sbfaulkner authored
View
9 README.markdown
@@ -33,15 +33,18 @@ Install the gem(s):
## CHANGES
+### 1.2.0
+
+- added assignment method
+- automatically store image width and height for image content types
+
### 1.1.0
- added support for :url option on contains to specify custom url path
## TODO
-- include logic for image width and height
-- better assignment support (i.e. don't require separate assignment of type and data)
-- publish in sequel www/pages/plugins
+- support for assignment other than from rack/sinatra?
- other containment types... e.g. filesystem, s3, git?
## Legal
View
14 lib/sequel_container.rb
@@ -1,4 +1,5 @@
require 'tmpdir'
+require 'image_size'
module Sequel
module Plugins
@@ -41,6 +42,19 @@ def #{object}_url
end
CONTAINED_URL
+ class_eval <<-CONTAINED_ASSIGNMENT, __FILE__, __LINE__ + 1
+ def #{object}=(value)
+ return if value.nil?
+ self.#{object}_type = content_type = value[:type]
+ self.#{object}_data = data = value[:tempfile].read
+ if content_type =~ /^image\\\/.*/
+ size = ImageSize.new(data)
+ self.#{object}_height = size.height
+ self.#{object}_width = size.width
+ end
+ end
+ CONTAINED_ASSIGNMENT
+
class_eval <<-CONTAINED_QUERY, __FILE__, __LINE__ + 1
def #{object}?
!#{object}_type.nil? && !#{object}_type.empty?
View
2  sequel_container.gemspec
@@ -1,7 +1,7 @@
SPEC = Gem::Specification.new do |s|
# identify the gem
s.name = "sequel_container"
- s.version = "1.1.1"
+ s.version = "1.2.0"
s.author = "S. Brent Faulkner"
s.email = "brentf@unwwwired.net"
s.homepage = "http://github.com/sbfaulkner/sequel_container"
Please sign in to comment.
Something went wrong with that request. Please try again.