trace-util-adv 0.2.4 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. data/TODO.txt +18 -2
  2. data/VERSION +1 -1
  3. data/lib/appenders/appender.rb +1 -1
  4. data/lib/appenders/base_appender.rb +18 -20
  5. data/lib/appenders/include.rb +2 -2
  6. data/lib/appenders/types/html_appender.rb +1 -1
  7. data/lib/appenders/types/logger_appender.rb +1 -1
  8. data/lib/appenders/types/xml_appender.rb +1 -1
  9. data/lib/extensions/hash_extensions.rb +41 -19
  10. data/lib/extensions/hash_rule_extensions.rb +4 -0
  11. data/lib/extensions/symbol_extensions.rb +7 -5
  12. data/lib/filters/composite/composite_class_filter.rb +1 -0
  13. data/lib/filters/composite/composite_module_filter.rb +1 -0
  14. data/lib/filters/executor/filter_exec.rb +6 -2
  15. data/lib/filters/filter.rb +12 -17
  16. data/lib/filters/filter_factory.rb +1 -1
  17. data/lib/filters/filter_mappings.rb +4 -2
  18. data/lib/filters/include.rb +4 -8
  19. data/lib/filters/list/list_instance_var_filter.rb +1 -0
  20. data/lib/filters/name_filter.rb +13 -0
  21. data/lib/filters/simple/argument_filter.rb +2 -1
  22. data/lib/filters/simple/class_filter.rb +1 -1
  23. data/lib/filters/simple/instance_var_filter.rb +9 -6
  24. data/lib/filters/simple/method_filter.rb +1 -0
  25. data/lib/filters/simple/module_filter.rb +6 -3
  26. data/lib/rules/rule_match.rb +5 -4
  27. data/lib/targets/file_target.rb +11 -0
  28. data/lib/templates/base_template.rb +11 -12
  29. data/lib/templates/html_template.rb +35 -36
  30. data/lib/templates/string_template.rb +0 -1
  31. data/lib/templates/template_mappings.rb +4 -4
  32. data/lib/templates/xml_template.rb +0 -1
  33. data/lib/trace-util-adv.rb +36 -20
  34. data/lib/trace_calls/trace_ext.rb +4 -17
  35. data/test/action_handler/include.rb +4 -0
  36. data/test/action_handler/test_action_handler.rb +1 -2
  37. data/test/action_handler/test_create_action_handler.rb +6 -9
  38. data/test/appenders/include.rb +4 -0
  39. data/test/appenders/test_appender_templates.rb +57 -0
  40. data/test/appenders/test_create_appender.rb +9 -10
  41. data/test/extensions/include.rb +4 -0
  42. data/test/extensions/test_filters_creation.rb +4 -28
  43. data/test/extensions/test_hash_extensions.rb +44 -47
  44. data/test/extensions/test_hash_filter_extensions.rb +46 -29
  45. data/test/extensions/test_set_context.rb +9 -11
  46. data/test/extensions/test_string_extensions.rb +1 -3
  47. data/test/extensions/test_symbol_extensions.rb +2 -4
  48. data/test/filters/chain/test_filters_chain.rb +1 -51
  49. data/test/filters/composite/test_composite_class_filter.rb +1 -3
  50. data/test/filters/composite/test_composite_module_filter.rb +1 -3
  51. data/test/filters/composite/test_composite_var_filter.rb +8 -11
  52. data/test/filters/executor/test_filter_exec.rb +1 -3
  53. data/test/filters/include.rb +8 -0
  54. data/test/filters/msg_context/test_custom_filters.rb +13 -14
  55. data/test/filters/simple/test_base_filter.rb +8 -6
  56. data/test/filters/simple/test_class_filter.rb +1 -3
  57. data/test/filters/simple/test_instancevar_filter.rb +5 -9
  58. data/test/filters/simple/test_method_filter.rb +4 -9
  59. data/test/filters/simple/test_module_filter.rb +13 -10
  60. data/test/samples/sample_composite_filters.rb +15 -12
  61. data/test/targets/test_create_targets.rb +21 -0
  62. data/test/templates/include.rb +4 -0
  63. data/test/templates/test_create_templates.rb +23 -0
  64. data/test/templates/test_exec_templates.rb +6 -0
  65. data/test/trace_calls/include.rb +4 -0
  66. data/test/trace_calls/test_configure_.rb +17 -14
  67. data/test/trace_calls/tracing/test_html_tracing.rb +2 -3
  68. data/test/trace_calls/tracing/test_logger_tracing.rb +5 -4
  69. data/test/trace_calls/tracing/test_stream_tracing.rb +2 -3
  70. data/test/trace_calls/tracing/test_teamplate_log_tracing.rb +2 -3
  71. data/test/trace_calls/tracing/test_xml_tracing.rb +2 -3
  72. data/trace-util-adv.gemspec +14 -6
  73. metadata +13 -5
  74. data/test/appenders/test_appender_tracers.rb +0 -56
  75. data/test/tracers/test_create_tracers.rb +0 -46
  76. data/test/tracers/test_exec_tracers.rb +0 -11
@@ -1,8 +1,4 @@
1
- dir = 'filters/'
2
- require dir + 'filter'
3
- include_folder_rec(dir + 'simple')
4
- include_folder_rec(dir + 'composite')
5
- include_folder_rec(dir + 'list')
6
- include_folder_rec(dir + 'msg_context')
7
- include_folder_rec(dir + 'executor')
8
- include_folder(dir)
1
+ require 'filters/filter'
2
+ rfolders = Require.rfolder('filters', {:folders => ['simple', 'composite', 'list', 'msg_context', 'executor'], :root_files => :after, :exclude => 'include'})
3
+
4
+
@@ -6,6 +6,7 @@ module Tracing
6
6
  end
7
7
 
8
8
  def allow_action(msg, context)
9
+ puts "LIF"
9
10
  action = rules[:default] || :yield
10
11
  var_rules = rules[:vars]
11
12
  # puts "var rules: #{var_rules.inspect}"
@@ -0,0 +1,13 @@
1
+ module Tracing
2
+ class NameFilter
3
+ attr_accessor :options
4
+
5
+ def initialize(options)
6
+ @options = options
7
+ end
8
+
9
+ def allow?(name)
10
+ true
11
+ end
12
+ end
13
+ end
@@ -5,11 +5,12 @@ module Tracing
5
5
 
6
6
  def initialize(options)
7
7
  super(options)
8
- @rules = options[:arg_rules] || {}
8
+ @rules = options[:arg_rules] || options[:args_filter] || {}
9
9
  @var_name = options[:arg_name]
10
10
  end
11
11
 
12
12
  def allow_action(msg, context)
13
+ puts "AMF"
13
14
  obj = context[:args]
14
15
  if var_name.kind_of?(Symbol) || var_name.kind_of?(String)
15
16
  key = var_name.to_sym
@@ -3,7 +3,7 @@ module Tracing
3
3
  class ClassFilter < BaseFilter
4
4
  def initialize(options)
5
5
  super(options)
6
- @rules = options[:class_rules] || {}
6
+ @rules = options[:class_rules] || options[:class_filter] || {}
7
7
  end
8
8
 
9
9
  def allow_action(msg, context)
@@ -6,20 +6,23 @@ module Tracing
6
6
  def initialize(options)
7
7
  super(options)
8
8
  # puts "create inst.var filter: #{options.inspect}"
9
- @rules = options[:var_rules] || {}
9
+ @rules = options[:var_rules] || options[:vars_filter] || {}
10
10
  @var_name = options[:var_name]
11
11
  end
12
12
 
13
13
  def allow_action(msg, context)
14
- # puts "InstanceVarFilter.allow_action"
14
+ puts "InstanceVarFilter.allow_action"
15
15
  obj = context[:self]
16
- # puts "var_name: #{var_name}"
16
+ puts "var_name: #{var_name}"
17
17
  if var_name.kind_of?(Symbol) || var_name.kind_of?(String)
18
18
  value = obj.instance_variable_get("@#{var_name}")
19
- # puts "value: #{value}"
19
+ puts "value: #{value}"
20
20
  return name_allow_action(value)
21
- end
22
- :yield
21
+ else
22
+ puts "return default :yield"
23
+ :yield
24
+ end
23
25
  end
26
+
24
27
  end
25
28
  end
@@ -9,6 +9,7 @@ module Tracing
9
9
  end
10
10
 
11
11
  def allow_action(msg, context)
12
+ puts "MethF"
12
13
  name = context[:method_name]
13
14
  # puts "allow name?: #{name}"
14
15
  allow = name_allow_action(name)
@@ -3,12 +3,15 @@ module Tracing
3
3
  class ModuleFilter < BaseFilter
4
4
  def initialize(options)
5
5
  super(options)
6
- @rules = options[:module_rules] || {}
6
+ @rules = options[:module_rules] || options[:module_filter] || {}
7
7
  end
8
8
 
9
9
  def allow_action(msg, context)
10
+ puts "ModuleF"
10
11
  name = context[:full_modules_name]
11
- allow = name_allow_action(name)
12
+ puts "name: #{name}"
13
+ # allow = name_allow_action(name)
12
14
  end
13
15
  end
14
- end
16
+ end
17
+
@@ -3,15 +3,15 @@ module Tracing
3
3
  class RuleTypeError < RuntimeError; end
4
4
 
5
5
  def matches_any?(name)
6
- puts "matches any: #{name.inspect}"
6
+ # puts "matches any: #{name.inspect}"
7
7
  self.any? do |rule|
8
- puts "rule:" + rule.inspect
9
- puts "against:" + name.inspect
8
+ # puts "rule:" + rule.inspect
9
+ # puts "against:" + name.inspect
10
10
  if rule.kind_of? Regexp
11
11
  # match return position of match, or nil if no match
12
12
  # here converted into boolean result
13
13
  match = !(name =~ rule).nil?
14
- puts "match: #{match}"
14
+ # puts "match: #{match}"
15
15
  match
16
16
  elsif rule.kind_of? String
17
17
  match = (name == rule)
@@ -28,6 +28,7 @@ module Tracing
28
28
  end
29
29
 
30
30
  def rules_allow_action(name)
31
+ puts "rules_allow_action: #{name}"
31
32
  self.each do |rule|
32
33
  res = rule.rule_allow_action(name)
33
34
  return :exclude if (res == :exclude)
@@ -1,10 +1,21 @@
1
1
  module Tracing
2
2
  class FileTarget
3
3
  include Tracing::DefaultPath
4
+
5
+ attr_accessor :to_file
6
+
4
7
  class << self
5
8
  include Tracing::DefaultPath
6
9
  end
7
10
 
11
+ def initialize(options)
12
+ def_path = options[:default_path]
13
+ _to_file = options[:to_file]
14
+
15
+ @default_path = def_path if def_path
16
+ @to_file = _to_file if _to_file
17
+ end
18
+
8
19
  def append(txt, context)
9
20
  file = get_file(context)
10
21
  write_file(file, txt)
@@ -2,20 +2,19 @@ require 'templates/trace_output_handler'
2
2
 
3
3
  module Tracing
4
4
  class BaseTemplate
5
- include Tracing::OutputHandler
5
+ include Tracing::OutputHandler
6
6
 
7
- def handle_after_call(context)
8
- template = end_template(context)
9
- output(template, context)
7
+ def handle_after_call(context)
8
+ template = end_template(context)
9
+ output(template, context)
10
+ end
11
+
12
+ def handle_before_call(context)
13
+ template = before_template(context)
14
+ if context[:block]
15
+ template << before_block_template
10
16
  end
11
-
12
- def handle_before_call(context)
13
- template = before_template(context)
14
- if context[:block]
15
- template << before_block_template
16
- end
17
- output(template, context)
18
- end
17
+ output(template, context)
19
18
  end
20
19
  end
21
20
  end
@@ -1,47 +1,46 @@
1
1
  module Tracing
2
2
  class HtmlTemplate < BaseTemplate
3
3
 
4
- def before_template(context)
5
- # method_name = context[:method_full_name]
6
- # args = context[:args].inspect
7
- template = <<-EOF
8
- <div class="method-title"><%= context[:method_full_name] %></div>
9
- <div class="method-body">
10
- <div class="begin">
11
- <div class="method-name"><%= context[:method_full_name] %> :: BEGIN</div>
12
- <div class="args">
13
- <div class="method-args"><%= context[:args] %> </div>
14
- #block#
15
- </div>
4
+ def before_template(context)
5
+ # method_name = context[:method_full_name]
6
+ # args = context[:args].inspect
7
+ template = <<-EOF
8
+ <div class="method-title"><%= context[:method_full_name] %></div>
9
+ <div class="method-body">
10
+ <div class="begin">
11
+ <div class="method-name"><%= context[:method_full_name] %> :: BEGIN</div>
12
+ <div class="args">
13
+ <div class="method-args"><%= context[:args] %> </div>
14
+ #block#
16
15
  </div>
17
- EOF
18
- end
16
+ </div>
17
+ EOF
18
+ end
19
19
 
20
- def before_block_template
21
- template = <<-EOF
22
- <div class="method block-arg">(and a block)</div>
23
- EOF
24
- end
20
+ def before_block_template
21
+ template = <<-EOF
22
+ <div class="method block-arg">(and a block)</div>
23
+ EOF
24
+ end
25
25
 
26
- def end_template(context)
27
- # method_name = context[:method_full_name]
28
- # result = context[:result].inspect
29
- template = <<-EOF
30
- <div class="end">
31
- <div class="method-name"><%= context[:method_full_name] %> :: END</div>
32
- <div class="method-result"><%= context[:result] %></div>
33
- </div>
26
+ def end_template(context)
27
+ # method_name = context[:method_full_name]
28
+ # result = context[:result].inspect
29
+ template = <<-EOF
30
+ <div class="end">
31
+ <div class="method-name"><%= context[:method_full_name] %> :: END</div>
32
+ <div class="method-result"><%= context[:result] %></div>
34
33
  </div>
35
- EOF
36
- end
34
+ </div>
35
+ EOF
36
+ end
37
37
 
38
- # override
39
- def handle_before_call(context)
40
- template = before_template(context)
41
- block_replace = context[:block] ? before_block_template : ""
42
- template.gsub!(/#block#/, block_replace)
43
- output(template, context)
44
- end
38
+ # override
39
+ def handle_before_call(context)
40
+ template = before_template(context)
41
+ block_replace = context[:block] ? before_block_template : ""
42
+ template.gsub!(/#block#/, block_replace)
43
+ output(template, context)
45
44
  end
46
45
  end
47
46
  end
@@ -25,5 +25,4 @@ module Tracing
25
25
  EOF
26
26
  end
27
27
  end
28
- end
29
28
  end
@@ -1,10 +1,10 @@
1
1
  module TemplateMappings
2
2
  def self.defaults
3
3
  {
4
- :string => Tracing::OutputTemplate::StringTrace,
5
- :xml => Tracing::OutputTemplate::XmlTrace,
6
- :html => Tracing::OutputTemplate::HtmlTrace,
7
- :default => Tracing::OutputTemplate::StringTrace
4
+ :string => Tracing::StringTemplate,
5
+ :xml => Tracing::XmlTemplate,
6
+ :html => Tracing::HtmlTemplate,
7
+ :default => Tracing::StringTemplate
8
8
  }
9
9
  end
10
10
  end
@@ -31,5 +31,4 @@ module Tracing
31
31
  output(template, context)
32
32
  end
33
33
  end
34
- end
35
34
  end
@@ -1,24 +1,40 @@
1
1
  require 'rubygems'
2
2
  require 'duration'
3
-
4
- def include_folder_rec(name)
5
- Dir.glob(File.join(File.dirname(__FILE__), "#{name}/**/*.rb")).each {|f|
6
- puts f
7
- require f
8
- }
9
- end
10
-
11
- def include_folder(name)
12
- Dir.glob(File.join(File.dirname(__FILE__), "#{name}/*.rb")).each {|f|
13
- puts f
14
- require f
15
- }
16
- end
17
-
18
- include_folder_rec('rules')
19
- include_folder_rec('extensions')
3
+ require 'require-magic'
4
+ Require.base_path = File.dirname(__FILE__)
5
+ Require.rfolder 'rules'
6
+ Require.folder 'extensions'
20
7
  require 'filters/include'
21
- include_folder('output_handler')
8
+ Require.folder 'output_handler'
22
9
  require 'appenders/include'
23
- include_folder_rec('action_handlers')
24
- include_folder_rec('targets')
10
+ Require.rfolder('action_handler')
11
+ Require.rfolder('targets')
12
+ Require.rfolder('templates')
13
+ Require.folder('trace_calls')
14
+
15
+
16
+ # Module_filter = {
17
+ # :name => 'my modules',
18
+ # :default => :exclude,
19
+ # :module_rules => [{
20
+ # # id of modules rule set
21
+ # :name => ['my_modules'],
22
+ # :include => [/Hobo/],
23
+ # :exclude => [/Dryml/],
24
+ # :default => :exclude
25
+ # }]
26
+ # }
27
+ #
28
+ # _filter = Module_filter
29
+ #
30
+ # context = {:modules => ['Blip', 'Blap']}.context
31
+ #
32
+ # puts context.inspect
33
+ #
34
+ # options = {:filters => _filter}
35
+ # exec = Tracing::Filter::Executor.new(options)
36
+ # result = exec.filters_allow?('msg', context)
37
+ #
38
+ # puts "Result:" + result.inspect
39
+ #
40
+ # assert_equal false, result, "Filter should NOT allow passage"
@@ -11,23 +11,10 @@ module Tracing
11
11
  include Tracing::Filter::Exec
12
12
 
13
13
  class << self
14
- # supports
15
- # - Filter registration
16
- # - ActionHandler registration
17
- include Tracing::Filter::Registration
18
- include Tracing::ActionHandler::Registration
19
-
20
- attr_accessor :final_yield_action
21
-
22
- def configure(options)
23
- # puts "Filters before config: " + Tracing::TraceExt.filters.inspect
24
-
25
- register_filters(options[:filters])
26
-
27
- # puts "Filters after config: " + Tracing::TraceExt.filters.inspect
28
-
29
- register_action_handlers(options[:action_handlers] || options)
30
- @final_yield_action = options[:final_yield] || :include
14
+ attr_accessor :configuration
15
+
16
+ def configure(configuration)
17
+ @configuration ||= configuration if configuration.kind_of? Tracing::Configuration
31
18
  end
32
19
 
33
20
  end
@@ -0,0 +1,4 @@
1
+ require "trace-util-adv"
2
+ Require.base_path = File.dirname(__FILE__)
3
+ Require.folder "../samples"
4
+ require "test/unit"
@@ -1,5 +1,4 @@
1
- require "trace-util-adv"
2
- require "test/unit"
1
+ require 'include'
3
2
 
4
3
  class TestFilter < Test::Unit::TestCase
5
4
 
@@ -1,9 +1,4 @@
1
- require "core_extensions"
2
- require "trace_calls"
3
- require "sample_filters"
4
- require "rubygems"
5
- require "duration"
6
- require "test/unit"
1
+ require 'include'
7
2
 
8
3
  class TestCreateActionHandler < Test::Unit::TestCase
9
4
 
@@ -15,14 +10,16 @@ class TestCreateActionHandler < Test::Unit::TestCase
15
10
  config = {:action_handlers => {:appenders => :html}}
16
11
  result = config.action_handlers
17
12
  assert_equal Tracing::HtmlAppender, result.appenders[0].class, "Should result in action handler with HtmlAppender registered"
18
-
13
+ end
14
+
15
+ def test_ah
19
16
  config = {:action_handlers => {:filters => {:i_method_filter => "a,b"}}}
20
17
  result = config.action_handlers
21
18
  assert_equal Tracing::MethodFilter, result.filters[0].class, "Should result in action handler with MethodFilter registered"
22
-
19
+
23
20
  ah1 = {:filters => {:i_method_filter => "a,b"}, :appenders => :html}
24
21
  ah2 = {:filters => {:x_method_filter => "c,d"}, :appenders => :xml}
25
-
22
+
26
23
  config = {:action_handlers => [ah1, ah2]}
27
24
  result = config.action_handlers
28
25
  assert_equal Tracing::MethodFilter, result[0].filters[0].class, "Should result in action handler with MethodFilter registered"