Class: CodeWeb::MethodCache

Inherits:
Object
  • Object
show all
Defined in:
lib/code_web/method_cache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method_regex = nil) ⇒ MethodCache

Returns a new instance of MethodCache.



10
11
12
13
# File 'lib/code_web/method_cache.rb', line 10

def initialize(method_regex = nil)
  @method_calls=[]
  @method_regex = method_regex
end

Instance Attribute Details

#arg_regexObject

Returns the value of attribute arg_regex.



8
9
10
# File 'lib/code_web/method_cache.rb', line 8

def arg_regex
  @arg_regex
end

#method_callsObject

Map<String,Array<MethodCall>>



4
5
6
# File 'lib/code_web/method_cache.rb', line 4

def method_calls
  @method_calls
end

#method_regexObject

only store the information on these methods



7
8
9
# File 'lib/code_web/method_cache.rb', line 7

def method_regex
  @method_regex
end

Instance Method Details

#<<(mc) ⇒ Object



15
16
17
# File 'lib/code_web/method_cache.rb', line 15

def <<(mc)
  @method_calls << mc if detect?(mc)
end

#detect?(mc) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
25
26
27
# File 'lib/code_web/method_cache.rb', line 19

def detect?(mc)
  (method_regex.nil? || mc.full_method_name =~ method_regex) &&
    (
      arg_regex.nil? || (
        mc.hash_args? &&
        mc.arg_keys.detect {|key| key =~ arg_regex }
      )
    )
end