Module: Bulldog

Extended by:
Util
Defined in:
lib/bulldog.rb,
lib/bulldog.rb,
lib/bulldog/util.rb,
lib/bulldog/error.rb,
lib/bulldog/style.rb,
lib/bulldog/stream.rb,
lib/bulldog/vector2.rb,
lib/bulldog/version.rb,
lib/bulldog/tempfile.rb,
lib/bulldog/style_set.rb,
lib/bulldog/attachment.rb,
lib/bulldog/attachment.rb,
lib/bulldog/reflection.rb,
lib/bulldog/saved_file.rb,
lib/bulldog/validations.rb,
lib/bulldog/missing_file.rb,
lib/bulldog/interpolation.rb,
lib/bulldog/attachment/pdf.rb,
lib/bulldog/has_attachment.rb,
lib/bulldog/processor/base.rb,
lib/bulldog/attachment/base.rb,
lib/bulldog/attachment/none.rb,
lib/bulldog/attachment/image.rb,
lib/bulldog/attachment/maybe.rb,
lib/bulldog/attachment/video.rb,
lib/bulldog/processor/ffmpeg.rb,
lib/bulldog/attachment/unknown.rb,
lib/bulldog/processor/one_shot.rb,
lib/bulldog/processor/image_magick.rb,
lib/bulldog/processor/argument_tree.rb,
lib/bulldog/attachment/has_dimensions.rb

Defined Under Namespace

Modules: Attachment, HasAttachment, Interpolation, Processor, Stream, Util, Validations Classes: MissingFile, Reflection, SavedFile, Style, StyleSet, Tempfile, Vector2

Constant Summary collapse

Error =
Class.new(::RuntimeError)
ConfigurationError =
Class.new(Error)
ProcessingError =
Class.new(Error)
VERSION =
[0, 2, 4]

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from Util

run

Class Attribute Details

.default_path_templateObject

The default path template to use. See the #path configuration option for #has_attachment.



32
33
34
# File 'lib/bulldog.rb', line 32

def default_path_template
  @default_path_template
end

.default_url_templateObject

The default url template to use. See the #url configuration option for #has_attachment.



38
39
40
# File 'lib/bulldog.rb', line 38

def default_url_template
  @default_url_template
end

.loggerObject

Logger object to log to. Set to nil to omit logging.



26
27
28
# File 'lib/bulldog.rb', line 26

def logger
  @logger
end

.path_rootObject

The root directory to use for paths.



43
44
45
# File 'lib/bulldog.rb', line 43

def path_root
  @path_root
end

Class Method Details

.to_detect_type_by(name, &block) ⇒ Object

Register a custom type detector.

When instantiating an attachment, Bulldog will use the configured type detector to work out which type of attachment to use. This method registers a custom type detector which may be selected in your attachment configuration by just using the name.

The given block is passed the record, the attribute name, and the value as a Bulldog::Stream. The block should return a symbol representing the attachment type.

Example:

Bulldog.to_detect_type_by :file_extension do |record, name, stream|
  case File.extname(stream.file_name).sub(/\A\./)
  when 'jpg', 'png', 'gif', 'tiff'
    :image
  when 'mpg', 'avi', 'ogv'
    :video
  when 'pdf'
    :pdf
  end
end


107
108
109
# File 'lib/bulldog.rb', line 107

def to_detect_type_by(name, &block)
  Reflection.to_detect_type_by(name, &block)
end

.to_interpolate(token, &block) ⇒ Object

Define an interpolation token.

If :<token> appears in a path or URL template, the block will be called to get the value to substitute in. The block will be called with 3 arguments: the record, the attachment name, and the style.

Example:

Bulldog.to_interpolate :datestamp do |record, name, style|
  Date.today.strftime("%Y%m%d")
end


77
78
79
# File 'lib/bulldog.rb', line 77

def to_interpolate(token, &block)
  Interpolation.to_interpolate(token, &block)
end