Class: MotionSupport::Callbacks::CallbackChain
- Defined in:
- motion/callbacks.rb
Overview
An Array with a compile method.
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
:nodoc:#.
-
#name ⇒ Object
readonly
:nodoc:#.
Instance Method Summary collapse
- #append(*callbacks) ⇒ Object
- #compile ⇒ Object
-
#initialize(name, config) ⇒ CallbackChain
constructor
A new instance of CallbackChain.
- #prepend(*callbacks) ⇒ Object
Methods inherited from Array
#as_json, #deep_dup, #extract_options!, #from, #has_hash_key?, #has_hash_value?, #in_groups, #in_groups_of, #reverse_each, #second, #split, #to, #to_formatted_s, #to_json, #to_param, #to_query, #to_sentence, wrap
Constructor Details
#initialize(name, config) ⇒ CallbackChain
Returns a new instance of CallbackChain.
243 244 245 246 247 248 249 |
# File 'motion/callbacks.rb', line 243 def initialize(name, config) @name = name @config = { :terminator => lambda { |result| false }, :scope => [ :kind ] }.merge!(config) end |
Instance Attribute Details
#config ⇒ Object (readonly)
:nodoc:#
241 242 243 |
# File 'motion/callbacks.rb', line 241 def config @config end |
#name ⇒ Object (readonly)
:nodoc:#
241 242 243 |
# File 'motion/callbacks.rb', line 241 def name @name end |
Instance Method Details
#append(*callbacks) ⇒ Object
271 272 273 |
# File 'motion/callbacks.rb', line 271 def append(*callbacks) callbacks.each { |c| append_one(c) } end |
#compile ⇒ Object
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
# File 'motion/callbacks.rb', line 251 def compile lambda do |obj, &block| value = nil halted = false callbacks = lambda do |obj, value, halted| value = !halted && (block.call if block) [value, halted] end reverse_each do |callback| callbacks = callback.apply(callbacks) end value, halted = *(callbacks.call(obj, value, halted)) value end end |
#prepend(*callbacks) ⇒ Object
275 276 277 |
# File 'motion/callbacks.rb', line 275 def prepend(*callbacks) callbacks.each { |c| prepend_one(c) } end |