Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ksylvest committed Jun 27, 2014
1 parent 2bebd5e commit 27b82ab
Show file tree
Hide file tree
Showing 44 changed files with 191 additions and 404 deletions.
14 changes: 4 additions & 10 deletions Gemfile
@@ -1,19 +1,13 @@
source 'https://rubygems.org'

gemspec

gem 'rails'

gem 'haml-rails'
gem 'jquery-rails'

gem 'sass-rails'
gem 'coffee-rails'

gem 'bootstrap-sass'

gem 'jruby-openssl', :platform => :jruby
gem 'activerecord-jdbcsqlite3-adapter', :platform => :jruby
gem 'sqlite3', :platform => :ruby

gem 'coveralls', :require => false
gem 'jruby-openssl', platform: :jruby
gem 'activerecord-jdbcsqlite3-adapter', platform: :jruby
gem 'sqlite3', platform: :ruby
gem 'coveralls', require: false
56 changes: 28 additions & 28 deletions Gemfile.lock
Expand Up @@ -9,27 +9,27 @@ PATH
GEM
remote: https://rubygems.org/
specs:
actionmailer (4.1.1)
actionpack (= 4.1.1)
actionview (= 4.1.1)
actionmailer (4.1.2)
actionpack (= 4.1.2)
actionview (= 4.1.2)
mail (~> 2.5.4)
actionpack (4.1.1)
actionview (= 4.1.1)
activesupport (= 4.1.1)
actionpack (4.1.2)
actionview (= 4.1.2)
activesupport (= 4.1.2)
rack (~> 1.5.2)
rack-test (~> 0.6.2)
actionview (4.1.1)
activesupport (= 4.1.1)
actionview (4.1.2)
activesupport (= 4.1.2)
builder (~> 3.1)
erubis (~> 2.7.0)
activemodel (4.1.1)
activesupport (= 4.1.1)
activemodel (4.1.2)
activesupport (= 4.1.2)
builder (~> 3.1)
activerecord (4.1.1)
activemodel (= 4.1.1)
activesupport (= 4.1.1)
activerecord (4.1.2)
activemodel (= 4.1.2)
activesupport (= 4.1.2)
arel (~> 5.0.0)
activesupport (4.1.1)
activesupport (4.1.2)
i18n (~> 0.6, >= 0.6.9)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
Expand All @@ -40,7 +40,7 @@ GEM
rake
thor (>= 0.14.0)
arel (5.0.1.20140414130214)
bootstrap-sass (3.1.1.1)
bootstrap-sass (3.2.0.0)
sass (~> 3.2)
builder (3.2.2)
coffee-rails (4.0.1)
Expand All @@ -59,14 +59,14 @@ GEM
docile (1.1.5)
erubis (2.7.0)
excon (0.37.0)
execjs (2.2.0)
execjs (2.2.1)
fog (1.22.1)
fog-brightbox
fog-core (~> 1.22)
fog-json
ipaddress (~> 0.5)
nokogiri (~> 1.5, >= 1.5.11)
fog-brightbox (0.1.0)
fog-brightbox (0.1.1)
fog-core (~> 1.22)
fog-json
inflecto
Expand Down Expand Up @@ -112,19 +112,19 @@ GEM
rack (1.5.2)
rack-test (0.6.2)
rack (>= 1.0)
rails (4.1.1)
actionmailer (= 4.1.1)
actionpack (= 4.1.1)
actionview (= 4.1.1)
activemodel (= 4.1.1)
activerecord (= 4.1.1)
activesupport (= 4.1.1)
rails (4.1.2)
actionmailer (= 4.1.2)
actionpack (= 4.1.2)
actionview (= 4.1.2)
activemodel (= 4.1.2)
activerecord (= 4.1.2)
activesupport (= 4.1.2)
bundler (>= 1.3.0, < 2.0)
railties (= 4.1.1)
railties (= 4.1.2)
sprockets-rails (~> 2.0)
railties (4.1.1)
actionpack (= 4.1.1)
activesupport (= 4.1.1)
railties (4.1.2)
actionpack (= 4.1.2)
activesupport (= 4.1.2)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (10.3.2)
Expand Down
65 changes: 18 additions & 47 deletions lib/attached.rb
@@ -1,37 +1,20 @@
require 'attached/definition'
require 'attached/attachment'
require 'attached/railtie'


module Attached


def self.mock!
Fog.mock!
end


def self.included(base)
base.extend ClassMethods
base.class_attribute :attached_options
end


module Definition
def attachment(*args)
options = args.extract_options!

args.each do |name|
column("#{name}_identifier", :string, options)
column("#{name}_extension", :string, options)
column("#{name}_size", :integer, options)
end
end
end


module ClassMethods


# Add an attachment to a class.
#
# Options:
Expand All @@ -43,8 +26,8 @@ module ClassMethods
# Usage:
#
# has_attached :video
# has_attached :video, :storage => :aws
# has_attached :video, styles => { :mov => { :size => "480p", :format => "mov" } }
# has_attached :video, storage: :aws
# has_attached :video, styles: { mov: { size: "480p", format: "mov" } }

def has_attached(name, options = {})

Expand Down Expand Up @@ -94,7 +77,6 @@ def has_attached(name, options = {})

end


# Validates an attached size in a specified range or minimum and maximum.
#
# Options:
Expand All @@ -106,9 +88,9 @@ def has_attached(name, options = {})
#
# Usage:
#
# validates_attached_size :avatar, :range => 10.megabytes .. 20.megabytes
# validates_attached_size :avatar, :minimum => 10.megabytes, :maximum => 20.megabytes
# validates_attached_size :avatar, :message => "size must be between :minimum and :maximum bytes"
# validates_attached_size :avatar, range: 10.megabytes .. 20.megabytes
# validates_attached_size :avatar, minimum: 10.megabytes, maximum: 20.megabytes
# validates_attached_size :avatar, message: "size must be between :minimum and :maximum bytes"

def validates_attached_size(name, options = {})

Expand All @@ -129,12 +111,11 @@ def validates_attached_size(name, options = {})
message.gsub!(/:minimum/, number_to_size(minimum)) unless minimum == zero
message.gsub!(/:maximum/, number_to_size(maximum)) unless maximum == infi

validates_inclusion_of :"#{name}_size", :in => range, :message => message,
:if => options[:if], :unless => options[:unless]
validates_inclusion_of :"#{name}_size", in: range, message: message,
if: options[:if], unless: options[:unless]

end


# Validates an attached extension in a specified set.
#
# Options:
Expand All @@ -143,11 +124,11 @@ def validates_attached_size(name, options = {})
#
# Usage:
#
# validates_attached_extension :avatar, :is => 'png'
# validates_attached_extension :avatar, :in => %w(png jpg)
# validates_attached_extension :avatar, :in => [:png, :jpg]
# validates_attached_extension :avatar, :in => %w(png jpg), :message => "extension must be :in"
# validates_attached_extension :avatar, :in => %w(png jpg), :message => "extension must be :in"
# validates_attached_extension :avatar, is: 'png'
# validates_attached_extension :avatar, in: %w(png jpg)
# validates_attached_extension :avatar, in: [:png, :jpg]
# validates_attached_extension :avatar, in: %w(png jpg), message: "extension must be :in"
# validates_attached_extension :avatar, in: %w(png jpg), message: "extension must be :in"

def validates_attached_extension(name, options = {})

Expand All @@ -158,11 +139,10 @@ def validates_attached_extension(name, options = {})

range = options[:in].map { |element| ".#{element}" }

validates_inclusion_of :"#{name}_extension", :in => range, :message => message,
:if => options[:if], :unless => options[:unless]
validates_inclusion_of :"#{name}_extension", in: range, message: message,
if: options[:if], unless: options[:unless]
end


# Validates that an attachment is included.
#
# Options:
Expand All @@ -172,22 +152,20 @@ def validates_attached_extension(name, options = {})
# Usage:
#
# validates_attached_presence :avatar
# validates_attached_presence :avatar, :message => "must be attached"
# validates_attached_presence :avatar, message: "must be attached"

def validates_attached_presence(name, options = {})

message = options[:message]
message ||= "must be attached"

validates_presence_of :"#{name}_identifier", :message => message,
:if => options[:if], :unless => options[:unless]
validates_presence_of :"#{name}_identifier", message: message,
if: options[:if], unless: options[:unless]

end


private


# Convert a number to a human readable size.
#
# Usage:
Expand Down Expand Up @@ -215,13 +193,10 @@ def number_to_size(number, options = {})
"#{number} #{unit}"
end


end


module InstanceMethods


# Create or access attachment.
#
# Usage:
Expand All @@ -233,7 +208,6 @@ def attachment_for(name)
@_attached_attachments[name] ||= Attachment.new(name, self, self.class.attached_options[name])
end


# Log and save all attached (using specified storage).
#
# Usage:
Expand All @@ -248,7 +222,6 @@ def save_attached
end
end


# Log and destroy all attached (using specified storage).
#
# Usage:
Expand All @@ -263,8 +236,6 @@ def destroy_attached
end
end


end


end

0 comments on commit 27b82ab

Please sign in to comment.