Module: Paperclip::Helpers
- Included in:
- Paperclip
- Defined in:
- lib/paperclip/helpers.rb
Instance Method Summary (collapse)
- - (Object) check_for_url_clash(name, url, klass)
- - (Object) class_for(class_name)
- - (Object) configure {|_self| ... }
-
- (Object) each_instance_with_attachment(klass, name)
Find all instances of the given Active Record model klass with attachment name.
- - (Object) interpolates(key, &block)
- - (Object) reset_duplicate_clash_check!
-
- (Object) run(cmd, arguments = "", local_options = {})
The run method takes the name of a binary to run, the arguments to that binary and some options:.
Instance Method Details
- (Object) check_for_url_clash(name, url, klass)
46 47 48 49 50 51 52 53 |
# File 'lib/paperclip/helpers.rb', line 46 def check_for_url_clash(name,url,klass) @names_url ||= {} default_url = url || Attachment.[:url] if @names_url[name] && @names_url[name][:url] == default_url && @names_url[name][:class] != klass && @names_url[name][:url] !~ /:class/ log("Duplicate URL for #{name} with #{default_url}. This will clash with attachment defined in #{@names_url[name][:class]} class") end @names_url[name] = {:url => default_url, :class => klass} end |
- (Object) class_for(class_name)
40 41 42 43 44 |
# File 'lib/paperclip/helpers.rb', line 40 def class_for(class_name) class_name.split('::').inject(Object) do |klass, partial_class_name| klass.const_defined?(partial_class_name) ? klass.const_get(partial_class_name, false) : klass.const_missing(partial_class_name) end end |
- (Object) configure {|_self| ... }
3 4 5 |
# File 'lib/paperclip/helpers.rb', line 3 def configure yield(self) if block_given? end |
- (Object) each_instance_with_attachment(klass, name)
Find all instances of the given Active Record model klass with attachment name. This method is used by the refresh rake tasks.
34 35 36 37 38 |
# File 'lib/paperclip/helpers.rb', line 34 def (klass, name) class_for(klass).unscoped.where("#{name}_file_name IS NOT NULL").find_each do |instance| yield(instance) end end |
- (Object) interpolates(key, &block)
7 8 9 |
# File 'lib/paperclip/helpers.rb', line 7 def interpolates key, &block Paperclip::Interpolations[key] = block end |
- (Object) reset_duplicate_clash_check!
55 56 57 |
# File 'lib/paperclip/helpers.rb', line 55 def reset_duplicate_clash_check! @names_url = nil end |
- (Object) run(cmd, arguments = "", local_options = {})
The run method takes the name of a binary to run, the arguments to that binary and some options:
:command_path -> A $PATH-like variable that defines where to look for the binary
on the filesystem. Colon-separated, just like $PATH.
:expected_outcodes -> An array of integers that defines the expected exit codes
of the binary. Defaults to [0].
:log_command -> Log the command being run when set to true (defaults to false).
This will only log if logging in general is set to true as well.
:swallow_stderr -> Set to true if you don't care what happens on STDERR.
25 26 27 28 29 30 |
# File 'lib/paperclip/helpers.rb', line 25 def run(cmd, arguments = "", = {}) command_path = [:command_path] Cocaine::CommandLine.path = ( Cocaine::CommandLine.path ? [Cocaine::CommandLine.path].flatten | [command_path] : command_path ) = .merge(:logger => logger) if logging? && ([:log_command] || [:log_command]) Cocaine::CommandLine.new(cmd, arguments, ).run end |