maul 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/LICENSE +24 -0
  2. data/README.md +38 -0
  3. data/Rakefile +16 -0
  4. data/lib/maul.rb +52 -0
  5. metadata +49 -0
data/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ Copyright (c) 2013 Simpli.fi
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # Maul
2
+
3
+ Maul. It splits logs. Get it?
4
+
5
+ ## Install
6
+
7
+ Clone this repository, then `rake install` should work. If not, try
8
+ it step-by-step:
9
+
10
+ ``` bash
11
+ gem build maul.gemspec
12
+ gem install maul-0.1.0.gem
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ This example writes each line from stdin to a file
18
+ whose name is determined from the first token in the
19
+ line up to the first comma.
20
+
21
+ ```
22
+ class MyMauler < Maul
23
+ def to_file line
24
+ # this method should return the name of the file
25
+ # where this line should get written
26
+ # or nil for this line to be ignored
27
+
28
+ line.split(",").first + ".log"
29
+ end
30
+ end
31
+
32
+ mauler = MyMauler.new
33
+
34
+ while line = STDIN.gets
35
+ maul.on line
36
+ end
37
+ ```
38
+
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ require 'rake/clean'
2
+
3
+ desc "Run rspec spec/ (compile if needed)"
4
+ task :test => :compile do
5
+ sh "rspec spec/"
6
+ end
7
+
8
+ desc "Create gem"
9
+ task :gem => "maul.gemspec" do
10
+ sh "gem build maul.gemspec"
11
+ end
12
+
13
+ desc "Install using 'gem install'"
14
+ task :install => :gem do
15
+ sh "gem install maul"
16
+ end
data/lib/maul.rb ADDED
@@ -0,0 +1,52 @@
1
+ class Maul
2
+ module VERSION
3
+ STRING = "0.1.0"
4
+ end
5
+
6
+ def initialize args = {}
7
+ @queues = {}
8
+
9
+ @queue_size = (args[:queue_size] || 1024)
10
+ @file_mode = (args[:mode] || 'a')
11
+ end
12
+
13
+ def to_file line
14
+ raise "You need to override this method"
15
+ end
16
+
17
+ def add_line name, line
18
+ return unless name
19
+ @queues[name] ||= []
20
+ @queues[name] << line.chomp
21
+
22
+ if @queues[name].size >= @queue_size
23
+ write_queue(name)
24
+ end
25
+ end
26
+
27
+ def write_queue(name)
28
+ File.open(name, @file_mode) do |f|
29
+ f.puts @queues[name]
30
+ #clear out queue, want to kep record we saw the file
31
+ #so that we can have the ability to post process later
32
+ @queues[name] = []
33
+ end
34
+ end
35
+
36
+ def post_process(name)
37
+ end
38
+
39
+ def on line
40
+ add_line to_file(line), line
41
+ end
42
+
43
+ def flush_queues
44
+ @queues.each_key do |name|
45
+ write_queue name
46
+ post_process name
47
+ @queues.delete name
48
+ end
49
+ end
50
+
51
+ end
52
+
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: maul
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Dan Swain
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-21 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: It splits logs.
15
+ email:
16
+ - dan@simpli.fi
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/maul.rb
22
+ - LICENSE
23
+ - Rakefile
24
+ - README.md
25
+ homepage:
26
+ licenses: []
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ none: false
33
+ requirements:
34
+ - - ! '>='
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ! '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ requirements: []
44
+ rubyforge_project:
45
+ rubygems_version: 1.8.25
46
+ signing_key:
47
+ specification_version: 3
48
+ summary: It splits logs. Get it?
49
+ test_files: []