jugyo-logy 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +0 -0
- data/README.markdown +62 -0
- data/Rakefile +53 -0
- data/bin/logy +5 -0
- data/lib/logy.rb +8 -0
- data/lib/logy/client.rb +42 -0
- data/lib/logy/command.rb +29 -0
- data/lib/logy/log.rb +6 -0
- data/lib/logy/standard_commands.rb +43 -0
- data/scripts/console +11 -0
- data/spec/client_spec.rb +47 -0
- data/spec/command_spec.rb +31 -0
- data/spec/spec_helper.rb +2 -0
- metadata +83 -0
data/History.txt
ADDED
File without changes
|
data/README.markdown
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
Logy
|
2
|
+
========
|
3
|
+
|
4
|
+
[http://github.com/jugyo/logy/tree/master](http://github.com/jugyo/logy/tree/master)
|
5
|
+
|
6
|
+
Description
|
7
|
+
--------
|
8
|
+
|
9
|
+
Logy is a Terminal based ChangeLoging tool.
|
10
|
+
|
11
|
+
Install
|
12
|
+
--------
|
13
|
+
|
14
|
+
gem source -a http://gems.github.com
|
15
|
+
sudo gem install jugyo-logy
|
16
|
+
|
17
|
+
Synopsis
|
18
|
+
--------
|
19
|
+
|
20
|
+
### Start:
|
21
|
+
|
22
|
+
% logy
|
23
|
+
|
24
|
+
Logy uses '~/logy.db' as a default database.
|
25
|
+
The database is a file of sqlite3.
|
26
|
+
|
27
|
+
### To specify a database file:
|
28
|
+
|
29
|
+
% logy ~/memo.db
|
30
|
+
|
31
|
+
Requirements
|
32
|
+
--------
|
33
|
+
|
34
|
+
* sqlite3
|
35
|
+
* Sequel
|
36
|
+
* TermColor
|
37
|
+
|
38
|
+
License
|
39
|
+
--------
|
40
|
+
|
41
|
+
(The MIT License)
|
42
|
+
|
43
|
+
Copyright (c) 2008-2009 jugyo
|
44
|
+
|
45
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
46
|
+
a copy of this software and associated documentation files (the
|
47
|
+
'Software'), to deal in the Software without restriction, including
|
48
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
49
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
50
|
+
permit persons to whom the Software is furnished to do so, subject to
|
51
|
+
the following conditions:
|
52
|
+
|
53
|
+
The above copyright notice and this permission notice shall be
|
54
|
+
included in all copies or substantial portions of the Software.
|
55
|
+
|
56
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
57
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
58
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
59
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
60
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
61
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
62
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec/rake/spectask'
|
2
|
+
require 'rake/clean'
|
3
|
+
require 'rake/gempackagetask'
|
4
|
+
require 'rake/rdoctask'
|
5
|
+
|
6
|
+
name = 'logy'
|
7
|
+
version = '0.2.0'
|
8
|
+
|
9
|
+
spec = Gem::Specification.new do |s|
|
10
|
+
s.name = name
|
11
|
+
s.version = version
|
12
|
+
s.summary = "Logy is a Terminal based ChangeLoging tool."
|
13
|
+
s.description = "Logy is a Terminal based ChangeLoging tool."
|
14
|
+
s.files = %w(Rakefile README.markdown History.txt) + Dir.glob("{lib,spec,scripts}/**/*")
|
15
|
+
s.executables = ["logy"]
|
16
|
+
s.add_dependency("sequel", ">= 2.12.0")
|
17
|
+
s.add_dependency("termcolor", ">= 1.0.0")
|
18
|
+
s.author = 'jugyo'
|
19
|
+
s.email = 'jugyo.org@gmail.com'
|
20
|
+
s.homepage = 'http://github.com/jugyo/logy'
|
21
|
+
s.rubyforge_project = 'logy'
|
22
|
+
s.has_rdoc = false
|
23
|
+
end
|
24
|
+
|
25
|
+
Rake::GemPackageTask.new(spec) do |p|
|
26
|
+
p.need_tar = true
|
27
|
+
end
|
28
|
+
|
29
|
+
task :install => [ :package ] do
|
30
|
+
sh %{sudo gem install pkg/#{name}-#{version}.gem}
|
31
|
+
end
|
32
|
+
|
33
|
+
task :uninstall => [ :clean ] do
|
34
|
+
sh %{sudo gem uninstall #{name}}
|
35
|
+
end
|
36
|
+
|
37
|
+
desc 'run all specs'
|
38
|
+
Spec::Rake::SpecTask.new do |t|
|
39
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
40
|
+
t.spec_opts = ['--colour --format progress --loadby mtime --reverse']
|
41
|
+
end
|
42
|
+
|
43
|
+
Rake::RDocTask.new do |t|
|
44
|
+
t.rdoc_dir = 'rdoc'
|
45
|
+
t.title = "rest-client, fetch RESTful resources effortlessly"
|
46
|
+
t.options << '--line-numbers' << '--inline-source' << '-A cattr_accessor=object'
|
47
|
+
t.options << '--charset' << 'utf-8'
|
48
|
+
t.rdoc_files.include('README.markdown')
|
49
|
+
t.rdoc_files.include('lib/logy.rb')
|
50
|
+
t.rdoc_files.include('lib/logy/*.rb')
|
51
|
+
end
|
52
|
+
|
53
|
+
CLEAN.include [ 'pkg', '*.gem' ]
|
data/bin/logy
ADDED
data/lib/logy.rb
ADDED
data/lib/logy/client.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
module Chlgr
|
4
|
+
class Client
|
5
|
+
def self.setup(path)
|
6
|
+
@@db = Sequel.sqlite(File.expand_path(path))
|
7
|
+
unless @@db.table_exists?(:logs)
|
8
|
+
@@db.create_table :logs do
|
9
|
+
primary_key :id
|
10
|
+
Text :text
|
11
|
+
DateTime :created_at
|
12
|
+
end
|
13
|
+
end
|
14
|
+
require 'logy/log'
|
15
|
+
self
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.db
|
19
|
+
@@db
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.start
|
23
|
+
self.new.start
|
24
|
+
end
|
25
|
+
|
26
|
+
def start
|
27
|
+
Readline.basic_word_break_characters= "\t\n\"\\'`><=;|&{("
|
28
|
+
Readline.completion_proc = lambda do |text|
|
29
|
+
Command.search(text)
|
30
|
+
end
|
31
|
+
|
32
|
+
while buf = Readline.readline('> ', true)
|
33
|
+
call_command(buf)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def call_command(text)
|
38
|
+
cmd, *args = text.split(/\s/)
|
39
|
+
Command.get(cmd).call(*args)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/logy/command.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
module Chlgr
|
4
|
+
class Command
|
5
|
+
@@commands = {}
|
6
|
+
class << self
|
7
|
+
def add(name, &block)
|
8
|
+
@@commands[name.to_sym] = block
|
9
|
+
end
|
10
|
+
|
11
|
+
def get(name)
|
12
|
+
@@commands[name.to_sym]
|
13
|
+
end
|
14
|
+
|
15
|
+
def search(text)
|
16
|
+
return [] if text.nil? || text.empty?
|
17
|
+
@@commands.keys.map{|i|i.to_s}.grep(/^#{Regexp.quote(text)}/).map{|i|i.to_sym}
|
18
|
+
end
|
19
|
+
|
20
|
+
def find_all
|
21
|
+
@@commands
|
22
|
+
end
|
23
|
+
|
24
|
+
def clear
|
25
|
+
@@commands.clear
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/logy/log.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'tempfile'
|
4
|
+
|
5
|
+
module Chlgr
|
6
|
+
class Command
|
7
|
+
add :list do |*args|
|
8
|
+
output Log
|
9
|
+
end
|
10
|
+
|
11
|
+
add :add do
|
12
|
+
file = Tempfile.new('logy')
|
13
|
+
system ENV['EDITOR'] || 'vi', file.path
|
14
|
+
text = open(file.path).read
|
15
|
+
Log << {:text => text, :created_at => Time.now}
|
16
|
+
end
|
17
|
+
|
18
|
+
add :search do |*args|
|
19
|
+
query = args.first
|
20
|
+
output Log.filter(:text.like("%#{query}%")) do |text|
|
21
|
+
text = TermColor.escape(text)
|
22
|
+
TermColor.parse(text.gsub(query, '<on_yellow><black>\0</black></on_yellow>'))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
add :delete do |*args|
|
27
|
+
output Log.filter(:text.like("%#{args.first}%"))
|
28
|
+
end
|
29
|
+
|
30
|
+
add :exit do
|
31
|
+
exit
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.output(dataset, &block)
|
35
|
+
dataset.reverse_order(:created_at).limit(10).each {|log|
|
36
|
+
time = log.created_at.strftime("%Y-%m-%d %X")
|
37
|
+
header = TermColor.parse("<90>-- [##{log.id}] #{time} --</90>")
|
38
|
+
text = block ? block.call(log.text) : log.text
|
39
|
+
puts "#{header}\n#{text}"
|
40
|
+
}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/scripts/console
ADDED
data/spec/client_spec.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
4
|
+
|
5
|
+
module Chlgr
|
6
|
+
describe Client do
|
7
|
+
DB_PATH = '/tmp/logy.db'
|
8
|
+
before do
|
9
|
+
File.delete(DB_PATH) if File.exists?(DB_PATH)
|
10
|
+
end
|
11
|
+
describe 'initialize db' do
|
12
|
+
before do
|
13
|
+
@client = Client.setup(DB_PATH).new
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should create db file' do
|
17
|
+
File.exists?(DB_PATH).should == true
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'chould create logs table' do
|
21
|
+
Client.db.table_exists?(:logs).should == true
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'add commands' do
|
25
|
+
before do
|
26
|
+
Command.clear
|
27
|
+
Command.add(:foo) {|arg|}
|
28
|
+
Command.add(:bar) {|a,b|}
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should call command "foo"' do
|
32
|
+
command = Command.get('foo')
|
33
|
+
Command.should_receive(:get).with('foo').and_return(command)
|
34
|
+
command.should_receive(:call).with('test')
|
35
|
+
@client.call_command('foo test')
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should call command "bar"' do
|
39
|
+
command = Command.get('bar')
|
40
|
+
Command.should_receive(:get).with('bar').and_return(command)
|
41
|
+
command.should_receive(:call).with('a', 'b')
|
42
|
+
@client.call_command('bar a b')
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
4
|
+
|
5
|
+
module Chlgr
|
6
|
+
describe Command do
|
7
|
+
it 'adds command' do
|
8
|
+
Command.clear
|
9
|
+
Command.add(:foo){}
|
10
|
+
Command.get('foo').class.should == Proc
|
11
|
+
Command.get('bar').should be_nil
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'add 3 commands' do
|
15
|
+
before(:each) do
|
16
|
+
Command.clear
|
17
|
+
Command.add(:foo1){}
|
18
|
+
Command.add(:foo2){}
|
19
|
+
Command.add(:bar){}
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'search command' do
|
23
|
+
commands = Command.search('foo')
|
24
|
+
commands.size.should == 2
|
25
|
+
commands.include?(:foo1).should == true
|
26
|
+
commands.include?(:foo2).should == true
|
27
|
+
commands.include?(:bar).should == false
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jugyo-logy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- jugyo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-05-16 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: sequel
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 2.12.0
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: termcolor
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.0.0
|
34
|
+
version:
|
35
|
+
description: Logy is a Terminal based ChangeLoging tool.
|
36
|
+
email: jugyo.org@gmail.com
|
37
|
+
executables:
|
38
|
+
- logy
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files: []
|
42
|
+
|
43
|
+
files:
|
44
|
+
- lib/logy/client.rb
|
45
|
+
- lib/logy/command.rb
|
46
|
+
- lib/logy/log.rb
|
47
|
+
- lib/logy/standard_commands.rb
|
48
|
+
- lib/logy.rb
|
49
|
+
- spec/client_spec.rb
|
50
|
+
- spec/command_spec.rb
|
51
|
+
- spec/spec_helper.rb
|
52
|
+
- scripts/console
|
53
|
+
- README.markdown
|
54
|
+
- History.txt
|
55
|
+
- Rakefile
|
56
|
+
has_rdoc: false
|
57
|
+
homepage: http://github.com/jugyo/logy
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: "0"
|
68
|
+
version:
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: "0"
|
74
|
+
version:
|
75
|
+
requirements: []
|
76
|
+
|
77
|
+
rubyforge_project: logy
|
78
|
+
rubygems_version: 1.2.0
|
79
|
+
signing_key:
|
80
|
+
specification_version: 2
|
81
|
+
summary: Logy is a Terminal based ChangeLoging tool.
|
82
|
+
test_files: []
|
83
|
+
|