iudex-filter 1.2.1-java → 1.3.0-java

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,11 @@
1
+ === 1.3.0 (2012-11-8)
2
+ * Upgrade/narrow to slf4j ~> 1.7.0, logback ~> 1.5
3
+ * Add FilterChain.alwaysPass option
4
+ * Add alternative create_chain options Hash syntax
5
+ * Add fltr_method and support,cleanup in ProcFilter
6
+ * Simplify KeyHelper.keys
7
+ * Misc java logging simplifications with slf4j 1.7 varargs
8
+
1
9
  === 1.2.1 (2012-9-15)
2
10
  * Upgrade/narrow to gravitext-util ~> 1.6.1
3
11
  * Upgrade to slf4j [1.6.5,1.8), logback ~> 1.2
@@ -15,4 +15,4 @@ test/test_filter_base.rb
15
15
  test/test_filter_chain_factory.rb
16
16
  test/test_proc_filter.rb
17
17
  test/test_sublist_filter.rb
18
- lib/iudex-filter/iudex-filter-1.2.1.jar
18
+ lib/iudex-filter/iudex-filter-1.3.0.jar
@@ -16,7 +16,7 @@
16
16
 
17
17
  module Iudex
18
18
  module Filter
19
- VERSION = '1.2.1'
19
+ VERSION = '1.3.0'
20
20
 
21
21
  LIB_DIR = File.dirname( __FILE__ ) # :nodoc:
22
22
  end
@@ -67,7 +67,9 @@ module Iudex
67
67
  flts = filters.flatten.compact
68
68
  log_and_register( flts )
69
69
 
70
- @chain = create_chain( @description, flts, :main )
70
+ @chain = create_chain( :desc => @description,
71
+ :filters => flts,
72
+ :listener => :main )
71
73
  @listener = ListenerChain.new( listeners )
72
74
 
73
75
  # Now replace the temp listener with the final listener
@@ -120,41 +122,78 @@ module Iudex
120
122
  @main_by_filter_period )
121
123
  end
122
124
 
123
- # Create, yield to optional block, and return FilterChain if
124
- # flts is not empty. Otherwise return a NoOpFilter and don't
125
- # yield. If passed a Symbol desc and nil flts, will use both
126
- # as description and method to obtain flts array from.
127
- def create_chain( desc, flts = nil, listener = nil )
125
+ # Create, yield to optional block, and returns FilterChain if
126
+ # provided filters is not empty. If empty returns a NoOpFilter
127
+ # but does not yield.
128
+ #
129
+ # A trailing Hash argument is interpreted as options, see
130
+ # below. Alternative positional parameters equivalent to
131
+ # either the following are deprecated:
132
+ #
133
+ # * filters (Symbol), nil, listener = nil
134
+ # * desc (~to_s), filters = nil, listener = nil
135
+ #
136
+ # === Options
137
+ #
138
+ # :desc:: ~>to_s Description of this chain.
139
+ # :filters:: Symbol method name to send for filters (and also
140
+ # default description), or an Array of filters.
141
+ # :listener:: The :main symbol for this filter chains
142
+ # listeners, or an alternative FilterListener
143
+ # instance.
144
+ # :pass:: If truthy, the chain always returns true (pass) on
145
+ # filter.
146
+ #
147
+ def create_chain( *args )
148
+
149
+ opts = args.last.is_a?( Hash ) ? args.pop.dup : {}
150
+
151
+ # Fold in deprecated positional parameters
152
+ if args[ 0 ].is_a?( Symbol ) && args[ 1 ].nil?
153
+ opts[ :filters ] ||= args[ 0 ]
154
+ else
155
+ opts[ :desc ] ||= args[ 0 ]
156
+ opts[ :filters ] ||= args[ 1 ]
157
+ end
158
+
159
+ opts[ :listener ] ||= args[ 2 ]
128
160
 
129
- if desc.is_a?( Symbol )
130
- flts = send( desc ) unless flts
131
- desc = desc.to_s.gsub( /_/, '-' )
161
+ # Handle special case of symbol for :filters
162
+ if opts[ :filters ].is_a?( Symbol )
163
+ opts[ :desc ] ||= opts[ :filters ].to_s.gsub( /_/, '-' )
164
+ opts[ :filters ] = send( opts[ :filters ] )
132
165
  end
133
166
 
134
- flts = flts.flatten.compact if flts
167
+ flts = Array( opts[ :filters ] ).flatten.compact
135
168
 
136
- if flts.nil? || flts.empty?
169
+ if flts.empty?
137
170
  NoOpFilter.new
138
171
  else
139
- c = FilterChain.new( desc, flts )
140
- if listener.nil?
141
- c.listener = log_listener( desc )
142
- elsif listener == :main
143
- c.listener = @listener
172
+ chain = FilterChain.new( opts[ :desc ], flts )
173
+
174
+ if opts[ :listener ] == :main
175
+ chain.listener = @listener
176
+ elsif opts[ :listener ].nil?
177
+ chain.listener = log_listener( opts[ :desc ] )
144
178
  else
145
- c.listener = listener
179
+ chain.listener = opts[ :listener ]
146
180
  end
147
- yield c if block_given?
148
- c
181
+
182
+ chain.always_pass = true if opts[ :pass ]
183
+
184
+ yield chain if block_given?
185
+ chain
149
186
  end
150
187
  end
151
188
 
152
189
  # Create a new Switch given selector key and map of values to
153
- # filters, or values to [filters,listener]
190
+ # filters, or values to [ filters, listener ]
154
191
  def create_switch( key, value_filters_map )
155
192
  switch = Switch.new
156
193
  value_filters_map.each do |value, (filters, listener)|
157
- create_chain( value.to_s.downcase, filters, listener ) do |chain|
194
+ create_chain( :desc => value.to_s.downcase,
195
+ :filters => filters,
196
+ :listener => listener ) do |chain|
158
197
  switch.add_proposition( Selector.new( key, value ), chain )
159
198
  end
160
199
  end
@@ -47,9 +47,9 @@ module Iudex
47
47
 
48
48
  # Map Symbols to Keys
49
49
  def keys( *syms )
50
- syms = syms[0] if ( syms[0] && syms[0].respond_to?( :each ) )
51
- syms.map { |s| s.to_k }.uniq
50
+ syms.flatten.compact.map { |s| s.to_k }.uniq
52
51
  end
52
+
53
53
  module_function :keys
54
54
  end
55
55
  end
@@ -18,30 +18,62 @@ require 'iudex-filter/filter_base'
18
18
 
19
19
  module Iudex::Filter
20
20
 
21
- # Short hand for ProcFilter.new
22
- def fltr( &block )
23
- ProcFilter.new( caller.first, &block )
21
+ # Short hand for ProcFilter.new( opts, &block )
22
+ def fltr( opts = {}, &block )
23
+ ProcFilter.new( { :caller => caller.first }.merge( opts ), &block )
24
24
  end
25
25
 
26
+ # Return a Procfilter using method( map ) identified by method_symbol
27
+ # in self's scope as filter. The default :desc is [ method_symbol ].
28
+ def fltr_method( method_symbol, opts = {} )
29
+ ProcFilter.new( { :desc => [ method_symbol ] }.merge( opts ),
30
+ &( method method_symbol ) )
31
+ end
32
+
33
+ # A filter wrapping a Ruby Proc.
26
34
  class ProcFilter < FilterBase
27
35
 
28
- # New ProcFilter using block as implmentation of
29
- # Filter.filter( map ). The created filter will only return false
30
- # (reject map, stop chain) if the block returns the :reject
31
- # symbol.
32
- def initialize( clr = nil, &block )
36
+ # Use block as implementation of filter(map). The filter will
37
+ # only return false (reject map, stop chain) if the block returns
38
+ # the :reject symbol. All other return values are ignored,
39
+ # including "false".
40
+ #
41
+ # === Options
42
+ #
43
+ # Passing a String for opts is interpreted as :caller (deprecated
44
+ # as of 1.3.0)
45
+ #
46
+ # :caller:: String from which to compose the description. This is
47
+ # used under Ruby 1.8 only, obtained via
48
+ # block.source_location in 1.9.
49
+ #
50
+ # :desc:: Array<~to_s> description (overrides caller)
51
+ #
52
+ def initialize( opts = {}, &block )
33
53
  @block = block
34
54
 
35
- clr ||= caller.first
36
- clr = clr.split( /:/ )
37
- @description = [ File.basename( clr[0], ".rb" ), clr[1].to_i ]
38
- #FIXME: When ruby 1.9, can use Proc.source_location instead.
55
+ opts = { :caller => opts } if opts.is_a?( String )
56
+ @description = Array( opts[ :desc ] ).compact
57
+
58
+ if @description.empty?
59
+ if @block.respond_to?( :source_location ) # ruby 1.9
60
+ clr = @block.source_location
61
+ else # ruby 1.8
62
+ clr = opts[ :caller ] || caller.first
63
+ clr = clr.split( /:/ )
64
+ end
65
+
66
+ @description = [ File.basename( clr[0], ".rb" ), clr[1].to_i ]
67
+ end
68
+
39
69
  end
40
70
 
41
71
  def describe
42
72
  @description
43
73
  end
44
74
 
75
+ # Calls initialized block, returning true if it returns anything
76
+ # but :reject
45
77
  def filter( map )
46
78
  ( @block.call( map ) != :reject )
47
79
  end
data/pom.xml CHANGED
@@ -5,13 +5,13 @@
5
5
  <groupId>iudex</groupId>
6
6
  <artifactId>iudex-filter</artifactId>
7
7
  <packaging>jar</packaging>
8
- <version>1.2.1</version>
8
+ <version>1.3.0</version>
9
9
  <name>Iudex Filter</name>
10
10
 
11
11
  <parent>
12
12
  <groupId>iudex</groupId>
13
13
  <artifactId>iudex-parent</artifactId>
14
- <version>1.2.1</version>
14
+ <version>1.3.0</version>
15
15
  <relativePath>..</relativePath>
16
16
  </parent>
17
17
 
@@ -83,12 +83,66 @@ class TestFilterChainFactory < MiniTest::Unit::TestCase
83
83
 
84
84
  end
85
85
 
86
+ def test_create_chain_noop
87
+ fcf = FilterChainFactory.new( "test" )
88
+ fc = fcf.create_chain() { |c| flunk( "NoOpFilter no yield" ) }
89
+ assert_kind_of( NoOpFilter, fc )
90
+ end
91
+
92
+ def test_create_chain_legacy_params
93
+ fcf = FilterChainFactory.new( "test" )
94
+ class << fcf
95
+ def filters_method
96
+ [ nil, [ RandomFilter.new ] ]
97
+ end
98
+ end
99
+
100
+ yielded = nil
101
+ fc = fcf.create_chain( :filters_method, nil, :main ) { |c| yielded = c }
102
+ assert_kind_of( FilterChain, fc )
103
+ assert_equal( fc, yielded )
104
+ assert_equal( 1, fc.children.length )
105
+ assert_equal( [ 'filters-method' ], Array( fc.describe ) )
106
+ assert_kind_of( RandomFilter, fc.children.first )
107
+
108
+ yielded = nil
109
+ fc = fcf.create_chain( :filters_method ) { |c| yielded = c }
110
+ assert_kind_of( FilterChain, fc )
111
+ assert_equal( fc, yielded )
112
+ assert_equal( [ 'filters-method' ], Array( fc.describe ) )
113
+ assert_equal( 1, fc.children.length )
114
+ assert_kind_of( RandomFilter, fc.children.first )
115
+ assert_kind_of( LogListener, fc.listener )
116
+ end
117
+
118
+ def test_create_chain_opts
119
+ fcf = FilterChainFactory.new( "test" )
120
+ class << fcf
121
+ def filters_method
122
+ [ nil, [ RandomFilter.new ] ]
123
+ end
124
+ end
125
+ yielded = nil
126
+ fc = fcf.create_chain( :desc => 'described',
127
+ :filters => :filters_method,
128
+ :listener => NoOpListener.new,
129
+ :pass => true ) do |c|
130
+ yielded = c
131
+ end
132
+ assert_kind_of( FilterChain, fc )
133
+ assert_equal( fc, yielded )
134
+ assert_equal( [ 'described' ], Array( fc.describe ) )
135
+ assert_equal( 1, fc.children.length )
136
+ assert_kind_of( RandomFilter, fc.children.first )
137
+ assert_kind_of( NoOpListener, fc.listener )
138
+ end
139
+
86
140
  def test_nested_reporting
87
141
  fcf = FilterChainFactory.new( "test" )
88
142
  class << fcf
89
143
  attr_accessor :summary_reporter
90
144
  def filters
91
- [ create_chain( :sub_filters, nil, :main ) ]
145
+ [ create_chain( :filters => :sub_filters, :listener => :main ) ]
92
146
  end
93
147
  def listeners
94
148
  super.tap do |ll|
@@ -29,18 +29,41 @@ class TestProcFilter < MiniTest::Unit::TestCase
29
29
  UniMap.create_key( 'mkey' )
30
30
  UniMap.define_accessors
31
31
 
32
- def test_describe
32
+ def test_describe_proc
33
33
  assert_equal( [ 'test_proc_filter', __LINE__ ], fltr {}.describe )
34
34
  assert_equal( [ 'test_proc_filter', __LINE__ ], ProcFilter.new {}.describe )
35
35
  assert_equal( [ 'test_proc_filter', __LINE__ ], ProcFilter.new {}.describe )
36
36
  end
37
37
 
38
- def test_name
38
+ def test_name_proc
39
39
  index = Core::FilterIndex.new
40
40
  name, line = index.register( fltr {} ), __LINE__
41
41
  assert_equal( "i.f.ProcFilter-test_proc_filter-#{line}", name )
42
42
  end
43
43
 
44
+ def test_describe_method
45
+ assert_equal( [ :filter_m_reject ],
46
+ fltr_method( :filter_m_reject ).describe )
47
+ end
48
+
49
+ def test_name_method
50
+ index = Core::FilterIndex.new
51
+ name = index.register( fltr_method( :filter_m_reject ) )
52
+ assert_equal( "i.f.ProcFilter-filter_m_reject", name )
53
+ end
54
+
55
+ def test_return_method
56
+ assert do_f( fltr_method :filter_m_happy )
57
+ refute do_f( fltr_method :filter_m_reject )
58
+ end
59
+
60
+ def filter_m_reject( map )
61
+ :reject
62
+ end
63
+
64
+ def filter_m_happy( map )
65
+ end
66
+
44
67
  def test_return
45
68
  assert do_f( fltr { } )
46
69
  assert do_f( fltr { nil } )
metadata CHANGED
@@ -1,137 +1,154 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: iudex-filter
3
- version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 1.2.1
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 1.3.0
6
6
  platform: java
7
- authors:
8
- - David Kellum
9
- autorequire:
7
+ authors:
8
+ - David Kellum
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2012-09-15 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: rjack-slf4j
17
- version_requirements: &id001 !ruby/object:Gem::Requirement
18
- none: false
19
- requirements:
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 1.6.5
23
- - - <
24
- - !ruby/object:Gem::Version
25
- version: "1.8"
26
- requirement: *id001
27
- prerelease: false
28
- type: :runtime
29
- - !ruby/object:Gem::Dependency
30
- name: gravitext-util
31
- version_requirements: &id002 !ruby/object:Gem::Requirement
32
- none: false
33
- requirements:
34
- - - ~>
35
- - !ruby/object:Gem::Version
36
- version: 1.6.1
37
- requirement: *id002
38
- prerelease: false
39
- type: :runtime
40
- - !ruby/object:Gem::Dependency
41
- name: minitest
42
- version_requirements: &id003 !ruby/object:Gem::Requirement
43
- none: false
44
- requirements:
45
- - - ~>
46
- - !ruby/object:Gem::Version
47
- version: "2.3"
48
- requirement: *id003
49
- prerelease: false
50
- type: :development
51
- - !ruby/object:Gem::Dependency
52
- name: rjack-logback
53
- version_requirements: &id004 !ruby/object:Gem::Requirement
54
- none: false
55
- requirements:
56
- - - ~>
57
- - !ruby/object:Gem::Version
58
- version: "1.2"
59
- requirement: *id004
60
- prerelease: false
61
- type: :development
62
- - !ruby/object:Gem::Dependency
63
- name: rjack-tarpit
64
- version_requirements: &id005 !ruby/object:Gem::Requirement
65
- none: false
66
- requirements:
67
- - - ~>
68
- - !ruby/object:Gem::Version
69
- version: "2.0"
70
- requirement: *id005
71
- prerelease: false
72
- type: :development
12
+ date: 2012-11-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rjack-slf4j
16
+ version_requirements: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: 1.7.0
21
+ none: false
22
+ requirement: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 1.7.0
27
+ none: false
28
+ prerelease: false
29
+ type: :runtime
30
+ - !ruby/object:Gem::Dependency
31
+ name: gravitext-util
32
+ version_requirements: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ~>
35
+ - !ruby/object:Gem::Version
36
+ version: 1.7.0
37
+ none: false
38
+ requirement: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ version: 1.7.0
43
+ none: false
44
+ prerelease: false
45
+ type: :runtime
46
+ - !ruby/object:Gem::Dependency
47
+ name: minitest
48
+ version_requirements: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ~>
51
+ - !ruby/object:Gem::Version
52
+ version: '2.3'
53
+ none: false
54
+ requirement: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ version: '2.3'
59
+ none: false
60
+ prerelease: false
61
+ type: :development
62
+ - !ruby/object:Gem::Dependency
63
+ name: rjack-logback
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1.5'
69
+ none: false
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ~>
73
+ - !ruby/object:Gem::Version
74
+ version: '1.5'
75
+ none: false
76
+ prerelease: false
77
+ type: :development
78
+ - !ruby/object:Gem::Dependency
79
+ name: rjack-tarpit
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ~>
83
+ - !ruby/object:Gem::Version
84
+ version: '2.0'
85
+ none: false
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ~>
89
+ - !ruby/object:Gem::Version
90
+ version: '2.0'
91
+ none: false
92
+ prerelease: false
93
+ type: :development
73
94
  description: Iudex is a general purpose web crawler and feed processor in ruby/java. The iudex-filter gem contains a fundamental filtering/chain of responsbility sub-system.
74
- email:
75
- - dek-oss@gravitext.com
95
+ email:
96
+ - dek-oss@gravitext.com
76
97
  executables: []
77
-
78
98
  extensions: []
79
-
80
- extra_rdoc_files:
81
- - History.rdoc
82
- - README.rdoc
83
- files:
84
- - History.rdoc
85
- - Manifest.txt
86
- - README.rdoc
87
- - Rakefile
88
- - pom.xml
89
- - lib/iudex-filter/base.rb
90
- - lib/iudex-filter.rb
91
- - lib/iudex-filter/by_filter_logger.rb
92
- - lib/iudex-filter/filter_base.rb
93
- - lib/iudex-filter/filter_chain_factory.rb
94
- - lib/iudex-filter/key_helper.rb
95
- - lib/iudex-filter/proc_filter.rb
96
- - test/setup.rb
97
- - test/test_filter_base.rb
98
- - test/test_filter_chain_factory.rb
99
- - test/test_proc_filter.rb
100
- - test/test_sublist_filter.rb
101
- - lib/iudex-filter/iudex-filter-1.2.1.jar
99
+ extra_rdoc_files:
100
+ - History.rdoc
101
+ - README.rdoc
102
+ files:
103
+ - History.rdoc
104
+ - Manifest.txt
105
+ - README.rdoc
106
+ - Rakefile
107
+ - pom.xml
108
+ - lib/iudex-filter/base.rb
109
+ - lib/iudex-filter.rb
110
+ - lib/iudex-filter/by_filter_logger.rb
111
+ - lib/iudex-filter/filter_base.rb
112
+ - lib/iudex-filter/filter_chain_factory.rb
113
+ - lib/iudex-filter/key_helper.rb
114
+ - lib/iudex-filter/proc_filter.rb
115
+ - test/setup.rb
116
+ - test/test_filter_base.rb
117
+ - test/test_filter_chain_factory.rb
118
+ - test/test_proc_filter.rb
119
+ - test/test_sublist_filter.rb
120
+ - lib/iudex-filter/iudex-filter-1.3.0.jar
102
121
  homepage: http://iudex.gravitext.com
103
122
  licenses: []
104
-
105
- post_install_message:
106
- rdoc_options:
107
- - --main
108
- - README.rdoc
109
- require_paths:
110
- - lib
111
- required_ruby_version: !ruby/object:Gem::Requirement
123
+ post_install_message:
124
+ rdoc_options:
125
+ - --main
126
+ - README.rdoc
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ segments:
135
+ - 0
136
+ hash: 2
112
137
  none: false
113
- requirements:
114
- - - ">="
115
- - !ruby/object:Gem::Version
116
- hash: 2
117
- segments:
118
- - 0
119
- version: "0"
120
- required_rubygems_version: !ruby/object:Gem::Requirement
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ! '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ segments:
144
+ - 0
145
+ hash: 2
121
146
  none: false
122
- requirements:
123
- - - ">="
124
- - !ruby/object:Gem::Version
125
- hash: 2
126
- segments:
127
- - 0
128
- version: "0"
129
147
  requirements: []
130
-
131
- rubyforge_project:
132
- rubygems_version: 1.8.15
133
- signing_key:
148
+ rubyforge_project:
149
+ rubygems_version: 1.8.24
150
+ signing_key:
134
151
  specification_version: 3
135
152
  summary: Iudex is a general purpose web crawler and feed processor in ruby/java.
136
153
  test_files: []
137
-
154
+ ...