logworm 0.7.6 → 0.7.7
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/CHANGELOG +3 -0
- data/Rakefile +1 -1
- data/lib/base/config.rb +7 -4
- data/lib/base/db.rb +15 -8
- data/logworm.gemspec +2 -2
- data/spec/base_spec.rb +50 -3
- metadata +3 -3
data/CHANGELOG
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
v0.7.7
|
2
|
+
DB.config now receives an optional app parameter, for the cases where you want to call command-line tools from a directory other than the app's directory... or when you have more than one Heroku remote/app from the same directory
|
3
|
+
|
1
4
|
v0.7.6
|
2
5
|
QueryBuilder now allows Time objects as arguments for timeframe
|
3
6
|
|
data/Rakefile
CHANGED
data/lib/base/config.rb
CHANGED
@@ -10,12 +10,15 @@ module Logworm
|
|
10
10
|
FILENAME = ".logworm"
|
11
11
|
|
12
12
|
def initialize
|
13
|
-
|
13
|
+
reset
|
14
14
|
end
|
15
|
-
|
16
|
-
def
|
15
|
+
|
16
|
+
def reset
|
17
17
|
@file_found = false
|
18
18
|
@url = nil
|
19
|
+
end
|
20
|
+
|
21
|
+
def read
|
19
22
|
begin
|
20
23
|
f = File.new("./" + FILENAME, 'r')
|
21
24
|
@url = f.readline.strip
|
@@ -30,7 +33,7 @@ module Logworm
|
|
30
33
|
end
|
31
34
|
|
32
35
|
def file_found?
|
33
|
-
@file_found and @url
|
36
|
+
@file_found and (!@url.nil? and @url != "")
|
34
37
|
end
|
35
38
|
|
36
39
|
def save(url)
|
data/lib/base/db.rb
CHANGED
@@ -27,24 +27,31 @@ module Logworm
|
|
27
27
|
DB.new(DB.make_url(host, consumer_key, consumer_secret, token, token_secret))
|
28
28
|
end
|
29
29
|
|
30
|
-
def self.from_config
|
31
|
-
# Try with URL from the environment
|
30
|
+
def self.from_config(app = nil)
|
31
|
+
# Try with URL from the environment. This will certainly be the case when running on Heroku, in production.
|
32
32
|
return DB.new(ENV['LOGWORM_URL']) if ENV['LOGWORM_URL'] and DB.parse_url(ENV['LOGWORM_URL'])
|
33
33
|
|
34
|
-
#
|
34
|
+
# If no env. found, try with configuration file, unless app specified
|
35
35
|
config = Logworm::Config.instance
|
36
|
-
|
36
|
+
config.read
|
37
|
+
unless app
|
38
|
+
return DB.new(config.url) if config.file_found? and DB.parse_url(config.url)
|
39
|
+
end
|
37
40
|
|
38
41
|
# Try with Heroku configuration otherwise
|
39
|
-
|
42
|
+
cmd = "heroku config --long #{app ? " --app #{app}" : ""}"
|
43
|
+
config_vars = %x[#{cmd}] || ""
|
40
44
|
m = config_vars.match(Regexp.new("LOGWORM_URL\\s+=>\\s+([^\\n]+)"))
|
41
|
-
|
45
|
+
if m and DB.parse_url(m[1])
|
46
|
+
config.save(m[1]) unless (config.file_found? and app) # Do not overwrite if --app is provided
|
47
|
+
return DB.new(m[1])
|
48
|
+
end
|
42
49
|
|
43
50
|
nil
|
44
51
|
end
|
45
52
|
|
46
|
-
def self.from_config_or_die
|
47
|
-
db = self.from_config
|
53
|
+
def self.from_config_or_die(app = nil)
|
54
|
+
db = self.from_config(app)
|
48
55
|
raise "The application is not properly configured. Either use 'heroku addon:add' to add logworm to your app, or save your project's credentials into the .logworm file" unless db
|
49
56
|
db
|
50
57
|
end
|
data/logworm.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{logworm}
|
5
|
-
s.version = "0.7.
|
5
|
+
s.version = "0.7.7"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Pomelo, LLC"]
|
9
|
-
s.date = %q{2010-
|
9
|
+
s.date = %q{2010-06-24}
|
10
10
|
s.description = %q{logworm logging tool}
|
11
11
|
s.email = %q{schapira@pomelollc.com}
|
12
12
|
s.extra_rdoc_files = ["CHANGELOG", "README", "lib/base/config.rb", "lib/base/db.rb", "lib/base/query_builder.rb", "lib/logworm.rb"]
|
data/spec/base_spec.rb
CHANGED
@@ -7,6 +7,11 @@ $: << File.dirname(__FILE__) + '/../lib'
|
|
7
7
|
require 'logworm.rb'
|
8
8
|
|
9
9
|
describe Logworm::DB, " initialization" do
|
10
|
+
before do
|
11
|
+
File.delete(".logworm") if File.exist?(".logworm")
|
12
|
+
Logworm::Config.instance.reset
|
13
|
+
end
|
14
|
+
|
10
15
|
it "should only accept proper URLs" do
|
11
16
|
lambda {Logworm::DB.new('')}.should raise_exception(Logworm::ForbiddenAccessException)
|
12
17
|
lambda {Logworm::DB.new('http://www.test.com')}.should raise_exception(Logworm::ForbiddenAccessException)
|
@@ -26,8 +31,50 @@ describe Logworm::DB, " initialization" do
|
|
26
31
|
db.token_secret.should == "d"
|
27
32
|
end
|
28
33
|
|
29
|
-
it "should be able to read its configuration from a file"
|
30
|
-
|
34
|
+
it "should be able to read its configuration from a file" do
|
35
|
+
File.open(".logworm", "w") do |f|
|
36
|
+
f.puts 'logworm://a:b@localhost:9401/c/d/'
|
37
|
+
end
|
38
|
+
db = Logworm::DB.from_config
|
39
|
+
db.host.should == "localhost:9401"
|
40
|
+
db.consumer_key.should == "a"
|
41
|
+
db.consumer_secret.should == "b"
|
42
|
+
db.token.should == "c"
|
43
|
+
db.token_secret.should == "d"
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should fail if no logworm file (and no current Heroku application)" do
|
47
|
+
db = Logworm::DB.from_config
|
48
|
+
db.should == nil
|
49
|
+
end
|
50
|
+
|
51
|
+
# Note that this will fail unless it's run from the command line!
|
52
|
+
it "should not be nil if we pass a proper app parameter" do
|
53
|
+
db = Logworm::DB.from_config("lw-client")
|
54
|
+
db.should_not == nil
|
55
|
+
db.host.should == "db.logworm.com"
|
56
|
+
end
|
57
|
+
|
58
|
+
# Note that this will fail unless it's run from the command line!
|
59
|
+
it "should not use a config file if app is passed" do
|
60
|
+
File.open(".logworm", "w") do |f|
|
61
|
+
f.puts 'logworm://a:b@xxx:9401/c/d/'
|
62
|
+
end
|
63
|
+
db = Logworm::DB.from_config("lw-client")
|
64
|
+
db.host.should == "db.logworm.com" # The one from the app, not the config file
|
65
|
+
end
|
66
|
+
|
67
|
+
# Note that this will fail unless it's run from the command line!
|
68
|
+
it "should not overwrite a config file if app is passed" do
|
69
|
+
File.open(".logworm", "w") do |f|
|
70
|
+
f.puts 'logworm://a:b@xxx:9401/c/d/'
|
71
|
+
end
|
72
|
+
|
73
|
+
db = Logworm::DB.from_config("lw-client")
|
74
|
+
Logworm::Config.instance.reset
|
75
|
+
Logworm::Config.instance.read
|
76
|
+
Logworm::Config.instance.url.should == 'logworm://a:b@xxx:9401/c/d/'
|
77
|
+
end
|
31
78
|
|
32
79
|
end
|
33
80
|
|
@@ -59,7 +106,7 @@ describe Logworm::DB, " functioning" do
|
|
59
106
|
|
60
107
|
it "should just parse and return the results of the call to query" do
|
61
108
|
return_body = {"id" => 10, "query" => "q", "self_uri" => "/queries/10", "results_uri" => "/queries/10/results"}
|
62
|
-
stub_request(:post, "#{host}/queries").with(:body => "table=table1
|
109
|
+
stub_request(:post, "#{host}/queries").with(:body => "query=q&table=table1").to_return(:body => return_body.to_json)
|
63
110
|
@db.query("table1", "q").should == return_body
|
64
111
|
end
|
65
112
|
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 7
|
8
|
-
-
|
9
|
-
version: 0.7.
|
8
|
+
- 7
|
9
|
+
version: 0.7.7
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Pomelo, LLC
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-06-24 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|