class Forwarder::Arguments
Attributes
args[R]
message[R]
target[R]
Public Class Methods
new(*args, &blk)
click to toggle source
# File lib/forwarder/arguments.rb, line 103 def initialize *args, &blk @message = args.shift raise ArgumentError, "need one message and a hash of kwd params, plus an optional block" unless args.size == 1 && args.first.is_a?( Hash ) @params = args.first set_message set_target set_args blk check_for_incompatibilities! translate_to_hash end
Public Instance Methods
after()
click to toggle source
# File lib/forwarder/arguments.rb, line 11 def after @after ||= @params[:after] end
after?()
click to toggle source
# File lib/forwarder/arguments.rb, line 15 def after? after end
all?()
click to toggle source
# File lib/forwarder/arguments.rb, line 7 def all? !args? && !lambda? && @__all__ end
aop?()
click to toggle source
# File lib/forwarder/arguments.rb, line 19 def aop? @__aop__ ||= !aop_values.empty? end
args?()
click to toggle source
# File lib/forwarder/arguments.rb, line 23 def args? !!args end
before()
click to toggle source
# File lib/forwarder/arguments.rb, line 27 def before @before ||= @params[:before] end
before?()
click to toggle source
# File lib/forwarder/arguments.rb, line 31 def before? before end
chain?()
click to toggle source
# File lib/forwarder/arguments.rb, line 35 def chain? @params[ :to_chain ] end
complete_args(*args)
click to toggle source
# File lib/forwarder/arguments.rb, line 39 def complete_args *args (self.args || []) + args end
custom_target?()
click to toggle source
# File lib/forwarder/arguments.rb, line 43 def custom_target? @params[:to_object] end
evaluable?()
click to toggle source
def delegatable?
!aop? && !custom_target? && !all? && !chain? && !args && !lambda?
end
# File lib/forwarder/arguments.rb, line 51 def evaluable? !lambda? && !aop? && ( !args || args.all?{|a| Evaller.evaluable? a } ) && ( !custom_target? || Evaller.evaluable?( custom_target? ) ) end
lambda(default=nil)
click to toggle source
# File lib/forwarder/arguments.rb, line 58 def lambda default=nil lambda? || default end
lambda?()
click to toggle source
# File lib/forwarder/arguments.rb, line 62 def lambda? @lambda end
must_not_compile?()
click to toggle source
# File lib/forwarder/arguments.rb, line 66 def must_not_compile? lambda? || aop? || custom_target? end
object_target(default)
click to toggle source
This is always nil unless we are a custom_target, in which case default is returned if target is :self, else target is returned
# File lib/forwarder/arguments.rb, line 72 def object_target default return unless custom_target? target == :self ? default : target end
serialized_params()
click to toggle source
# File lib/forwarder/arguments.rb, line 77 def serialized_params Evaller.serialize args end
to_hash?()
click to toggle source
# File lib/forwarder/arguments.rb, line 81 def to_hash? @__to_hash__ ||= @params[ :to_hash ] end
translation(alternative=nil, &blk)
click to toggle source
# File lib/forwarder/arguments.rb, line 85 def translation alternative=nil, &blk @params[ :as ].tap do | tltion | break alternative unless tltion break tltion unless blk blk.( tltion ) end end
Private Instance Methods
aop_values()
click to toggle source
# File lib/forwarder/arguments.rb, line 94 def aop_values @__aop_values__ ||= @params.values_at( :after, :before ).compact end
check_for_incompatibilities!()
click to toggle source
# File lib/forwarder/arguments.rb, line 98 def check_for_incompatibilities! raise ArgumentError, "cannot provide translations for forward_all" if @__all__ && translation raise ArgumentError, "cannot provide arguments for forward_all" if @__all__ && args? end
set_args(blk)
click to toggle source
# File lib/forwarder/arguments.rb, line 114 def set_args blk set_lambda blk hw = @params.has_key? :with ha = @params.has_key? :with_ary raise ArgumentError, "cannot use :with and :with_ary parameter" if hw && ha unless to_hash? set_args_normal if hw set_args_ary if ha end end
set_args_ary()
click to toggle source
# File lib/forwarder/arguments.rb, line 125 def set_args_ary @args = [ @params[:with_ary] ] raise ArgumentError, ":with_ary needs an array parameter" unless Array === @args.first end
set_args_normal()
click to toggle source
# File lib/forwarder/arguments.rb, line 130 def set_args_normal case arg = @params[:with] when Array @args = arg.dup rescue arg else @args = [ (arg.dup rescue arg) ] end end
set_lambda(blk)
click to toggle source
# File lib/forwarder/arguments.rb, line 146 def set_lambda blk if use_block? @after = blk if @params[:after] == :use_block @before = blk if @params[:before] == :use_block @lambda = @params[:with_block] else raise ArgumentError, "cannot use :with_block and a block" if @params[:with_block] && blk @lambda = @params.fetch :with_block, blk end end
set_message()
click to toggle source
# File lib/forwarder/arguments.rb, line 139 def set_message case @message when Array @__all__ = true end end
set_target()
click to toggle source
# File lib/forwarder/arguments.rb, line 160 def set_target [:to, :to_chain, :to_object, :to_hash].each do | tgt_kwd | tgt = @params[ tgt_kwd ] next unless tgt raise ArgumentError, "more than one target specified." if @target @target = tgt end raise ArgumentError, "no target specified." unless @target end
translate_to_hash()
click to toggle source
# File lib/forwarder/arguments.rb, line 171 def translate_to_hash return unless @params[:to_hash] raise ArgumentError, "cannot provide arguments for to_hash:" if @params.has_key?( :with ) || @params.has_key?( :with_ary ) end
use_block?()
click to toggle source
# File lib/forwarder/arguments.rb, line 175 def use_block? aop_values.include?( :use_block ) end