Class: Seasar::Container::AspectInfoDef

Inherits:
Object
  • Object
show all
Defined in:
lib/seasar/container/aspect-info-def.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ AspectInfoDef

  • args

    1. Hash options



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/seasar/container/aspect-info-def.rb', line 27

def initialize(options)
  if options[:interceptor].nil?
    raise ArgumentError.new("interceptor not specified.")
  end
  @interceptor = options[:interceptor]

  if options[:pattern].nil?
    @pattern = /interceptor/i
    @condition = false
  else
    @pattern = options[:pattern]
    @condition = options[:condition].nil? ? true : options[:condition]
  end

  @pointcut = options[:pointcut].nil? ? /.+/ : options[:pointcut]

  self.setup_matcher
end

Instance Attribute Details

#conditionObject

Returns the value of attribute condition.



23
24
25
# File 'lib/seasar/container/aspect-info-def.rb', line 23

def condition
  @condition
end

#interceptorObject

Returns the value of attribute interceptor.



23
24
25
# File 'lib/seasar/container/aspect-info-def.rb', line 23

def interceptor
  @interceptor
end

#patternObject

Returns the value of attribute pattern.



23
24
25
# File 'lib/seasar/container/aspect-info-def.rb', line 23

def pattern
  @pattern
end

#pointcutObject

Returns the value of attribute pointcut.



23
24
25
# File 'lib/seasar/container/aspect-info-def.rb', line 23

def pointcut
  @pointcut
end

Instance Method Details

#applicable?(component_def) ⇒ Boolean

  • args

    1. Seasar::Container::ComponentDef component_def

  • return

    • Boolean

Returns:

  • (Boolean)


84
85
86
87
88
89
90
91
# File 'lib/seasar/container/aspect-info-def.rb', line 84

def applicable?(component_def)
  result = @matcher.call(component_def)
  if @condition
    return result
  else
    return !result
  end
end

#setup_matcherObject

  • args

    • none

  • return

    • none



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/seasar/container/aspect-info-def.rb', line 52

def setup_matcher
  case
  when @pattern.is_a?(Regexp)
    @matcher = lambda {|component_def|
      result = false
      if @pattern.match(component_def.component_name.to_s)
        result = true
      end
      if @pattern.match(component_def.component_class.name)
        result = true
      end
      result
    }
  when @pattern.is_a?(Class)
    @matcher = lambda {|component_def| component_def.component_class == @pattern }
  when @pattern.is_a?(Module)
    @matcher = lambda {|component_def| component_def.component_class.name.match(/^#{@pattern.name}::/) }
  when @pattern.is_a?(String)
    @matcher = lambda {|component_def| @pattern == component_def.component_name or @pattern == component_def.component_class.name }
  when @pattern.is_a?(Symbol)
    @matcher = lambda {|component_def| @pattern == component_def.component_name or @pattern == component_def.component_class.name.to_sym }
  else
    raise ArgumentError.new("unsupported pattern class #{@pattern}")
  end
end