appstats 0.0.7 → 0.0.8
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/.gitignore +2 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +64 -21
- data/appstats.gemspec +4 -5
- data/lib/appstats.rb +3 -1
- data/lib/appstats/code_injections.rb +7 -0
- data/lib/appstats/entry.rb +13 -0
- data/lib/appstats/logger.rb +103 -0
- data/lib/appstats/tasks.rb +50 -35
- data/lib/appstats/version.rb +1 -1
- data/lib/templates/appstats_config.rb +3 -0
- data/spec/entry_spec.rb +44 -0
- data/spec/logger_spec.rb +200 -0
- metadata +16 -11
- data/lib/appstats/appstats_entry.rb +0 -10
- data/spec/appstats_entry_spec.rb +0 -42
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,33 +1,72 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
appstats (0.0.
|
5
|
-
rails (=
|
4
|
+
appstats (0.0.8)
|
5
|
+
rails (= 3.0.3)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: http://rubygems.org/
|
9
9
|
specs:
|
10
10
|
ZenTest (4.4.2)
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
activesupport (=
|
18
|
-
|
19
|
-
|
20
|
-
|
11
|
+
abstract (1.0.0)
|
12
|
+
actionmailer (3.0.3)
|
13
|
+
actionpack (= 3.0.3)
|
14
|
+
mail (~> 2.2.9)
|
15
|
+
actionpack (3.0.3)
|
16
|
+
activemodel (= 3.0.3)
|
17
|
+
activesupport (= 3.0.3)
|
18
|
+
builder (~> 2.1.2)
|
19
|
+
erubis (~> 2.6.6)
|
20
|
+
i18n (~> 0.4)
|
21
|
+
rack (~> 1.2.1)
|
22
|
+
rack-mount (~> 0.6.13)
|
23
|
+
rack-test (~> 0.5.6)
|
24
|
+
tzinfo (~> 0.3.23)
|
25
|
+
activemodel (3.0.3)
|
26
|
+
activesupport (= 3.0.3)
|
27
|
+
builder (~> 2.1.2)
|
28
|
+
i18n (~> 0.4)
|
29
|
+
activerecord (3.0.3)
|
30
|
+
activemodel (= 3.0.3)
|
31
|
+
activesupport (= 3.0.3)
|
32
|
+
arel (~> 2.0.2)
|
33
|
+
tzinfo (~> 0.3.23)
|
34
|
+
activeresource (3.0.3)
|
35
|
+
activemodel (= 3.0.3)
|
36
|
+
activesupport (= 3.0.3)
|
37
|
+
activesupport (3.0.3)
|
38
|
+
arel (2.0.7)
|
39
|
+
builder (2.1.2)
|
21
40
|
diff-lcs (1.1.2)
|
41
|
+
erubis (2.6.6)
|
42
|
+
abstract (>= 1.0.0)
|
43
|
+
i18n (0.5.0)
|
44
|
+
mail (2.2.14)
|
45
|
+
activesupport (>= 2.3.6)
|
46
|
+
i18n (>= 0.4.0)
|
47
|
+
mime-types (~> 1.16)
|
48
|
+
treetop (~> 1.4.8)
|
49
|
+
mime-types (1.16)
|
22
50
|
mysql (2.8.1)
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
51
|
+
polyglot (0.3.1)
|
52
|
+
rack (1.2.1)
|
53
|
+
rack-mount (0.6.13)
|
54
|
+
rack (>= 1.0.0)
|
55
|
+
rack-test (0.5.7)
|
56
|
+
rack (>= 1.0)
|
57
|
+
rails (3.0.3)
|
58
|
+
actionmailer (= 3.0.3)
|
59
|
+
actionpack (= 3.0.3)
|
60
|
+
activerecord (= 3.0.3)
|
61
|
+
activeresource (= 3.0.3)
|
62
|
+
activesupport (= 3.0.3)
|
63
|
+
bundler (~> 1.0)
|
64
|
+
railties (= 3.0.3)
|
65
|
+
railties (3.0.3)
|
66
|
+
actionpack (= 3.0.3)
|
67
|
+
activesupport (= 3.0.3)
|
68
|
+
rake (>= 0.8.7)
|
69
|
+
thor (~> 0.14.4)
|
31
70
|
rake (0.8.7)
|
32
71
|
rspec (2.4.0)
|
33
72
|
rspec-core (~> 2.4.0)
|
@@ -40,6 +79,10 @@ GEM
|
|
40
79
|
standalone_migrations (0.3.0)
|
41
80
|
activerecord
|
42
81
|
rake
|
82
|
+
thor (0.14.6)
|
83
|
+
treetop (1.4.9)
|
84
|
+
polyglot (>= 0.3.1)
|
85
|
+
tzinfo (0.3.24)
|
43
86
|
|
44
87
|
PLATFORMS
|
45
88
|
ruby
|
@@ -48,6 +91,6 @@ DEPENDENCIES
|
|
48
91
|
ZenTest
|
49
92
|
appstats!
|
50
93
|
mysql
|
51
|
-
rails (=
|
94
|
+
rails (= 3.0.3)
|
52
95
|
rspec
|
53
96
|
standalone_migrations
|
data/appstats.gemspec
CHANGED
@@ -12,17 +12,16 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.summary = %q{Provide usage statistics about how your application is being used}
|
13
13
|
s.description = %q{Provide usage statistics about how your application is being used}
|
14
14
|
|
15
|
-
|
15
|
+
# Models are to be used in Rails 3 environment, but the logger can work with Rails 2 apps
|
16
|
+
# But, for testing appstats itself, you will need Rails 3
|
17
|
+
s.add_dependency('rails','>=2.3.0')
|
18
|
+
# s.add_dependency('rails','3.0.3')
|
16
19
|
|
17
20
|
s.add_development_dependency('rspec')
|
18
21
|
s.add_development_dependency('ZenTest')
|
19
22
|
s.add_development_dependency('standalone_migrations')
|
20
23
|
s.add_development_dependency('mysql')
|
21
24
|
|
22
|
-
# only on a mac machine
|
23
|
-
# s.add_development_dependency('autotest-fsevent')
|
24
|
-
|
25
|
-
|
26
25
|
s.files = `git ls-files`.split("\n")
|
27
26
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
28
27
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
data/lib/appstats.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'active_record'
|
3
|
-
require "#{File.dirname(__FILE__)}/appstats/
|
3
|
+
require "#{File.dirname(__FILE__)}/appstats/entry"
|
4
4
|
require "#{File.dirname(__FILE__)}/appstats/tasks"
|
5
|
+
require "#{File.dirname(__FILE__)}/appstats/logger"
|
6
|
+
require "#{File.dirname(__FILE__)}/appstats/code_injections"
|
5
7
|
|
6
8
|
module Appstats
|
7
9
|
# Your code goes here...
|
@@ -0,0 +1,103 @@
|
|
1
|
+
|
2
|
+
module Appstats
|
3
|
+
class Logger
|
4
|
+
|
5
|
+
def self.reset
|
6
|
+
@@filename_template = nil
|
7
|
+
@@default_contexts = nil
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.default_contexts
|
11
|
+
@@default_contexts ||= {}
|
12
|
+
@@default_contexts
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.filename_template=(value)
|
16
|
+
@@filename_template = value
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.filename_template
|
20
|
+
@@filename_template ||= 'appstats'
|
21
|
+
@@filename_template
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.filename
|
25
|
+
"#{filename_template}_#{today}.log"
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.raw_write(text)
|
29
|
+
File.open(filename, "a") { |f| f.write("#{text}\n") }
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.raw_read
|
33
|
+
return [] unless File.exists?(filename)
|
34
|
+
File.open(filename,"r").readlines.collect { |line| line.strip }
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.entry_to_s(action,contexts = {})
|
38
|
+
contexts = contexts.merge(default_contexts)
|
39
|
+
section_delimiter, assign_delimiter, newline_delimiter = determine_delimiters(contexts.merge(:action => action))
|
40
|
+
answer = "#{Appstats::VERSION} setup[#{section_delimiter},#{assign_delimiter},#{newline_delimiter}] "
|
41
|
+
answer += "#{now} action#{assign_delimiter}#{action}"
|
42
|
+
contexts.keys.sort.each do |key|
|
43
|
+
answer += " #{section_delimiter} #{key}#{assign_delimiter}#{contexts[key]}"
|
44
|
+
end
|
45
|
+
answer
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.entry_to_hash(action_and_contexts)
|
49
|
+
hash = { :action => "UNKNOWN_ACTION", :raw_input => action_and_contexts }
|
50
|
+
return hash if action_and_contexts.nil?
|
51
|
+
setup = action_and_contexts.match(/(.*?) setup\[(.*?),(.*?),(.*?)\] (.*? .*?) (.*)/)
|
52
|
+
return hash if setup.nil?
|
53
|
+
hash.delete(:raw_input)
|
54
|
+
full, version, section_delimiter, assign_delimiter, newline_delimiter, timestamp, input = setup.to_a
|
55
|
+
|
56
|
+
hash[:timestamp] = timestamp
|
57
|
+
input.split(section_delimiter).each do |pair|
|
58
|
+
key,value = pair.strip.split(assign_delimiter)
|
59
|
+
hash[key.to_sym] = value
|
60
|
+
end
|
61
|
+
hash
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.entry(action,contexts = {})
|
65
|
+
raw_write(entry_to_s(action,contexts))
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.today
|
69
|
+
"#{Time.now.strftime('%Y-%m-%d')}"
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.now
|
73
|
+
"#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}"
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
def self.determine_delimiters(lookups)
|
79
|
+
section_delimiter = ":"
|
80
|
+
assign_delimiter = "="
|
81
|
+
newline_delimiter = "-n"
|
82
|
+
|
83
|
+
lookups.each do |pair|
|
84
|
+
name = pair[1]
|
85
|
+
while(name.include?(section_delimiter))
|
86
|
+
section_delimiter += ":"
|
87
|
+
end
|
88
|
+
while(name.include?(assign_delimiter))
|
89
|
+
assign_delimiter += "="
|
90
|
+
end
|
91
|
+
while(name.include?(newline_delimiter))
|
92
|
+
newline_delimiter = "-#{newline_delimiter}"
|
93
|
+
end
|
94
|
+
end
|
95
|
+
[section_delimiter,assign_delimiter,newline_delimiter]
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
|
data/lib/appstats/tasks.rb
CHANGED
@@ -2,46 +2,61 @@ require 'rake'
|
|
2
2
|
require 'rake/tasklib'
|
3
3
|
require 'logger'
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
module Appstats
|
6
|
+
def self.table_name() "mice" end
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
8
|
+
class Tasks < ::Rake::TaskLib
|
9
|
+
attr_accessor :name, :base, :vendor, :config, :schema, :env, :default_env, :verbose, :log_level
|
10
|
+
|
11
|
+
def initialize(name = :appstats)
|
12
|
+
@name = name
|
13
|
+
base = File.expand_path('.')
|
14
|
+
here = File.expand_path(File.dirname(File.dirname(File.dirname((__FILE__)))))
|
15
|
+
@base = base
|
16
|
+
@vendor = "#{here}/vendor"
|
17
|
+
@gem_migrations = "#{here}/db/migrations"
|
18
|
+
@app_migrate = "#{base}/db/migrate"
|
19
|
+
@config = "#{base}/db/config.yml"
|
20
|
+
@schema = "#{base}/db/schema.rb"
|
21
|
+
@appstats_initializer = "#{base}/config/initializers/appstats.rb"
|
22
|
+
@appstats_initializer_template = "#{here}/lib/templates/appstats_config.rb"
|
23
|
+
@env = 'DB'
|
24
|
+
@default_env = 'development'
|
25
|
+
@verbose = true
|
26
|
+
@log_level = Logger::ERROR
|
27
|
+
yield self if block_given?
|
28
|
+
# Add to load_path every "lib/" directory in vendor
|
29
|
+
Dir["#{vendor}/**/lib"].each{|p| $LOAD_PATH << p }
|
30
|
+
define
|
31
|
+
end
|
27
32
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
33
|
+
def define
|
34
|
+
namespace :appstats do
|
35
|
+
namespace :install do
|
36
|
+
desc "Install the migrations for this gem (for the database aspect of the gem)"
|
37
|
+
task :migrations do
|
38
|
+
unless File.exists?(@app_migrate)
|
39
|
+
puts "Creating migrate directory"
|
40
|
+
mkdir @app_migrate
|
41
|
+
end
|
42
|
+
puts "Moving migrations files from:\n> #{@gem_migrations}\nTo\n> #{@app_migrate}"
|
43
|
+
system "cp -R #{@gem_migrations}/* #{@app_migrate}"
|
44
|
+
end
|
45
|
+
|
46
|
+
desc "Install the logger for this gem (for application instances that log statistics)"
|
47
|
+
task :logger do
|
48
|
+
if File.exists?(@appstats_initializer)
|
49
|
+
puts "Initialize [#{@appstats_initializer}] already exists, creating example file [#{@appstats_initializer}.example] to see any new changes since you last installed this gem"
|
50
|
+
system "cp -R #{@appstats_initializer_template} #{@appstats_initializer}.example"
|
51
|
+
else
|
52
|
+
puts "Creating default initializer [#{@appstats_initializer}]"
|
53
|
+
system "cp -R #{@appstats_initializer_template} #{@appstats_initializer}"
|
54
|
+
end
|
55
|
+
end
|
37
56
|
end
|
38
|
-
puts "Moving migrations files from:\n> #{@gem_migrations}\nTo\n> #{@app_migrate}"
|
39
|
-
system "cp -R #{@gem_migrations}/* #{@app_migrate}"
|
40
57
|
end
|
41
|
-
|
42
58
|
end
|
43
59
|
end
|
44
|
-
|
45
60
|
end
|
46
61
|
|
47
|
-
|
62
|
+
Appstats::Tasks.new
|
data/lib/appstats/version.rb
CHANGED
data/spec/entry_spec.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Appstats
|
4
|
+
describe Entry do
|
5
|
+
|
6
|
+
describe "#initialize" do
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
@entry = Appstats::Entry.new
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should set entry_type to nil" do
|
13
|
+
@entry.entry_type.should == nil
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should set name to nil" do
|
17
|
+
@entry.name.should == nil
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should set description to nil" do
|
21
|
+
@entry.description.should == nil
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should set on constructor" do
|
25
|
+
entry = Appstats::Entry.new(:entry_type => 'a', :name => 'b', :description => 'c')
|
26
|
+
entry.entry_type.should == 'a'
|
27
|
+
entry.name.should == 'b'
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#to_s" do
|
34
|
+
|
35
|
+
before(:each) do
|
36
|
+
@entry = Appstats::Entry.new
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should run the test" do
|
40
|
+
@entry.to_s.should == 'Entry [type],[name],[description]'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/spec/logger_spec.rb
ADDED
@@ -0,0 +1,200 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Appstats
|
4
|
+
describe Logger do
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
Appstats::Logger.reset
|
8
|
+
Time.stub!(:now).and_return(Time.parse('2010-09-21 23:15:20'))
|
9
|
+
end
|
10
|
+
|
11
|
+
after(:each) do
|
12
|
+
File.delete(Appstats::Logger.filename) if File.exists?(Appstats::Logger.filename)
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "#initialize" do
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#reset" do
|
20
|
+
|
21
|
+
it "should unset filename_template" do
|
22
|
+
Appstats::Logger.filename_template = "blah"
|
23
|
+
Appstats::Logger.reset
|
24
|
+
Appstats::Logger.filename_template.should == "appstats"
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should unset default contexts" do
|
28
|
+
Appstats::Logger.default_contexts[:blah] = "x"
|
29
|
+
Appstats::Logger.reset
|
30
|
+
Appstats::Logger.default_contexts.empty?.should be_true
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "#filename" do
|
36
|
+
|
37
|
+
it "should be based on daily timestamp" do
|
38
|
+
Appstats::Logger.filename.should == 'appstats_2010-09-21.log'
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should support full paths" do
|
42
|
+
Appstats::Logger.filename_template = "/a/b/appstats"
|
43
|
+
Appstats::Logger.filename.should == '/a/b/appstats_2010-09-21.log'
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "#filename_template" do
|
49
|
+
|
50
|
+
it "should default to appstats" do
|
51
|
+
Appstats::Logger.filename_template.should == "appstats"
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should be settable" do
|
55
|
+
Appstats::Logger.filename_template = "blah"
|
56
|
+
Appstats::Logger.filename_template.should == "blah"
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "#raw_read" do
|
62
|
+
|
63
|
+
it "should return empty if file does not exist" do
|
64
|
+
File.exists?(Appstats::Logger.filename).should == false
|
65
|
+
Appstats::Logger.raw_read.should == []
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should read all data" do
|
69
|
+
Appstats::Logger.raw_write("abc")
|
70
|
+
Appstats::Logger.raw_write("def")
|
71
|
+
Appstats::Logger.raw_read.should == ["abc","def"]
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "#raw_write" do
|
77
|
+
|
78
|
+
it "should create the file if it doesn't exist" do
|
79
|
+
File.exists?("appstats_2010-09-21.log").should == false
|
80
|
+
Appstats::Logger.raw_write("abc")
|
81
|
+
File.exists?("appstats_2010-09-21.log").should == true
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should save text as is" do
|
85
|
+
Appstats::Logger.raw_write("abc")
|
86
|
+
Appstats::Logger.raw_write("def")
|
87
|
+
Appstats::Logger.raw_read.should == ["abc","def"]
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "#now" do
|
93
|
+
|
94
|
+
it "should return a formatted date" do
|
95
|
+
Appstats::Logger.now.should == "2010-09-21 23:15:20"
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
describe "#today" do
|
101
|
+
|
102
|
+
it "should return a formatted date" do
|
103
|
+
Appstats::Logger.today.should == "2010-09-21"
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
describe "#entry" do
|
109
|
+
|
110
|
+
it "should outlien the to_s" do
|
111
|
+
Appstats::Logger.stub!(:entry_to_s).with("address_search",{}).and_return("entry_to_s called")
|
112
|
+
Appstats::Logger.entry("address_search")
|
113
|
+
Appstats::Logger.raw_read.should == ["entry_to_s called"]
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
describe "#entry_to_hash" do
|
119
|
+
|
120
|
+
it "should handle nil" do
|
121
|
+
Appstats::Logger.entry_to_hash(nil).should == { :action => "UNKNOWN_ACTION", :raw_input => nil }
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should fail softly with invalid data" do
|
125
|
+
Appstats::Logger.entry_to_hash("blah").should == { :action => "UNKNOWN_ACTION", :raw_input => "blah" }
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should handle a statistics entry" do
|
129
|
+
expected = { :action => "address_search", :timestamp => "2010-09-21 23:15:20" }
|
130
|
+
actual = Appstats::Logger.entry_to_hash("0.0.8 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search")
|
131
|
+
actual.should == expected
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should handle contexts" do
|
135
|
+
expected = { :action => "address_filter", :timestamp => "2010-09-21 23:15:20", :server => "Live", :app_name => 'Market' }
|
136
|
+
actual = Appstats::Logger.entry_to_hash("0.0.8 setup[:,=,-n] 2010-09-21 23:15:20 action=address_filter : app_name=Market : server=Live")
|
137
|
+
actual.should == expected
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should handle actions with the delimiter (and change the delimiter)" do
|
141
|
+
expected = { :action => "address:=search-n", :timestamp => "2010-09-21 23:15:20" }
|
142
|
+
actual = Appstats::Logger.entry_to_hash("0.0.8 setup[::,==,--n] 2010-09-21 23:15:20 action==address:=search-n")
|
143
|
+
actual.should == expected
|
144
|
+
|
145
|
+
expected = { :action => "address::search==--n", :timestamp => "2010-09-21 23:15:20" }
|
146
|
+
actual = Appstats::Logger.entry_to_hash("0.0.8 setup[:::,===,---n] 2010-09-21 23:15:20 action===address::search==--n")
|
147
|
+
actual.should == expected
|
148
|
+
end
|
149
|
+
|
150
|
+
it "should handle contexts with the delimiter (and change the delimiter)" do
|
151
|
+
expected = { :action => "address", :timestamp => "2010-09-21 23:15:20", :server => "market:eval=-n" }
|
152
|
+
actual = Appstats::Logger.entry_to_hash("0.0.8 setup[::,==,--n] 2010-09-21 23:15:20 action==address :: server==market:eval=-n")
|
153
|
+
actual.should == expected
|
154
|
+
end
|
155
|
+
|
156
|
+
|
157
|
+
end
|
158
|
+
|
159
|
+
describe "#entry_to_s" do
|
160
|
+
|
161
|
+
it "should handle a statistics entry" do
|
162
|
+
expected = "0.0.8 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search"
|
163
|
+
actual = Appstats::Logger.entry_to_s("address_search")
|
164
|
+
actual.should == expected
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should handle default contexts" do
|
168
|
+
Appstats::Logger.default_contexts[:app_name] = "market"
|
169
|
+
expected = "0.0.8 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search : app_name=market"
|
170
|
+
actual = Appstats::Logger.entry_to_s("address_search")
|
171
|
+
actual.should == expected
|
172
|
+
end
|
173
|
+
|
174
|
+
it "should handle contexts (and sort them by symbol)" do
|
175
|
+
expected = "0.0.8 setup[:,=,-n] 2010-09-21 23:15:20 action=address_filter : app_name=Market : server=Live"
|
176
|
+
actual = Appstats::Logger.entry_to_s("address_filter", { :server => "Live", :app_name => 'Market' })
|
177
|
+
actual.should == expected
|
178
|
+
end
|
179
|
+
|
180
|
+
it "should handle actions with the delimiter (and change the delimiter)" do
|
181
|
+
expected = "0.0.8 setup[::,==,--n] 2010-09-21 23:15:20 action==address:=search-n"
|
182
|
+
actual = Appstats::Logger.entry_to_s("address:=search-n")
|
183
|
+
actual.should == expected
|
184
|
+
|
185
|
+
expected = "0.0.8 setup[:::,===,---n] 2010-09-21 23:15:20 action===address::search==--n"
|
186
|
+
actual = Appstats::Logger.entry_to_s("address::search==--n")
|
187
|
+
actual.should == expected
|
188
|
+
end
|
189
|
+
|
190
|
+
it "should handle contexts with the delimiter (and change the delimiter)" do
|
191
|
+
expected = "0.0.8 setup[::,==,--n] 2010-09-21 23:15:20 action==address :: server==market:eval=-n"
|
192
|
+
actual = Appstats::Logger.entry_to_s("address", :server => 'market:eval=-n')
|
193
|
+
actual.should == expected
|
194
|
+
end
|
195
|
+
|
196
|
+
end
|
197
|
+
|
198
|
+
|
199
|
+
end
|
200
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: appstats
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 8
|
10
|
+
version: 0.0.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Andrew Forward
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-01-
|
18
|
+
date: 2011-01-20 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -24,14 +24,14 @@ dependencies:
|
|
24
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
|
-
- - "
|
27
|
+
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
29
|
+
hash: 3
|
30
30
|
segments:
|
31
31
|
- 2
|
32
32
|
- 3
|
33
|
-
-
|
34
|
-
version: 2.3.
|
33
|
+
- 0
|
34
|
+
version: 2.3.0
|
35
35
|
type: :runtime
|
36
36
|
version_requirements: *id001
|
37
37
|
- !ruby/object:Gem::Dependency
|
@@ -113,9 +113,12 @@ files:
|
|
113
113
|
- db/migrations/20110105221941_create_appstats_entries.rb
|
114
114
|
- db/schema.rb
|
115
115
|
- lib/appstats.rb
|
116
|
-
- lib/appstats/
|
116
|
+
- lib/appstats/code_injections.rb
|
117
|
+
- lib/appstats/entry.rb
|
118
|
+
- lib/appstats/logger.rb
|
117
119
|
- lib/appstats/tasks.rb
|
118
120
|
- lib/appstats/version.rb
|
121
|
+
- lib/templates/appstats_config.rb
|
119
122
|
- pkg/appstats-0.0.1.gem
|
120
123
|
- pkg/appstats-0.0.1.tgz
|
121
124
|
- pkg/appstats-0.0.1/History.txt
|
@@ -132,8 +135,9 @@ files:
|
|
132
135
|
- script/console
|
133
136
|
- script/destroy
|
134
137
|
- script/generate
|
135
|
-
- spec/appstats_entry_spec.rb
|
136
138
|
- spec/appstats_spec.rb
|
139
|
+
- spec/entry_spec.rb
|
140
|
+
- spec/logger_spec.rb
|
137
141
|
- spec/spec_helper.rb
|
138
142
|
has_rdoc: true
|
139
143
|
homepage: http://github.com/aforward/appstats
|
@@ -170,6 +174,7 @@ signing_key:
|
|
170
174
|
specification_version: 3
|
171
175
|
summary: Provide usage statistics about how your application is being used
|
172
176
|
test_files:
|
173
|
-
- spec/appstats_entry_spec.rb
|
174
177
|
- spec/appstats_spec.rb
|
178
|
+
- spec/entry_spec.rb
|
179
|
+
- spec/logger_spec.rb
|
175
180
|
- spec/spec_helper.rb
|
data/spec/appstats_entry_spec.rb
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe AppstatsEntry do
|
4
|
-
|
5
|
-
describe "#initialize" do
|
6
|
-
|
7
|
-
before(:each) do
|
8
|
-
@entry = AppstatsEntry.new
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should set entry_type to nil" do
|
12
|
-
@entry.entry_type.should == nil
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should set name to nil" do
|
16
|
-
@entry.name.should == nil
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should set description to nil" do
|
20
|
-
@entry.description.should == nil
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should set on constructor" do
|
24
|
-
entry = AppstatsEntry.new(:entry_type => 'a', :name => 'b', :description => 'c')
|
25
|
-
entry.entry_type.should == 'a'
|
26
|
-
entry.name.should == 'b'
|
27
|
-
entry.description.should == 'c'
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
describe "#to_s" do
|
33
|
-
|
34
|
-
before(:each) do
|
35
|
-
@entry = AppstatsEntry.new
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should run the test" do
|
39
|
-
@entry.to_s.should == 'Entry [type],[name],[description]'
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|