simple_record 1.4.0 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/simple_record.rb +70 -45
- data/lib/simple_record/active_sdb.rb +985 -0
- data/lib/simple_record/logging.rb +42 -0
- data/lib/simple_record/translations.rb +1 -1
- data/test/test_encodings.rb +26 -1
- data/test/test_usage.rb +40 -0
- metadata +8 -4
@@ -0,0 +1,42 @@
|
|
1
|
+
module SimpleRecord
|
2
|
+
|
3
|
+
require 'csv'
|
4
|
+
|
5
|
+
module Logging
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def write_usage(type, domain, q_type, params, results)
|
9
|
+
puts 'params=' + params.inspect
|
10
|
+
if SimpleRecord.usage_logging_options
|
11
|
+
type_options = SimpleRecord.usage_logging_options[type]
|
12
|
+
if type_options
|
13
|
+
file = type_options[:file]
|
14
|
+
if file.nil?
|
15
|
+
file = File.open(type_options[:filename], File.exists?(type_options[:filename]) ? "a" : "w")
|
16
|
+
puts file.path
|
17
|
+
type_options[:file] = file
|
18
|
+
end
|
19
|
+
conditions = params[:conditions][0] if params[:conditions]
|
20
|
+
line = usage_line(type_options[:format], [type, domain, q_type, conditions, params[:order]], results[:request_id], results[:box_usage])
|
21
|
+
file.puts line
|
22
|
+
puts 'line=' + line
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def usage_line(format, query_data, request_id, box_usage)
|
28
|
+
if format == :csv
|
29
|
+
line_data = []
|
30
|
+
line_data << Time.now.iso8601
|
31
|
+
query_data.each do |r|
|
32
|
+
line_data << r.to_s
|
33
|
+
end
|
34
|
+
line_data << request_id
|
35
|
+
line_data << box_usage
|
36
|
+
return CSV.generate_line(line_data)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
@@ -84,7 +84,7 @@ module SimpleRecord
|
|
84
84
|
# puts 'to eval=' + to_eval
|
85
85
|
begin
|
86
86
|
ret = eval(to_eval) # (defined? #{arg}_id)
|
87
|
-
rescue
|
87
|
+
rescue SimpleRecord::ActiveSdb::ActiveSdbError => ex
|
88
88
|
if ex.message.include? "Couldn't find"
|
89
89
|
ret = RemoteNil.new
|
90
90
|
else
|
data/test/test_encodings.rb
CHANGED
@@ -14,5 +14,30 @@ class Person < SimpleRecord::Base
|
|
14
14
|
end
|
15
15
|
class TestEncodings < TestBase
|
16
16
|
|
17
|
-
|
17
|
+
def test_ascii_http_post
|
18
|
+
first_name = "joe" + ("X" * 1000) # pad the field to help get the URL over the 2000 length limit so AWS uses a POST
|
19
|
+
last_name = "blow" + ("X" * 1000) # pad the field to help get the URL over the 2000 length limit so AWS uses a POST
|
20
|
+
mm = MyModel.create :first_name=>first_name, :last_name=>last_name
|
21
|
+
mm.save
|
22
|
+
sleep 1
|
23
|
+
assert mm.first_name == first_name
|
24
|
+
assert mm.last_name == last_name
|
25
|
+
mm2 = MyModel.find(mm.id)
|
26
|
+
assert mm2.first_name == first_name
|
27
|
+
assert mm2.last_name == last_name
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_utf8_http_post
|
31
|
+
first_name = "jos�" + ("X" * 1000) # pad the field to help get the URL over the 2000 length limit so AWS uses a POST
|
32
|
+
last_name = "??" + ("X" * 1000) # pad the field to help get the URL over the 2000 length limit so AWS uses a POST
|
33
|
+
mm = MyModel.create :first_name=>first_name, :last_name=>last_name
|
34
|
+
mm.save
|
35
|
+
sleep 1
|
36
|
+
assert mm.first_name == first_name
|
37
|
+
assert mm.last_name == last_name
|
38
|
+
mm2 = MyModel.find(mm.id)
|
39
|
+
assert mm2.first_name == first_name
|
40
|
+
assert mm2.last_name == last_name
|
41
|
+
end
|
42
|
+
|
18
43
|
end
|
data/test/test_usage.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# These ones take longer to run
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require File.join(File.dirname(__FILE__), "/../lib/simple_record")
|
5
|
+
require File.join(File.dirname(__FILE__), "./test_helpers")
|
6
|
+
require File.join(File.dirname(__FILE__), "./test_base")
|
7
|
+
require "yaml"
|
8
|
+
require 'aws'
|
9
|
+
require 'my_model'
|
10
|
+
require 'my_child_model'
|
11
|
+
require 'active_support'
|
12
|
+
|
13
|
+
# Tests for SimpleRecord
|
14
|
+
#
|
15
|
+
|
16
|
+
class TestUsage < TestBase
|
17
|
+
|
18
|
+
|
19
|
+
# ensures that it uses next token and what not
|
20
|
+
def test_select_usage_logging
|
21
|
+
|
22
|
+
SimpleRecord.log_usage(:select=>{:filename=>"/mnt/selects.csv", :format=>:csv})
|
23
|
+
|
24
|
+
num_made = 10
|
25
|
+
num_made.times do |i|
|
26
|
+
mm = MyModel.create(:name=>"Travis", :age=>i, :cool=>true)
|
27
|
+
end
|
28
|
+
|
29
|
+
mms = MyModel.find(:all, :conditions=>["name=?", "Travis"])
|
30
|
+
mms = MyModel.find(:all, :conditions=>["name=?", "Travis"], :order=>"name desc")
|
31
|
+
mms = MyModel.find(:all, :conditions=>["name=? and age>?", "Travis", 3], :order=>"name desc")
|
32
|
+
|
33
|
+
|
34
|
+
SimpleRecord.close_usage_log(:select)
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
end
|
40
|
+
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 3
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 1.4.
|
9
|
+
- 2
|
10
|
+
version: 1.4.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Travis Reeder
|
@@ -17,7 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2010-07-
|
20
|
+
date: 2010-07-16 00:00:00 -07:00
|
21
21
|
default_executable:
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|
@@ -44,12 +44,14 @@ extra_rdoc_files:
|
|
44
44
|
- README.markdown
|
45
45
|
files:
|
46
46
|
- lib/simple_record.rb
|
47
|
+
- lib/simple_record/active_sdb.rb
|
47
48
|
- lib/simple_record/attributes.rb
|
48
49
|
- lib/simple_record/callbacks.rb
|
49
50
|
- lib/simple_record/encryptor.rb
|
50
51
|
- lib/simple_record/errors.rb
|
51
52
|
- lib/simple_record/exceptions.rb
|
52
53
|
- lib/simple_record/json.rb
|
54
|
+
- lib/simple_record/logging.rb
|
53
55
|
- lib/simple_record/password.rb
|
54
56
|
- lib/simple_record/results_array.rb
|
55
57
|
- lib/simple_record/stats.rb
|
@@ -73,6 +75,7 @@ files:
|
|
73
75
|
- test/test_pagination.rb
|
74
76
|
- test/test_results_array.rb
|
75
77
|
- test/test_simple_record.rb
|
78
|
+
- test/test_usage.rb
|
76
79
|
has_rdoc: true
|
77
80
|
homepage: http://github.com/appoxy/simple_record/
|
78
81
|
licenses: []
|
@@ -126,3 +129,4 @@ test_files:
|
|
126
129
|
- test/test_pagination.rb
|
127
130
|
- test/test_results_array.rb
|
128
131
|
- test/test_simple_record.rb
|
132
|
+
- test/test_usage.rb
|