Sha256: 28540a1e604e7d252b4f5dffac7ba63d79426b6e3f665479d16570c0a83c4db9
Contents?: true
Size: 1.68 KB
Versions: 2
Compression:
Stored size: 1.68 KB
Contents
module Fortitude module Rails YIELDED_OBJECT_OUTPUTTER_SUPERCLASS = if defined?(::BasicObject) then ::BasicObject else ::Object end class YieldedObjectOutputter < YIELDED_OBJECT_OUTPUTTER_SUPERCLASS class << self def wrap_block_as_needed(output_target, for_method_name, original_block, yielded_methods_to_output) if original_block && yielded_methods_to_output lambda do |yielded_object, *args| outputter = new(output_target, yielded_object, for_method_name, yielded_methods_to_output) original_block.call(outputter, *args) end else original_block end end end def initialize(output_target, yielded_object, for_method_name, method_names) @output_target = output_target @yielded_object = yielded_object @for_method_name = for_method_name @method_names_hash = { } method_names.each do |method_name| @method_names_hash[method_name.to_sym] = true end end EMPTY_RETURN_VALUE = ''.freeze def method_missing(method_name, *args, &block) if @method_names_hash[method_name.to_sym] block = ::Fortitude::Rails::YieldedObjectOutputter.wrap_block_as_needed(@output_target, method_name, block, @method_names_hash.keys) return_value = @yielded_object.send(method_name, *args, &block) @output_target.rawtext(return_value) EMPTY_RETURN_VALUE else @yielded_object.send(method_name, *args, &block) end end def respond_to?(symbol, include_all = false) @yielded_object.respond_to?(symbol, include_all) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
fortitude-0.9.4-java | lib/fortitude/rails/yielded_object_outputter.rb |
fortitude-0.9.4 | lib/fortitude/rails/yielded_object_outputter.rb |