Class: Aspect4r::Model::Advice

Inherits:
Object
  • Object
show all
Defined in:
lib/aspect4r/model/advice.rb

Constant Summary collapse

BEFORE =
1
AFTER =
2
AROUND =
3

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, method_matcher, with_method, group, options = {}) ⇒ Advice

Returns a new instance of Advice.



11
12
13
14
15
16
17
# File 'lib/aspect4r/model/advice.rb', line 11

def initialize type, method_matcher, with_method, group, options = {}
  @type        = type
  @method_matcher = method_matcher
  @with_method = with_method
  @group       = group
  @options     = options
end

Instance Attribute Details

#groupObject (readonly)

Returns the value of attribute group.



8
9
10
# File 'lib/aspect4r/model/advice.rb', line 8

def group
  @group
end

#method_matcherObject

Returns the value of attribute method_matcher.



9
10
11
# File 'lib/aspect4r/model/advice.rb', line 9

def method_matcher
  @method_matcher
end

#optionsObject

Returns the value of attribute options.



9
10
11
# File 'lib/aspect4r/model/advice.rb', line 9

def options
  @options
end

#typeObject

Returns the value of attribute type.



9
10
11
# File 'lib/aspect4r/model/advice.rb', line 9

def type
  @type
end

#with_methodObject

Returns the value of attribute with_method.



9
10
11
# File 'lib/aspect4r/model/advice.rb', line 9

def with_method
  @with_method
end

Instance Method Details

#after?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/aspect4r/model/advice.rb', line 31

def after?
  type == AFTER
end

#around?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/aspect4r/model/advice.rb', line 35

def around?
  type == AROUND
end

#before?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/aspect4r/model/advice.rb', line 23

def before?
  type == BEFORE and not options[:skip_if_false]
end

#before_filter?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/aspect4r/model/advice.rb', line 27

def before_filter?
  type == BEFORE and options[:skip_if_false]
end

#invoke(obj, *args, &block) ⇒ Object



39
40
41
# File 'lib/aspect4r/model/advice.rb', line 39

def invoke obj, *args, &block
  obj.send with_method, *args, &block
end

#nameObject



19
20
21
# File 'lib/aspect4r/model/advice.rb', line 19

def name
  options[:name] || with_method
end

#to_sObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/aspect4r/model/advice.rb', line 43

def to_s
  s = "<" << @group << "> "
  case @type
  when BEFORE
    if @options[:skip_if_false]
      s << "BEFORE_FILTER: "
    else
      s << "BEFORE: "
    end
  when AFTER
    s << "AFTER : "
  when AROUND
    s << "AROUND: "
  end
  s << "[" << @method_matcher.to_s << "] DO "
  s << @with_method.to_s
  s << " WITH OPTIONS "
  @options.each do |key, value|
    next if key == :skip_if_false
    s << key.to_s << ":" << value.to_s
  end
  s
end