trace-util-adv 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. data/Advanced TraceUtils tutorial.pdf +0 -0
  2. data/CHANGELOG +4 -8
  3. data/{lib/TODO.txt → TODO.txt} +8 -0
  4. data/VERSION +1 -1
  5. data/lib/action_handler/action_handler.rb +40 -0
  6. data/lib/{action_handler.rb → action_handler/action_handler_registration.rb} +3 -41
  7. data/lib/appenders/appender.rb +1 -13
  8. data/lib/appenders/appender_mappings.rb +13 -0
  9. data/lib/appenders/base_appender.rb +2 -11
  10. data/lib/appenders/file_appender.rb +21 -13
  11. data/lib/appenders/include.rb +4 -0
  12. data/lib/appenders/types/README-NOTE.txt +2 -0
  13. data/lib/appenders/{html_appender.rb → types/html_appender.rb} +4 -20
  14. data/lib/appenders/{logger_appender.rb → types/logger_appender.rb} +0 -0
  15. data/lib/appenders/{stream_appender.rb → types/stream_appender.rb} +0 -0
  16. data/lib/appenders/{template_log_appender.rb → types/template_log_appender.rb} +0 -0
  17. data/lib/appenders/{xml_appender.rb → types/xml_appender.rb} +1 -1
  18. data/lib/extensions/array_extensions.rb +42 -0
  19. data/lib/extensions/hash_extensions.rb +181 -0
  20. data/lib/extensions/hash_rule_extensions.rb +50 -0
  21. data/lib/extensions/include.rb +1 -0
  22. data/lib/extensions/nilclass_extensions.rb +10 -0
  23. data/lib/extensions/object_extensions.rb +19 -0
  24. data/lib/extensions/string_extensions.rb +35 -0
  25. data/lib/extensions/symbol_extensions.rb +30 -0
  26. data/lib/filters/composite/composite_class_filter.rb +25 -0
  27. data/lib/filters/composite/composite_module_filter.rb +53 -0
  28. data/lib/filters/executor/filter_exec.rb +74 -0
  29. data/lib/filters/filter.rb +43 -0
  30. data/lib/filters/filter_factory.rb +1 -1
  31. data/lib/filters/filter_mappings.rb +36 -0
  32. data/lib/filters/{tracing_filter.rb → filter_registration.rb} +6 -49
  33. data/lib/filters/filter_use.rb +10 -0
  34. data/lib/filters/include.rb +8 -0
  35. data/lib/filters/list/README-NOTE.txt +1 -0
  36. data/lib/filters/list/list_instance_var_filter.rb +27 -0
  37. data/lib/filters/{message_filters.rb → msg_context/message_context_filters.rb} +3 -12
  38. data/lib/filters/simple/argument_filter.rb +24 -0
  39. data/lib/filters/simple/class_filter.rb +15 -0
  40. data/lib/filters/simple/instance_var_filter.rb +25 -0
  41. data/lib/filters/simple/method_filter.rb +17 -0
  42. data/lib/filters/simple/module_filter.rb +14 -0
  43. data/lib/{templates/trace_output_handler.rb → output_handler/output_handler.rb} +0 -0
  44. data/lib/rules/rule_mappings.rb +10 -0
  45. data/lib/{rule_match.rb → rules/rule_match.rb} +5 -3
  46. data/lib/targets/README-NOTE.txt +2 -0
  47. data/lib/targets/file_target.rb +65 -0
  48. data/lib/targets/stream_target.rb +9 -0
  49. data/lib/targets/string_target.rb +9 -0
  50. data/lib/templates/base_template.rb +3 -2
  51. data/lib/templates/html_template.rb +1 -2
  52. data/lib/templates/include.rb +2 -0
  53. data/lib/templates/string_template.rb +24 -25
  54. data/lib/templates/template_mappings.rb +10 -0
  55. data/lib/templates/xml_template.rb +28 -29
  56. data/lib/trace-util-adv.rb +24 -4
  57. data/lib/{trace_calls.rb → trace_calls/trace_calls.rb} +0 -0
  58. data/lib/trace_calls/trace_configuration.rb +29 -0
  59. data/lib/{trace_ext.rb → trace_calls/trace_ext.rb} +10 -9
  60. data/test/{test_action_handler.rb → action_handler/test_action_handler.rb} +1 -5
  61. data/test/action_handler/test_create_action_handler.rb +31 -0
  62. data/test/appenders/test_appender_filters.rb +0 -0
  63. data/test/appenders/test_appender_tracers.rb +56 -0
  64. data/test/appenders/test_create_appender.rb +49 -0
  65. data/test/{test_html_appender.rb → appenders/test_html_appender.rb} +3 -7
  66. data/test/appenders/test_stream_appender.rb +41 -0
  67. data/test/appenders/test_template_log_appender.rb +18 -0
  68. data/test/{test_xml_appender.rb → appenders/test_xml_appender.rb} +0 -0
  69. data/test/extensions/test_filters_creation.rb +36 -0
  70. data/test/extensions/test_hash_extensions.rb +208 -0
  71. data/test/extensions/test_hash_filter_extensions.rb +65 -0
  72. data/test/extensions/test_set_context.rb +94 -0
  73. data/test/extensions/test_string_extensions.rb +55 -0
  74. data/test/extensions/test_symbol_extensions.rb +35 -0
  75. data/test/{test_filters_chain.rb → filters/chain/test_filters_chain.rb} +2 -1
  76. data/test/filters/composite/test_composite_class_filter.rb +78 -0
  77. data/test/filters/composite/test_composite_module_filter.rb +82 -0
  78. data/test/filters/composite/test_composite_var_filter.rb +103 -0
  79. data/test/filters/executor/test_filter_exec.rb +80 -0
  80. data/test/filters/msg_context/test_custom_filters.rb +54 -0
  81. data/test/filters/simple/test_base_filter.rb +56 -0
  82. data/test/filters/simple/test_class_filter.rb +75 -0
  83. data/test/filters/simple/test_instancevar_filter.rb +82 -0
  84. data/test/filters/simple/test_method_filter.rb +77 -0
  85. data/test/filters/simple/test_module_filter.rb +63 -0
  86. data/test/samples/include.rb +1 -0
  87. data/test/samples/sample_classes.rb +23 -0
  88. data/test/samples/sample_composite_filters.rb +50 -0
  89. data/test/samples/sample_filters.rb +58 -0
  90. data/test/sandbox/matcher.rb +7 -0
  91. data/test/sandbox/sandbox.rb +25 -0
  92. data/test/{test_xml_gen.rb → sandbox/test_xml_gen.rb} +0 -0
  93. data/test/trace_calls/test_configure_.rb +70 -0
  94. data/test/trace_calls/tracing/test_html_tracing.rb +20 -0
  95. data/test/trace_calls/tracing/test_logger_tracing.rb +18 -0
  96. data/test/trace_calls/tracing/test_stream_tracing.rb +17 -0
  97. data/test/trace_calls/tracing/test_teamplate_log_tracing.rb +18 -0
  98. data/test/trace_calls/tracing/test_xml_tracing.rb +18 -0
  99. data/test/tracers/test_create_tracers.rb +46 -0
  100. data/test/tracers/test_exec_tracers.rb +11 -0
  101. data/trace-util-adv.gemspec +91 -32
  102. metadata +91 -32
  103. data/lib/core_extensions.rb +0 -101
  104. data/lib/filters/base_filters.rb +0 -178
  105. data/lib/filters/composite_filters.rb +0 -71
  106. data/lib/output_templates.rb +0 -5
  107. data/lib/sample_filters.rb +0 -97
  108. data/lib/trace_appenders.rb +0 -9
  109. data/lib/trace_filters.rb +0 -4
  110. data/test/test_appender.rb +0 -29
  111. data/test/test_file_appender.rb +0 -32
  112. data/test/test_filters.rb +0 -112
  113. data/test/test_filters_create.rb +0 -28
  114. data/test/test_special_filters.rb +0 -78
Binary file
data/CHANGELOG CHANGED
@@ -1,9 +1,5 @@
1
- 27-10-2009
1
+ 13-Nov-2009
2
2
  ==========
3
- * Created filter_factory.rb
4
- - will include convenience methods to create and operate on filters
5
- - should be used when registering filters in all cases
6
-
7
- * improved README documentation
8
-
9
- NOTE: Framework has become overly complex - simplify, and refactor next week!
3
+ * Test cases for basic and composite filters all pass
4
+ * Created new filter: ArgumentsFilter
5
+ * Major refactoring!
@@ -1,4 +1,12 @@
1
1
  TODO:
2
+ ----
3
+ - Unit tests for appenders. action_handler
4
+ - require txt_file_mutator
5
+
6
+ ---
7
+ Add time to context for before- and after handle calls. Enable tracing time output
8
+ Allow for comparing time it takes to complete method and act upon it!
9
+ Store method with come context on stack, to allow look up to compare with previous calls. Perhaps find average time it took to call this method etc.
2
10
 
3
11
  Support Intrusive trace statements
4
12
  ----------------------------------
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.3
1
+ 0.2.4
@@ -0,0 +1,40 @@
1
+ Dir.glob(File.join(File.dirname(__FILE__), '**/*.rb')).each {|f| require f }
2
+
3
+ module Tracing
4
+ class ActionHandler
5
+ # supports:
6
+ # - Filter registration and execution
7
+ # - Appender registration
8
+ include Tracing::FilterUse
9
+ include Tracing::Appender::Registration
10
+
11
+ # register filters and appenders
12
+ def initialize(init_options)
13
+ register_filters(init_options.filters)
14
+ register_appenders(init_options.appenders)
15
+ end
16
+
17
+ # action for tracelogs that pass the filters
18
+ # by default send to all appenders for further processing!
19
+ def handle_allow(txt, context)
20
+ appenders.each do |appender|
21
+ appender.handle(txt, context)
22
+ end
23
+ end
24
+
25
+ # action for tracelogs that DO NOT pass the filters
26
+ def handle_not_allow(txt, context)
27
+ end
28
+
29
+ # handle tracelogs by applying filters and action handler methods
30
+ def handle(txt, context)
31
+ if filters_allow?(txt, context)
32
+ # puts "handle_allow: " + context[:method_name]
33
+ handle_allow(txt, context)
34
+ else
35
+ # puts "handle_not_allow: " + context[:method_name]
36
+ handle_not_allow(txt, context)
37
+ end
38
+ end
39
+ end # class
40
+ end # module
@@ -1,14 +1,5 @@
1
- require 'filters/tracing_filter'
2
- require 'trace_appenders'
3
-
4
1
  module Tracing
5
2
  class ActionHandler
6
- include Tracing::Filter::Registration
7
- include Tracing::Filter::Exec
8
- include Tracing::Appender::Registration
9
-
10
- attr_accessor :filters
11
-
12
3
  # enable registration of action handlers
13
4
  module Registration
14
5
  attr_accessor :action_handlers
@@ -44,7 +35,7 @@ module Tracing
44
35
  reg_action_handlers
45
36
  end
46
37
  end
47
-
38
+
48
39
  def create_action_handler(options)
49
40
  if options.kind_of? Tracing::ActionHandler
50
41
  options
@@ -66,34 +57,5 @@ module Tracing
66
57
  @action_handlers << new_action_handlers
67
58
  end
68
59
  end
69
-
70
- # register filters and appenders
71
- def initialize(init_options)
72
- register_filters(init_options[:filters])
73
- register_appenders(init_options[:appenders] || init_options)
74
- end
75
-
76
- # action for tracelogs that pass the filters
77
- # by default send to all appenders for further processing!
78
- def handle_allow(txt, context)
79
- appenders.each do |appender|
80
- appender.handle(txt, context)
81
- end
82
- end
83
-
84
- # action for tracelogs that DO NOT pass the filters
85
- def handle_not_allow(txt, context)
86
- end
87
-
88
- # handle tracelogs by applying filters and action handler methods
89
- def handle(txt, context)
90
- if filters_allow?(txt, context)
91
- # puts "handle_allow: " + context[:method_name]
92
- handle_allow(txt, context)
93
- else
94
- # puts "handle_not_allow: " + context[:method_name]
95
- handle_not_allow(txt, context)
96
- end
97
- end
98
- end # class
99
- end # module
60
+ end
61
+ end
@@ -6,21 +6,9 @@ module Tracing
6
6
  # array of Appender instances
7
7
  attr_accessor :appender_mappings
8
8
 
9
- # used to help construct/register Appender instances using convenience symbols
10
- def default_appender_mappings
11
- {
12
- :logger => Tracing::LoggerAppender,
13
- :stream => Tracing::StreamAppender,
14
- :xml => Tracing::XmlAppender,
15
- :html => Tracing::HtmlAppender,
16
- :template => Tracing::TemplateLogAppender,
17
- :default => Tracing::StreamAppender
18
- }
19
- end
20
-
21
9
  def register_default_mappings
22
10
  @appender_mappings ||= {}
23
- @appender_mappings.merge!(default_appender_mappings)
11
+ @appender_mappings.merge!(Mappings.default_appender_mappings)
24
12
  end
25
13
 
26
14
  def register_appender_mappings(_appender_mappings)
@@ -0,0 +1,13 @@
1
+ module AppenderMappings
2
+ # used to help construct/register Appender instances using convenience symbols
3
+ def self.defaults
4
+ {
5
+ :logger => Tracing::LoggerAppender,
6
+ :stream => Tracing::StreamAppender,
7
+ :xml => Tracing::XmlAppender,
8
+ :html => Tracing::HtmlAppender,
9
+ :template => Tracing::TemplateLogAppender,
10
+ :default => Tracing::StreamAppender
11
+ }
12
+ end
13
+ end
@@ -1,8 +1,7 @@
1
1
  module Tracing
2
2
  # base appender (abstract)
3
3
  class BaseAppender
4
- include Tracing::Filter::Registration
5
- include Tracing::Filter::Exec
4
+ include Tracing::FilterUse
6
5
 
7
6
  attr_accessor :options
8
7
  attr_reader :tracer
@@ -10,17 +9,9 @@ module Tracing
10
9
  class << self
11
10
  attr_accessor :tracers
12
11
 
13
- def default_tracers
14
- {
15
- :string => Tracing::OutputTemplate::StringTrace,
16
- :xml => Tracing::OutputTemplate::XmlTrace,
17
- :html => Tracing::OutputTemplate::HtmlTrace,
18
- :default => Tracing::OutputTemplate::StringTrace
19
- }
20
- end
21
12
 
22
13
  def register_tracers(tracers = nil)
23
- @tracers ||= default_tracers
14
+ @tracers ||= {} # default_tracers
24
15
  @tracers = @tracers.merge!(tracers || {})
25
16
  end
26
17
 
@@ -1,19 +1,26 @@
1
+ module Tracing
2
+ module DefaultPath
3
+ def default_path
4
+ return if !@default_path
5
+ if !File.exists?(@default_path)
6
+ FileUtils.mkdir_p @default_path
7
+ end
8
+ @default_path
9
+ end
10
+
11
+ def default_path=(path)
12
+ @default_path = path
13
+ end
14
+ end
15
+ end
16
+
17
+
1
18
  module Tracing
2
19
  # File Appender
3
20
  class FileAppender < BaseAppender
4
-
21
+ include Tracing::DefaultPath
5
22
  class << self
6
- def default_path
7
- return if !@default_path
8
- if !File.exists?(@default_path)
9
- FileUtils.mkdir_p @default_path
10
- end
11
- @default_path
12
- end
13
-
14
- def default_path=(path)
15
- @default_path = path
16
- end
23
+ include Tracing::DefaultPath
17
24
  end
18
25
 
19
26
  # file
@@ -49,7 +56,8 @@ module Tracing
49
56
  end
50
57
 
51
58
  def file_path(file)
52
- file = File.join(self.class.default_path, file) if self.class.default_path
59
+ def_path = default_path || self.class.default_path
60
+ file = File.join(def_path, file) if self.class.default_path
53
61
  end
54
62
 
55
63
  protected
@@ -0,0 +1,4 @@
1
+ require 'appenders/base_appender'
2
+ include_folder('appenders')
3
+ include_folder_rec('appenders/types')
4
+
@@ -0,0 +1,2 @@
1
+ Html and Xml appenders should not be hardcoded to append to a file
2
+ Simply include a FileAppender as a strategy if configured for this, but use file as default output strategy
@@ -1,27 +1,7 @@
1
- # surround html ouput with wrapper-html
2
- # include jquery and css
3
- # collapse non-important regions and expand important ones
4
-
5
- # TODO: how to ensure html ouput finishes
6
- # file.seek(-20, IO:SEEK_END)
7
1
  module Tracing
8
2
  class HtmlAppender < FileAppender
9
3
  attr_accessor :to_file, :html_output
10
4
 
11
- class << self
12
- def default_path
13
- return if !@default_path
14
- if !File.exists?(@default_path)
15
- FileUtils.mkdir_p @default_path
16
- end
17
- @default_path
18
- end
19
-
20
- def default_path=(path)
21
- @default_path = path
22
- end
23
- end
24
-
25
5
  def initialize(init_options = nil)
26
6
  @tracer = Tracing::OutputTemplate::HtmlTrace.new
27
7
  super(init_options)
@@ -30,6 +10,10 @@ module Tracing
30
10
  return if !init_options
31
11
  # write to file
32
12
  @to_file = init_options[:to_file]
13
+
14
+ # override default path for class
15
+ @default_path = init_options[:default_path]
16
+
33
17
  if @to_file
34
18
  write_wrap_file(to_file)
35
19
  else
@@ -17,7 +17,7 @@ module Tracing
17
17
  end
18
18
  end
19
19
 
20
- def initialize(init_options)
20
+ def initialize(init_options = nil)
21
21
  @tracer = Tracing::OutputTemplate::XmlTrace.new
22
22
  super(init_options)
23
23
  @xml_output = xml_begin
@@ -0,0 +1,42 @@
1
+ class Array
2
+ include Tracing::RuleMatch
3
+
4
+ def add(obj)
5
+ self << obj
6
+ self.flatten!
7
+ self.compact! if self
8
+ end
9
+
10
+ def rule_list
11
+ self
12
+ end
13
+
14
+ # iterate and return filters array
15
+ def filters
16
+ _filters = []
17
+ self.each do |_filter|
18
+ _filters.add(_filter.filters)
19
+ end
20
+ _filters
21
+ end
22
+
23
+ # iterate and return action_handlers array
24
+ def action_handlers
25
+ _action_handlers = []
26
+ self.each do |_action_handler|
27
+ _action_handlers.add(_action_handler.action_handlers)
28
+ end
29
+ _action_handlers
30
+ end
31
+
32
+ # iterate and return action_handlers array
33
+ def appenders
34
+ _appenders = []
35
+ self.each do |_appender|
36
+ _appenders.add(_appender.appenders)
37
+ end
38
+ _appenders
39
+ end
40
+
41
+
42
+ end
@@ -0,0 +1,181 @@
1
+ class Hash
2
+
3
+ def context
4
+ modules = self[:modules]
5
+ cls_name = self[:class_name]
6
+ method_name = self[:method_name]
7
+ self[:modules] = cls_name.modules if cls_name && !modules
8
+ self[:class_name] = cls_name.class_name if cls_name
9
+ calculate_full_names
10
+ end
11
+
12
+ def method_name=(name)
13
+ self[:method_name] = name
14
+ calculate_full_method_name
15
+ end
16
+
17
+ def result=(res)
18
+ self[:result] = res
19
+ end
20
+
21
+
22
+ def set_context(hash)
23
+ modules = hash[:modules]
24
+ cls_name = hash[:class_name]
25
+ method_name = hash[:method_name]
26
+ args = hash[:args]
27
+ vars = hash[:vars]
28
+ self[:modules] = cls_name.modules if cls_name
29
+ self[:modules] = modules if modules
30
+
31
+ self[:class_name] = cls_name.class_name if cls_name
32
+ self[:method_name] = method_name if method_name
33
+ self[:args] = args if args
34
+ self[:vars] = vars if vars
35
+
36
+ calculate_full_names
37
+ end
38
+
39
+ def full_modules_name
40
+ self[:modules].join("::") if self[:modules]
41
+ end
42
+
43
+ def full_class_name
44
+ mod_name = self.full_modules_name
45
+ name = self[:class_name]
46
+ name = "#{mod_name}::#{name}" if !mod_name.blank?
47
+ end
48
+
49
+ def full_method_name
50
+ cls_name = self.full_class_name
51
+ name = self[:method_name]
52
+ name = "#{cls_name}.#{name}" if !cls_name.blank?
53
+ end
54
+
55
+
56
+ def configuration
57
+ Tracing::Configuration.new(self)
58
+ end
59
+
60
+ def final_yield_action
61
+ self[:final_yield_action] || :include
62
+ end
63
+
64
+ # return filter
65
+ def filters
66
+ filter_list = self[:filters]
67
+ # puts "filter_list: #{filter_list.inspect}"
68
+ if filter_list
69
+ filter_list.filters
70
+ else
71
+ # puts "create filter from: #{self.inspect}"
72
+ x = self.create_filter
73
+ # puts "created filter: #{x.inspect}"
74
+ x
75
+ end
76
+ end
77
+
78
+ # return action_handler
79
+ def action_handlers
80
+ action_handler_list = self[:action_handlers]
81
+ if action_handler_list
82
+ action_handler_list.action_handlers
83
+ else
84
+ Tracing::ActionHandler.new(self)
85
+ end
86
+ end
87
+
88
+ # return action_handler
89
+ def appenders
90
+ appender_list = self[:appenders]
91
+ appender_list.appenders
92
+ end
93
+
94
+ # return tracer
95
+ def tracer
96
+ tracer_key = self[:tracer]
97
+ tracer_class = Mappings.default_tracer_mappings[tracer_key]
98
+ tracer_class.new
99
+ end
100
+
101
+ def create_filter
102
+ return self.filters if self[:filters]
103
+ hash = self.create_filter_hash || self
104
+ if hash
105
+ filter_class = hash.filter_class
106
+ # puts "hash: #{hash.inspect} -> class: #{filter_class}"
107
+ return filter_class.new(hash) if filter_class
108
+ end
109
+ nil
110
+ end
111
+
112
+ def create_filter_hash
113
+ # puts "TRY create_filter: " + name_hash.inspect
114
+ [:module_filter, :class_filter, :method_filter, :vars_filter].each do |symbol|
115
+ # puts "symbol:" + symbol.to_s
116
+ res = self.try_create_filter_hash(symbol)
117
+ # puts "Filter created:" + res.inspect
118
+ return res if res
119
+ end
120
+ # puts "no filter could be created :("
121
+ nil
122
+ end
123
+
124
+ def try_create_filter_hash(symbol)
125
+ _symbol = has_any_prefix(symbol)
126
+ puts _symbol.inspect
127
+ return if !_symbol
128
+
129
+ prefix = _symbol[:prefix]
130
+ filter_sym = _symbol[:filter_symbol]
131
+ #
132
+ filter_names = self[filter_sym]
133
+ #
134
+ rule_symbol = prefix.to_sym.rule
135
+ {symbol => {rule_symbol => filter_names}}
136
+ end
137
+
138
+ def map(key)
139
+ clazz = self[key]
140
+ return clazz if clazz
141
+ self[:default]
142
+ end
143
+
144
+ def filter_class
145
+ Mappings.convenience_map.select do |key, _filter|
146
+ return _filter.filter_class if self.has_key?(key) || self.has_key?(_filter)
147
+ end
148
+ Mappings.filter_rule_mappings.select do |key, _filter|
149
+ return _filter.filter_class if self.has_key? key
150
+ end
151
+ nil
152
+ end
153
+
154
+ protected
155
+
156
+ def calculate_full_names
157
+ self[:full_modules_name] = full_modules_name
158
+ self[:full_class_name] = full_class_name
159
+ calculate_full_method_name
160
+ end
161
+
162
+ def calculate_full_method_name
163
+ self[:full_method_name] = full_method_name
164
+ end
165
+
166
+ def has_prefix(symbol, prefix)
167
+ sym = symbol.prefix(prefix)
168
+ self.has_key?(sym) ? {:filter_symbol => sym, :prefix => prefix} : false
169
+ end
170
+
171
+ def has_any_prefix(symbol)
172
+ ['iy', 'xy', 'i', 'x'].each do |prefix|
173
+ hash_result = has_prefix(symbol, prefix)
174
+ return hash_result if hash_result
175
+ end
176
+ false
177
+ end
178
+ end
179
+
180
+
181
+
@@ -0,0 +1,50 @@
1
+ class Hash
2
+ include Tracing::RuleMatch
3
+
4
+ def rules_allow_action(name)
5
+ rule_allow_action(name)
6
+ end
7
+
8
+ def rule_list
9
+ rules
10
+ end
11
+
12
+ # return a symbol, either - :include, :exclude or :exclude_and_yield, :include_and_yield or :yield (let next filter decide)
13
+ def rule_allow_action(name)
14
+ include_rules = self[:include].rule_list
15
+ if !include_rules.blank?
16
+ # puts "Rule include"
17
+ res = include_rules.matches_any?(name)
18
+ return :include if res
19
+ end
20
+ exclude_rules = self[:exclude].rule_list
21
+ if !exclude_rules.blank?
22
+ # puts "Rule exclude"
23
+ return :exclude if exclude_rules.matches_any?(name)
24
+ end
25
+
26
+ rules = self[:exclude_and_yield].rule_list
27
+ if !rules.blank?
28
+ # puts "Rule exclude"
29
+ return :exclude_and_yield if rules.matches_any?(name)
30
+ end
31
+
32
+ rules = self[:include_and_yield].rule_list
33
+ if !rules.blank?
34
+ # puts "Rule exclude"
35
+ return :include_and_yield if rules.matches_any?(name)
36
+ end
37
+
38
+
39
+ # puts "Not included or excluded"
40
+ if !self[:default].nil?
41
+ # puts "Return default: #{self[:default]}"
42
+ return self[:default]
43
+ end
44
+ # puts "Rule yields"
45
+ return :yield
46
+ rescue RuleTypeError
47
+ # puts "error"
48
+ return :exclude
49
+ end
50
+ end
@@ -0,0 +1 @@
1
+ Dir.glob(File.join(File.dirname(__FILE__), '**/*.rb')).each {|f| require f }
@@ -0,0 +1,10 @@
1
+ class NilClass
2
+ def rule_list
3
+ nil
4
+ end
5
+
6
+ def split_names
7
+ nil
8
+ end
9
+
10
+ end
@@ -0,0 +1,19 @@
1
+ class Object
2
+ def blank?
3
+ respond_to?(:empty?) ? empty? : !self
4
+ end
5
+
6
+ def rule_list
7
+ self
8
+ end
9
+
10
+ def appenders
11
+ self
12
+ end
13
+
14
+ def filters
15
+ self
16
+ end
17
+
18
+ end
19
+
@@ -0,0 +1,35 @@
1
+ class String
2
+ def modules
3
+ self.split("::")[0..-2]
4
+ end
5
+
6
+ def class_name
7
+ name = self.split("::")[-1..-1]
8
+ name = name[0] if name.kind_of? Array
9
+ name
10
+ end
11
+
12
+ def in_module?(module_name)
13
+ modules = self.modules
14
+ modules.include?(module_name)
15
+ end
16
+
17
+ def rule_list
18
+ self.split_names
19
+ end
20
+
21
+ def split_names
22
+ if self.include?(",")
23
+ s = self.gsub(/\s/, '')
24
+ s.split(",") if s
25
+ else
26
+ self.split(" ")
27
+ end
28
+ end
29
+
30
+ # return name matching rules as array
31
+ # split " ", ","
32
+ def rules
33
+ end
34
+
35
+ end
@@ -0,0 +1,30 @@
1
+ class Symbol
2
+ def prefix(pre)
3
+ (pre.to_s + '_' + self.to_s).to_sym
4
+ end
5
+
6
+ def filter_class
7
+ mapper = Mappings.default_filters
8
+ mapper.map(self)
9
+ end
10
+
11
+ def trace_class
12
+ mapper = Mappings::default_tracer_mappings
13
+ mapper.map(self)
14
+ end
15
+
16
+ def appender_class
17
+ mapper = Mappings::default_appender_mappings
18
+ mapper.map(self)
19
+ end
20
+
21
+ def rule
22
+ mapper = Mappings::rule_symbol_mappings
23
+ mapper.map(self)
24
+ end
25
+
26
+ def appenders
27
+ self.appender_class.new
28
+ end
29
+
30
+ end