Class: Bulldog::Reflection::Configuration
- Inherits:
-
Object
- Object
- Bulldog::Reflection::Configuration
- Defined in:
- lib/bulldog/reflection.rb
Class Method Summary collapse
Instance Method Summary collapse
- #default_style(name) ⇒ Object
-
#detect_type_by(detector = nil, &block) ⇒ Object
Specify a procedure to run to determine the type of the attachment.
-
#initialize(reflection) ⇒ Configuration
constructor
A new instance of Configuration.
- #path(path_template) ⇒ Object
-
#process(options = {}, &callback) ⇒ Object
Register the callback to fire for the given types of attachments.
- #process_once(options = {}, &callback) ⇒ Object
- #store_attributes(*args) ⇒ Object
- #style(name, attributes = {}) ⇒ Object
-
#type(type) ⇒ Object
Always use the given attachment type for this attachment.
- #url(url_template) ⇒ Object
Constructor Details
#initialize(reflection) ⇒ Configuration
Returns a new instance of Configuration.
111 112 113 |
# File 'lib/bulldog/reflection.rb', line 111 def initialize(reflection) @reflection = reflection end |
Class Method Details
.configure(reflection, &block) ⇒ Object
107 108 109 |
# File 'lib/bulldog/reflection.rb', line 107 def self.configure(reflection, &block) new(reflection).instance_eval(&block) end |
Instance Method Details
#default_style(name) ⇒ Object
127 128 129 |
# File 'lib/bulldog/reflection.rb', line 127 def default_style(name) @reflection.default_style = name end |
#detect_type_by(detector = nil, &block) ⇒ Object
Specify a procedure to run to determine the type of the attachment.
Pass either:
* A symbol argument, which names a named type detector. Use
+Bulldog.to_detect_type_by+ to register custom named type
detectors.
* A block, which takes the record, attribute name, and
Stream being assigned, and returns the attachment type to
use as a Symbol.
* A callable object, e.g. a Proc or BoundMethod, which has
the same signature as the block above.
202 203 204 205 206 207 |
# File 'lib/bulldog/reflection.rb', line 202 def detect_type_by(detector=nil, &block) detector && block and raise ArgumentError, "cannot pass argument and a block" @reflection.type = nil @reflection.type_detector = detector || block end |
#path(path_template) ⇒ Object
115 116 117 |
# File 'lib/bulldog/reflection.rb', line 115 def path(path_template) @reflection.path_template = path_template end |
#process(options = {}, &callback) ⇒ Object
Register the callback to fire for the given types of attachments.
Options:
* :types - A list of attachment types to process on. If
nil, process on any type.
* :on - The name of the event to run the processor on.
* :after - Same as prepending 'after_' to the given event.
* :before - Same as prepending 'before_' to the given event.
* :with - Use the given processor type. If nil (the
default), use the default type for the attachment.
145 146 147 148 149 150 151 152 |
# File 'lib/bulldog/reflection.rb', line 145 def process(={}, &callback) event_name = event_name() types = Array([:types]) if [:types] @reflection.events[event_name] << Event.new(:processor_type => [:with], :attachment_types => types, :styles => [:styles], :callback => callback) end |
#process_once(options = {}, &callback) ⇒ Object
154 155 156 157 158 159 160 161 |
# File 'lib/bulldog/reflection.rb', line 154 def process_once(={}, &callback) [:with] and raise ArgumentError, "cannot specify a processor (:with option) with #process_once" [:styles] and raise ArgumentError, "no :styles available for #process_once" [:with] = :one_shot process(, &callback) end |
#store_attributes(*args) ⇒ Object
163 164 165 166 167 168 169 |
# File 'lib/bulldog/reflection.rb', line 163 def store_attributes(*args) stored_attributes = args..symbolize_keys args.each do |attribute| stored_attributes[attribute] = :"#{@reflection.name}_#{attribute}" end @reflection.stored_attributes = stored_attributes end |
#style(name, attributes = {}) ⇒ Object
123 124 125 |
# File 'lib/bulldog/reflection.rb', line 123 def style(name, attributes={}) @reflection.styles << Style.new(name, attributes) end |
#type(type) ⇒ Object
Always use the given attachment type for this attachment.
This is equivalent to:
detect_type_by do
type if stream
end
180 181 182 183 |
# File 'lib/bulldog/reflection.rb', line 180 def type(type) @reflection.type = type @reflection.type_detector = nil end |
#url(url_template) ⇒ Object
119 120 121 |
# File 'lib/bulldog/reflection.rb', line 119 def url(url_template) @reflection.url_template = url_template end |