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] || @params[:before_with_block]
end

#before?Boolean

Returns:

  • (Boolean)


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

def before?
  before
end

#before_with_block?Boolean

Returns:

  • (Boolean)


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

def before_with_block?
  !!@params[:before_with_block]
end

#chain?Boolean

Returns:

  • (Boolean)


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

def chain?
  @params[ :to_chain ]
end

#complete_args(*args) ⇒ Object



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

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

#custom_target?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/forwarder/arguments.rb', line 48

def custom_target?
  @params[:to_object]
end

#evaluable?Boolean

def delegatable?

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

Returns:

  • (Boolean)


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

def evaluable?
  !lambda? &&
    !aop? &&
    ( !args || args.all?{|a| Evaller.evaluable? a } ) &&
    ( !custom_target? || Evaller.evaluable?( custom_target? ) )
end

#lambda(default = nil) ⇒ Object



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

def lambda default=nil
  lambda? || default
end

#lambda?Boolean

Returns:

  • (Boolean)


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

def lambda?
  @lambda
end

#must_not_compile?Boolean

Returns:

  • (Boolean)


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

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



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

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

#serialized_paramsObject



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

def serialized_params
  Evaller.serialize args
end

#to_hash?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/forwarder/arguments.rb', line 86

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

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



90
91
92
93
94
95
96
# File 'lib/forwarder/arguments.rb', line 90

def translation alternative=nil, &blk
  @params[ :as ].tap do | tltion |
    break alternative unless tltion
    break tltion unless blk
    blk.( tltion ) 
  end
end