Class: Forwarder::Arguments

Inherits:
Object
  • Object
show all
Defined in:
lib/forwarder/arguments.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



5
6
7
# File 'lib/forwarder/arguments.rb', line 5

def args
  @args
end

#messageObject (readonly)

Returns the value of attribute message.



5
6
7
# File 'lib/forwarder/arguments.rb', line 5

def message
  @message
end

#targetObject (readonly)

Returns the value of attribute target.



5
6
7
# File 'lib/forwarder/arguments.rb', line 5

def target
  @target
end

Instance Method Details

#afterObject



11
12
13
# File 'lib/forwarder/arguments.rb', line 11

def after
  @after ||= @params[:after]
end

#after?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/forwarder/arguments.rb', line 15

def after?
  after
end

#all?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/forwarder/arguments.rb', line 7

def all?
  !args? && !lambda? && @__all__
end

#aop?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/forwarder/arguments.rb', line 19

def aop?
  @__aop__ ||= !aop_values.empty?
end

#args?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/forwarder/arguments.rb', line 23

def args?
  !!args
end

#beforeObject



27
28
29
# File 'lib/forwarder/arguments.rb', line 27

def before
  @before ||= @params[:before]
end

#before?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/forwarder/arguments.rb', line 31

def before?
  before
end

#chain?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/forwarder/arguments.rb', line 35

def chain?
  @params[ :to_chain ]
end

#complete_args(*args) ⇒ Object



39
40
41
# File 'lib/forwarder/arguments.rb', line 39

def complete_args *args
  (self.args || []) + args
end

#custom_target?Boolean

Returns:

  • (Boolean)


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

def custom_target?
  @params[:to_object]
end

#evaluable?Boolean

def delegatable?

  !aop? && !custom_target? && !all? && !chain? && !args && !lambda?
end

Returns:

  • (Boolean)


51
52
53
54
55
56
# 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) ⇒ Object



58
59
60
# File 'lib/forwarder/arguments.rb', line 58

def lambda default=nil
  lambda? || default
end

#lambda?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/forwarder/arguments.rb', line 62

def lambda?
  @lambda
end

#must_not_compile?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/forwarder/arguments.rb', line 66

def must_not_compile?
  lambda? || aop? || custom_target?
end

#object_target(default) ⇒ Object

This is always nil unless we are a custom_target, in which case default is returned if target is :self, else target is returned



72
73
74
75
# File 'lib/forwarder/arguments.rb', line 72

def object_target default
  return unless custom_target?
  target == :self ? default : target
end

#serialized_paramsObject



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

def serialized_params
  Evaller.serialize args
end

#to_hash?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/forwarder/arguments.rb', line 81

def to_hash?
  @__to_hash__ ||= @params[ :to_hash ]
end

#translation(alternative = nil, &blk) ⇒ Object



85
86
87
88
89
90
91
# 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