axe 0.0.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/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2011 by John Thomas Marino
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
@@ -0,0 +1,33 @@
1
+ axe
2
+ ======
3
+
4
+ axe is a command line utility that makes parsing logs easy as you develop.
5
+
6
+ Install
7
+ -------
8
+
9
+ gem install axe
10
+
11
+ Commands
12
+ --------
13
+
14
+ $ axe
15
+ > tail -f log/development.log
16
+
17
+ $ axe active_record
18
+ > tail -f log/development.log | grep active_record
19
+
20
+ $ axe active_record action_view INSERT
21
+ > tail -f log/development.log | grep "active_record\|action_view\|INSERT"
22
+
23
+ $ axe -e test
24
+ > tail -f log/test.log
25
+
26
+ $ axe -e test active_record action_view INSERT
27
+ > tail -f log/test.log | grep "active_record\|action_view\|INSERT"
28
+
29
+ $ axe -n 50
30
+ > tail -n 50 log/development.log
31
+
32
+ $ axe -n 50 INSERT
33
+ > tail -n 50 log/development.log | grep INSERT
@@ -0,0 +1,11 @@
1
+ require 'bundler'
2
+ require 'rake/testtask'
3
+ Bundler::GemHelper.install_tasks
4
+
5
+ task :default => :test
6
+ Rake::TestTask.new do |t|
7
+ t.libs << 'lib'
8
+ t.ruby_opts << '-rubygems'
9
+ t.pattern = 'test/**/*_test.rb'
10
+ t.verbose = false
11
+ end
data/bin/axe ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'axe'
4
+ Axe::Swing.execute(*ARGV)
@@ -0,0 +1,52 @@
1
+ module Axe
2
+ class Swing
3
+ attr_accessor :args, :commands
4
+
5
+ def initialize(*args)
6
+ @args = args.dup
7
+ @commands = []
8
+ run(args)
9
+ end
10
+
11
+ def self.execute(*args)
12
+ new(*args).execute
13
+ end
14
+
15
+ def execute
16
+ puts command
17
+ exit($?.exitstatus || 0) unless system(command)
18
+ end
19
+
20
+ def command
21
+ commands.join(' ')
22
+ end
23
+
24
+ def run(args)
25
+ options = {:query => '', :action => '-f', :env => 'development'}
26
+ until args.empty?
27
+ case arg = args.shift
28
+ when '-n' then options[:action] = "-n #{args.shift}"
29
+ when '-e' then options[:env] = args.shift
30
+ else
31
+ options[:query] << (options[:query].empty? ? arg : '\|' + arg)
32
+ end
33
+ end
34
+ assemble_command(options)
35
+ end
36
+
37
+ def assemble_command(options = {})
38
+ commands << 'tail'
39
+ commands << options[:action]
40
+ commands << file(options[:env])
41
+ commands << grep(options[:query]) unless options[:query].empty?
42
+ end
43
+
44
+ def grep(query)
45
+ "| grep \"#{query}\""
46
+ end
47
+
48
+ def file(env)
49
+ "log/#{env}.log"
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,3 @@
1
+ module Axe
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,49 @@
1
+ $LOAD_PATH.unshift File.dirname(__FILE__)
2
+ require 'helper'
3
+
4
+ class AxeTest < Test::Unit::TestCase
5
+
6
+ def test_basic_run
7
+ assert_command '', 'tail -f log/development.log'
8
+ end
9
+
10
+ def test_query_run
11
+ assert_command 'INSERT', "tail -f log/development.log | grep \"INSERT\""
12
+ end
13
+
14
+ def test_queries_run
15
+ assert_command 'params INSERT active_record',
16
+ "tail -f log/development.log | grep \"params\\|INSERT\\|active_record\""
17
+ end
18
+
19
+ def test_environment_run
20
+ assert_command '-e test', 'tail -f log/test.log'
21
+ end
22
+
23
+ def test_environments_run
24
+ assert_command '-e test -e staging', 'tail -f log/staging.log'
25
+ end
26
+
27
+ def test_num_run
28
+ assert_command '-n 100', 'tail -n 100 log/development.log'
29
+ end
30
+
31
+ def test_nums_run
32
+ assert_command '-n 100 -n 200', 'tail -n 200 log/development.log'
33
+ end
34
+
35
+ def test_queries_environment_num_run
36
+ assert_command 'params INSERT active_record -e test -n 100',
37
+ "tail -n 100 log/test.log | grep \"params\\|INSERT\\|active_record\""
38
+ end
39
+
40
+ def test_queries_environment_run
41
+ assert_command 'params INSERT active_record -e test',
42
+ "tail -f log/test.log | grep \"params\\|INSERT\\|active_record\""
43
+ end
44
+
45
+ def test_mixed_query_with_num_and_environment
46
+ assert_command 'params -e test INSERT -n 100 active_record',
47
+ "tail -n 100 log/test.log | grep \"params\\|INSERT\\|active_record\""
48
+ end
49
+ end
@@ -0,0 +1,13 @@
1
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
2
+ require 'test/unit'
3
+ require 'axe'
4
+
5
+ class Test::Unit::TestCase
6
+ def Axe(args)
7
+ Axe::Swing.new(*args.split(' '))
8
+ end
9
+
10
+ def assert_command(input, expected)
11
+ assert_equal expected, Axe(input).command
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: axe
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - John Thomas Marino
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-04-16 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: "\n axe is a command line utility that makes parsing logs easy as you develop.\n "
23
+ email: writejm@gmail.com
24
+ executables:
25
+ - axe
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - README.md
32
+ - Rakefile
33
+ - LICENSE
34
+ - lib/axe/version.rb
35
+ - lib/axe.rb
36
+ - bin/axe
37
+ - test/axe_test.rb
38
+ - test/helper.rb
39
+ has_rdoc: true
40
+ homepage: http://github.com/johmas/axe
41
+ licenses: []
42
+
43
+ post_install_message:
44
+ rdoc_options: []
45
+
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ hash: 3
54
+ segments:
55
+ - 0
56
+ version: "0"
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ hash: 3
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ requirements: []
67
+
68
+ rubyforge_project: axe
69
+ rubygems_version: 1.3.7
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: axe makes parsing logs easy as you develop
73
+ test_files: []
74
+