herpes 0.0.1 → 0.0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/herpes.gemspec +1 -1
 - data/lib/herpes.rb +16 -18
 - data/lib/herpes/extensions.rb +1 -2
 - data/lib/herpes/module.rb +1 -1
 - data/lib/herpes/rss.rb +31 -10
 - data/lib/herpes/version.rb +1 -1
 - metadata +5 -6
 - data/lib/herpes/workers.rb +0 -26
 
    
        data/herpes.gemspec
    CHANGED
    
    
    
        data/lib/herpes.rb
    CHANGED
    
    | 
         @@ -10,7 +10,6 @@ 
     | 
|
| 
       10 
10 
     | 
    
         | 
| 
       11 
11 
     | 
    
         
             
            require 'herpes/version'
         
     | 
| 
       12 
12 
     | 
    
         
             
            require 'herpes/extensions'
         
     | 
| 
       13 
     | 
    
         
            -
            require 'herpes/workers'
         
     | 
| 
       14 
13 
     | 
    
         
             
            require 'herpes/event'
         
     | 
| 
       15 
14 
     | 
    
         
             
            require 'herpes/module'
         
     | 
| 
       16 
15 
     | 
    
         | 
| 
         @@ -74,12 +73,15 @@ class Herpes 
     | 
|
| 
       74 
73 
     | 
    
         
             
            		new.load(*path)
         
     | 
| 
       75 
74 
     | 
    
         
             
            	end
         
     | 
| 
       76 
75 
     | 
    
         | 
| 
       77 
     | 
    
         
            -
            	 
     | 
| 
      
 76 
     | 
    
         
            +
            	include Awakenable
         
     | 
| 
      
 77 
     | 
    
         
            +
            	extend Forwardable
         
     | 
| 
      
 78 
     | 
    
         
            +
             
     | 
| 
      
 79 
     | 
    
         
            +
            	attr_reader    :modules
         
     | 
| 
      
 80 
     | 
    
         
            +
            	def_delegators :@pool, :do, :process
         
     | 
| 
       78 
81 
     | 
    
         | 
| 
       79 
82 
     | 
    
         
             
            	def initialize
         
     | 
| 
      
 83 
     | 
    
         
            +
            		@pool    = ThreadPool.new
         
     | 
| 
       80 
84 
     | 
    
         
             
            		@modules = []
         
     | 
| 
       81 
     | 
    
         
            -
            		@workers = Workers.new
         
     | 
| 
       82 
     | 
    
         
            -
            		@pipes   = IO.pipe
         
     | 
| 
       83 
85 
     | 
    
         | 
| 
       84 
86 
     | 
    
         
             
            		@before   = Hash.new { |h, k| h[k] = [] }
         
     | 
| 
       85 
87 
     | 
    
         
             
            		@matchers = Hash.new { |h, k| h[k] = [] }
         
     | 
| 
         @@ -88,6 +90,10 @@ class Herpes 
     | 
|
| 
       88 
90 
     | 
    
         
             
            		@callbacks = []
         
     | 
| 
       89 
91 
     | 
    
         
             
            	end
         
     | 
| 
       90 
92 
     | 
    
         | 
| 
      
 93 
     | 
    
         
            +
            	def workers (number)
         
     | 
| 
      
 94 
     | 
    
         
            +
            		@pool.resize(number)
         
     | 
| 
      
 95 
     | 
    
         
            +
            	end
         
     | 
| 
      
 96 
     | 
    
         
            +
             
     | 
| 
       91 
97 
     | 
    
         
             
            	def state (path = nil)
         
     | 
| 
       92 
98 
     | 
    
         
             
            		if path && path != @path
         
     | 
| 
       93 
99 
     | 
    
         
             
            			@path  = File.expand_path(path)
         
     | 
| 
         @@ -198,19 +204,9 @@ class Herpes 
     | 
|
| 
       198 
204 
     | 
    
         
             
            	def until_next
         
     | 
| 
       199 
205 
     | 
    
         
             
            		next_in = @callbacks.min_by(&:next_in).next_in
         
     | 
| 
       200 
206 
     | 
    
         | 
| 
       201 
     | 
    
         
            -
            		next_in > 0 ? next_in :  
     | 
| 
      
 207 
     | 
    
         
            +
            		next_in > 0 ? next_in : nil
         
     | 
| 
       202 
208 
     | 
    
         
             
            	rescue
         
     | 
| 
       203 
     | 
    
         
            -
            		 
     | 
| 
       204 
     | 
    
         
            -
            	end
         
     | 
| 
       205 
     | 
    
         
            -
             
     | 
| 
       206 
     | 
    
         
            -
            	def sleep (time)
         
     | 
| 
       207 
     | 
    
         
            -
            		@pipes.first.read_nonblock 1337 rescue nil
         
     | 
| 
       208 
     | 
    
         
            -
             
     | 
| 
       209 
     | 
    
         
            -
            		IO.select([@pipes.first], nil, nil, time)
         
     | 
| 
       210 
     | 
    
         
            -
            	end
         
     | 
| 
       211 
     | 
    
         
            -
             
     | 
| 
       212 
     | 
    
         
            -
            	def wake_up
         
     | 
| 
       213 
     | 
    
         
            -
            		@pipes.last.write 'x'
         
     | 
| 
      
 209 
     | 
    
         
            +
            		nil
         
     | 
| 
       214 
210 
     | 
    
         
             
            	end
         
     | 
| 
       215 
211 
     | 
    
         | 
| 
       216 
212 
     | 
    
         
             
            	def running?; !!@running; end
         
     | 
| 
         @@ -231,7 +227,7 @@ class Herpes 
     | 
|
| 
       231 
227 
     | 
    
         | 
| 
       232 
228 
     | 
    
         
             
            				callback.gonna_call!
         
     | 
| 
       233 
229 
     | 
    
         | 
| 
       234 
     | 
    
         
            -
            				 
     | 
| 
      
 230 
     | 
    
         
            +
            				process {
         
     | 
| 
       235 
231 
     | 
    
         
             
            					callback.call
         
     | 
| 
       236 
232 
     | 
    
         
             
            				}
         
     | 
| 
       237 
233 
     | 
    
         
             
            			}
         
     | 
| 
         @@ -241,7 +237,9 @@ class Herpes 
     | 
|
| 
       241 
237 
     | 
    
         
             
            	end
         
     | 
| 
       242 
238 
     | 
    
         | 
| 
       243 
239 
     | 
    
         
             
            	def stop!
         
     | 
| 
       244 
     | 
    
         
            -
            		@running = false 
     | 
| 
      
 240 
     | 
    
         
            +
            		@running = false
         
     | 
| 
       245 
241 
     | 
    
         
             
            		wake_up
         
     | 
| 
      
 242 
     | 
    
         
            +
             
     | 
| 
      
 243 
     | 
    
         
            +
            		@pool.kill
         
     | 
| 
       246 
244 
     | 
    
         
             
            	end
         
     | 
| 
       247 
245 
     | 
    
         
             
            end
         
     | 
    
        data/lib/herpes/extensions.rb
    CHANGED
    
    | 
         @@ -9,6 +9,7 @@ 
     | 
|
| 
       9 
9 
     | 
    
         
             
            #++
         
     | 
| 
       10 
10 
     | 
    
         | 
| 
       11 
11 
     | 
    
         
             
            require 'forwardable'
         
     | 
| 
      
 12 
     | 
    
         
            +
            require 'threadpool'
         
     | 
| 
       12 
13 
     | 
    
         | 
| 
       13 
14 
     | 
    
         
             
            class Numeric
         
     | 
| 
       14 
15 
     | 
    
         
             
            	def seconds
         
     | 
| 
         @@ -56,7 +57,6 @@ class Object 
     | 
|
| 
       56 
57 
     | 
    
         
             
            			define_singleton_method "no_#{name}!" do
         
     | 
| 
       57 
58 
     | 
    
         
             
            				instance_variable_set "@#{name}", false
         
     | 
| 
       58 
59 
     | 
    
         
             
            			end
         
     | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
       60 
60 
     | 
    
         
             
            		}
         
     | 
| 
       61 
61 
     | 
    
         
             
            	end
         
     | 
| 
       62 
62 
     | 
    
         
             
            end
         
     | 
| 
         @@ -89,7 +89,6 @@ class Module 
     | 
|
| 
       89 
89 
     | 
    
         
             
            			define_method "no_#{name}!" do
         
     | 
| 
       90 
90 
     | 
    
         
             
            				instance_variable_set "@#{name}", false
         
     | 
| 
       91 
91 
     | 
    
         
             
            			end
         
     | 
| 
       92 
     | 
    
         
            -
             
     | 
| 
       93 
92 
     | 
    
         
             
            		}
         
     | 
| 
       94 
93 
     | 
    
         
             
            	end
         
     | 
| 
       95 
94 
     | 
    
         
             
            end
         
     | 
    
        data/lib/herpes/module.rb
    CHANGED
    
    
    
        data/lib/herpes/rss.rb
    CHANGED
    
    | 
         @@ -42,20 +42,33 @@ Herpes::Generator.define :rss do 
     | 
|
| 
       42 
42 
     | 
    
         
             
            			(state[:rss] ||= {})[r.url] ||= []
         
     | 
| 
       43 
43 
     | 
    
         | 
| 
       44 
44 
     | 
    
         
             
            			RSS::Parser.parse(open(r.url).read, false).tap {|p|
         
     | 
| 
       45 
     | 
    
         
            -
            				p.items. 
     | 
| 
       46 
     | 
    
         
            -
            					 
     | 
| 
      
 45 
     | 
    
         
            +
            				p.items.reverse_each {|item|
         
     | 
| 
      
 46 
     | 
    
         
            +
            					if p.is_a?(RSS::Atom::Feed)
         
     | 
| 
      
 47 
     | 
    
         
            +
            						next if state[:rss][r.url].member? [item.updated.content, item.title.content]
         
     | 
| 
      
 48 
     | 
    
         
            +
            					else
         
     | 
| 
      
 49 
     | 
    
         
            +
            						next if state[:rss][r.url].member? [item.date, item.title]
         
     | 
| 
      
 50 
     | 
    
         
            +
            					end
         
     | 
| 
       47 
51 
     | 
    
         | 
| 
       48 
52 
     | 
    
         
             
            					event = Herpes::Event.new {
         
     | 
| 
       49 
53 
     | 
    
         
             
            						tags  r.tags
         
     | 
| 
       50 
54 
     | 
    
         
             
            						group r.group
         
     | 
| 
       51 
55 
     | 
    
         
             
            						name  r.name
         
     | 
| 
       52 
56 
     | 
    
         | 
| 
       53 
     | 
    
         
            -
            						 
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
      
 57 
     | 
    
         
            +
            						if p.is_a?(RSS::Atom::Feed)
         
     | 
| 
      
 58 
     | 
    
         
            +
            							channel Struct.new(:title, :date, :link).new(p.title.content.dup, p.updated.content, p.link.href.dup)
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
      
 60 
     | 
    
         
            +
            							title       item.title.content.dup
         
     | 
| 
      
 61 
     | 
    
         
            +
            							link        item.link.href.dup
         
     | 
| 
      
 62 
     | 
    
         
            +
            							description item.content.content.dup
         
     | 
| 
      
 63 
     | 
    
         
            +
            							date        item.updated.content
         
     | 
| 
      
 64 
     | 
    
         
            +
            						else
         
     | 
| 
      
 65 
     | 
    
         
            +
            							channel p.channel.dup
         
     | 
| 
      
 66 
     | 
    
         
            +
             
     | 
| 
      
 67 
     | 
    
         
            +
            							title       item.title.dup
         
     | 
| 
      
 68 
     | 
    
         
            +
            							link        item.link.dup
         
     | 
| 
      
 69 
     | 
    
         
            +
            							description item.description.dup
         
     | 
| 
      
 70 
     | 
    
         
            +
            							date        item.date
         
     | 
| 
      
 71 
     | 
    
         
            +
            						end
         
     | 
| 
       59 
72 
     | 
    
         
             
            					}
         
     | 
| 
       60 
73 
     | 
    
         | 
| 
       61 
74 
     | 
    
         
             
            					if digest
         
     | 
| 
         @@ -64,12 +77,20 @@ Herpes::Generator.define :rss do 
     | 
|
| 
       64 
77 
     | 
    
         
             
            						dispatch(event)
         
     | 
| 
       65 
78 
     | 
    
         
             
            					end
         
     | 
| 
       66 
79 
     | 
    
         | 
| 
       67 
     | 
    
         
            -
            					 
     | 
| 
      
 80 
     | 
    
         
            +
            					if p.is_a?(RSS::Atom::Feed)
         
     | 
| 
      
 81 
     | 
    
         
            +
            						state[:rss][r.url].push [item.updated.content, item.title.content]
         
     | 
| 
      
 82 
     | 
    
         
            +
            					else
         
     | 
| 
      
 83 
     | 
    
         
            +
            						state[:rss][r.url].push [item.date, item.title]
         
     | 
| 
      
 84 
     | 
    
         
            +
            					end
         
     | 
| 
       68 
85 
     | 
    
         
             
            				}
         
     | 
| 
       69 
86 
     | 
    
         | 
| 
       70 
87 
     | 
    
         
             
            				state[:rss][r.url].reject! {|(date, title)|
         
     | 
| 
       71 
88 
     | 
    
         
             
            					p.items.none? {|item|
         
     | 
| 
       72 
     | 
    
         
            -
            						 
     | 
| 
      
 89 
     | 
    
         
            +
            						if p.is_a?(RSS::Atom::Feed)
         
     | 
| 
      
 90 
     | 
    
         
            +
            							 item.updated.content == date && item.title.content == title
         
     | 
| 
      
 91 
     | 
    
         
            +
            						else
         
     | 
| 
      
 92 
     | 
    
         
            +
            							item.date == date && item.title == title
         
     | 
| 
      
 93 
     | 
    
         
            +
            						end
         
     | 
| 
       73 
94 
     | 
    
         
             
            					}
         
     | 
| 
       74 
95 
     | 
    
         
             
            				}
         
     | 
| 
       75 
96 
     | 
    
         
             
            			}
         
     | 
    
        data/lib/herpes/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: herpes
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.0.1
         
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.0.1.1
         
     | 
| 
       5 
5 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       6 
6 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       7 
7 
     | 
    
         
             
            authors:
         
     | 
| 
         @@ -9,11 +9,11 @@ authors: 
     | 
|
| 
       9 
9 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       10 
10 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       11 
11 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       12 
     | 
    
         
            -
            date: 2011-11- 
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2011-11-25 00:00:00.000000000 Z
         
     | 
| 
       13 
13 
     | 
    
         
             
            dependencies:
         
     | 
| 
       14 
14 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       15 
     | 
    
         
            -
              name:  
     | 
| 
       16 
     | 
    
         
            -
              requirement: & 
     | 
| 
      
 15 
     | 
    
         
            +
              name: threadpool
         
     | 
| 
      
 16 
     | 
    
         
            +
              requirement: &14985100 !ruby/object:Gem::Requirement
         
     | 
| 
       17 
17 
     | 
    
         
             
                none: false
         
     | 
| 
       18 
18 
     | 
    
         
             
                requirements:
         
     | 
| 
       19 
19 
     | 
    
         
             
                - - ! '>='
         
     | 
| 
         @@ -21,7 +21,7 @@ dependencies: 
     | 
|
| 
       21 
21 
     | 
    
         
             
                    version: '0'
         
     | 
| 
       22 
22 
     | 
    
         
             
              type: :runtime
         
     | 
| 
       23 
23 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       24 
     | 
    
         
            -
              version_requirements: * 
     | 
| 
      
 24 
     | 
    
         
            +
              version_requirements: *14985100
         
     | 
| 
       25 
25 
     | 
    
         
             
            description: 
         
     | 
| 
       26 
26 
     | 
    
         
             
            email: meh@paranoici.org
         
     | 
| 
       27 
27 
     | 
    
         
             
            executables:
         
     | 
| 
         @@ -41,7 +41,6 @@ files: 
     | 
|
| 
       41 
41 
     | 
    
         
             
            - lib/herpes/module.rb
         
     | 
| 
       42 
42 
     | 
    
         
             
            - lib/herpes/rss.rb
         
     | 
| 
       43 
43 
     | 
    
         
             
            - lib/herpes/version.rb
         
     | 
| 
       44 
     | 
    
         
            -
            - lib/herpes/workers.rb
         
     | 
| 
       45 
44 
     | 
    
         
             
            homepage: http://github.com/meh/herpes
         
     | 
| 
       46 
45 
     | 
    
         
             
            licenses: []
         
     | 
| 
       47 
46 
     | 
    
         
             
            post_install_message: 
         
     | 
    
        data/lib/herpes/workers.rb
    DELETED
    
    | 
         @@ -1,26 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            #--
         
     | 
| 
       2 
     | 
    
         
            -
            #            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
         
     | 
| 
       3 
     | 
    
         
            -
            #                    Version 2, December 2004
         
     | 
| 
       4 
     | 
    
         
            -
            #
         
     | 
| 
       5 
     | 
    
         
            -
            #            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
         
     | 
| 
       6 
     | 
    
         
            -
            #   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
         
     | 
| 
       7 
     | 
    
         
            -
            #
         
     | 
| 
       8 
     | 
    
         
            -
            #  0. You just DO WHAT THE FUCK YOU WANT TO.
         
     | 
| 
       9 
     | 
    
         
            -
            #++
         
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
            require 'actionpool'
         
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
            class Workers
         
     | 
| 
       14 
     | 
    
         
            -
            	extend Forwardable
         
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
            	def_delegators :@pool, :max, :max=, :min, :min=
         
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
            	def initialize (range = 2 .. 4)
         
     | 
| 
       19 
     | 
    
         
            -
            		@pool = ActionPool::Pool.new(:min_threads => range.begin, :max_threads => range.end)
         
     | 
| 
       20 
     | 
    
         
            -
            	end
         
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
            	def do (*args, &block)
         
     | 
| 
       23 
     | 
    
         
            -
            		@pool.process(*args, &block)
         
     | 
| 
       24 
     | 
    
         
            -
            	end
         
     | 
| 
       25 
     | 
    
         
            -
            end
         
     | 
| 
       26 
     | 
    
         
            -
             
     |