simple_record 2.1.3 → 2.1.6

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.
@@ -1,71 +1,51 @@
1
1
  module SimpleRecord
2
- module Json
2
+ module Json
3
3
 
4
- def self.included(base)
5
- base.extend ClassMethods
6
- end
4
+ def self.included(base)
5
+ base.extend ClassMethods
6
+ end
7
7
 
8
- module ClassMethods
8
+ module ClassMethods
9
9
 
10
- def json_create(object)
11
- obj = new
12
- for key, value in object
13
- next if key == 'json_class'
14
- if key == 'id'
15
- obj.id = value
16
- next
17
- end
18
- obj.set key, value
19
- end
20
- obj
21
- end
10
+ def json_create(object)
11
+ obj = new
12
+ for key, value in object
13
+ next if key == 'json_class'
14
+ if key == 'id'
15
+ obj.id = value
16
+ next
17
+ end
18
+ obj.set key, value
19
+ end
20
+ obj
21
+ end
22
22
 
23
- def from_json(json_string)
24
- return JSON.parse(json_string)
25
- end
23
+ def from_json(json_string)
24
+ return JSON.parse(json_string)
25
+ end
26
26
 
27
- end
28
- #
29
- # def to_json(*a)
30
- # puts 'SimpleRecord to_json called'
31
- # result = {
32
- # 'json_class' => self.class.name,
33
- # 'id' => self.id
34
- # }
35
- # defined_attributes_local.each_pair do |name, val|
36
- ## puts name.to_s + "=" + val.inspect
37
- # if val.type == :belongs_to
38
- # result[name.to_s + "_id"] = get_attribute_sdb(name)
39
- # else
40
- # result[name] = get_attribute(name)
41
- # end
42
- ## puts 'result[name]=' + result[name].inspect
43
- # end
44
- # ret = result.to_json(*a)
45
- ## puts 'ret=' + ret.inspect
46
- # return ret
47
- # end
27
+ end
48
28
 
49
- def as_json(options={})
50
- # puts 'SimpleRecord as_json called'
51
- result = {
52
- 'json_class' => self.class.name,
53
- 'id' => self.id
54
- }
55
- defined_attributes_local.each_pair do |name, val|
29
+ def as_json(options={})
30
+ puts 'SimpleRecord as_json called with options: ' + options.inspect
31
+ result = {
32
+ 'id' => self.id
33
+ }
34
+ result['json_class'] = self.class.name unless options[:exclude_json_class]
35
+ defined_attributes_local.each_pair do |name, val|
56
36
  # puts name.to_s + "=" + val.inspect
57
- if val.type == :belongs_to
58
- result[name.to_s + "_id"] = get_attribute_sdb(name)
59
- else
60
- result[name] = get_attribute(name)
61
- end
37
+ if val.type == :belongs_to
38
+ result[name.to_s + "_id"] = get_attribute_sdb(name)
39
+ else
40
+ result[name] = get_attribute(name)
41
+ end
62
42
  # puts 'result[name]=' + result[name].inspect
63
- end
43
+ end
64
44
  # ret = result.as_json(options)
65
45
  # puts 'ret=' + ret.inspect
66
46
  # return ret
67
- result
68
- end
69
-
47
+ result
70
48
  end
49
+
50
+ end
71
51
  end
@@ -1,3 +1,5 @@
1
+ require 'concur'
2
+
1
3
  module SimpleRecord
2
4
 
3
5
  module Sharding
@@ -26,7 +28,7 @@ module SimpleRecord
26
28
  options = params.size > 1 ? params[1] : {}
27
29
 
28
30
  if options[:shard] # User specified shard.
29
- shard = options[:shard]
31
+ shard = options[:shard]
30
32
  domains = shard.is_a?(Array) ? (shard.collect { |x| prefix_shard_name(x) }) : [prefix_shard_name(shard)]
31
33
  else
32
34
  domains = sharded_domains
@@ -34,32 +36,58 @@ module SimpleRecord
34
36
  # puts "sharded_domains=" + domains.inspect
35
37
 
36
38
  single = false
39
+ by_ids = false
37
40
  case params.first
38
41
  when nil then
39
42
  raise "Invalid parameters passed to find: nil."
40
43
  when :all, :first, :count
41
44
  # nada
42
45
  else # single id
46
+ by_ids = true
43
47
  unless params.first.is_a?(Array)
44
48
  single = true
45
49
  end
46
50
  end
47
-
48
- results = ShardedResults.new(params)
51
+ puts 'single? ' + single.inspect
52
+ puts 'by_ids? ' + by_ids.inspect
53
+
54
+ # todo: should have a global executor
55
+ executor = options[:concurrent] ? Concur::Executor.new_multi_threaded_executor : Concur::Executor.new_single_threaded_executor
56
+ results = nil
57
+ if by_ids
58
+ results = []
59
+ else
60
+ results = ShardedResults.new(params)
61
+ end
62
+ futures = []
49
63
  domains.each do |d|
50
- p2 = params.dup
51
- op2 = options.dup
52
- op2[:from] = d
64
+ p2 = params.dup
65
+ op2 = options.dup
66
+ op2[:from] = d
53
67
  op2[:shard_find] = true
54
- p2[1] = op2
55
- rs = find(*p2)
68
+ p2[1] = op2
69
+
70
+ futures << executor.execute do
71
+ puts 'executing=' + p2.inspect
72
+ # todo: catch RecordNotFound errors and throw later if there really isn't any record found.
73
+ rs = find(*p2)
74
+ puts 'rs=' + rs.inspect
75
+ rs
76
+ end
77
+ end
78
+ futures.each do |f|
79
+ puts 'getting future ' + f.inspect
56
80
  if params.first == :first || single
57
- return rs if rs
81
+ puts 'f.get=' + f.get.inspect
82
+ return f.get if f.get
83
+ elsif by_ids
84
+ results << f.get if f.get
58
85
  else
59
- results.add_results rs
86
+ results.add_results f.get
60
87
  end
61
88
  end
62
- puts 'results=' + results.inspect
89
+ executor.shutdown
90
+ # puts 'results=' + results.inspect
63
91
  if params.first == :first || single
64
92
  # Then we found nothing by this point so return nil
65
93
  return nil
@@ -81,7 +109,7 @@ module SimpleRecord
81
109
 
82
110
  def sharded_domains
83
111
  sharded_domains = []
84
- shard_names = shards
112
+ shard_names = shards
85
113
  shard_names.each do |s|
86
114
  sharded_domains << prefix_shard_name(s)
87
115
  end
@@ -91,7 +119,7 @@ module SimpleRecord
91
119
 
92
120
  def sharded_domain
93
121
  # puts 'getting sharded_domain'
94
- options = self.class.sharding_options
122
+ options = self.class.sharding_options
95
123
  # val = self.send(options[:on])
96
124
  # puts "val=" + val.inspect
97
125
  # shards = options[:shards] # is user passed in static array of shards
@@ -107,8 +135,8 @@ module SimpleRecord
107
135
  include Enumerable
108
136
 
109
137
  def initialize(params)
110
- @params = params
111
- @options = params.size > 1 ? params[1] : {}
138
+ @params = params
139
+ @options = params.size > 1 ? params[1] : {}
112
140
  @results_arrays = []
113
141
  end
114
142
 
@@ -146,9 +174,9 @@ module SimpleRecord
146
174
  return element_at(index)
147
175
  else
148
176
  offset = i[0]
149
- rows = i[1]
150
- ret = []
151
- x = offset
177
+ rows = i[1]
178
+ ret = []
179
+ x = offset
152
180
  while x < (offset+rows)
153
181
  ret << element_at(x)
154
182
  x+=1
@@ -268,9 +296,9 @@ module SimpleRecord
268
296
  # puts 'sdbm_hash ' + str.inspect
269
297
  hash = 0
270
298
  len.times { |i|
271
- c = str[i]
299
+ c = str[i]
272
300
  # puts "c=" + c.class.name + "--" + c.inspect + " -- " + c.ord.inspect
273
- c = c.ord
301
+ c = c.ord
274
302
  hash = c + (hash << 6) + (hash << 16) - hash
275
303
  }
276
304
  # puts "hash=" + hash.inspect
@@ -9,7 +9,7 @@ module SimpleRecord
9
9
  # end
10
10
 
11
11
  def self.included(base)
12
- puts 'Validations included ' + base.inspect
12
+ # puts 'Validations included ' + base.inspect
13
13
  # if defined?(ActiveModel)
14
14
  # base.class_eval do
15
15
  # alias_method :am_valid?, :valid?
metadata CHANGED
@@ -1,38 +1,50 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: simple_record
3
- version: !ruby/object:Gem::Version
4
- version: 2.1.3
3
+ version: !ruby/object:Gem::Version
5
4
  prerelease:
5
+ version: 2.1.6
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Travis Reeder
9
9
  - Chad Arimura
10
10
  - RightScale
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2011-02-11 00:00:00.000000000 -08:00
15
- default_executable:
16
- dependencies:
17
- - !ruby/object:Gem::Dependency
14
+
15
+ date: 2011-05-08 00:00:00 Z
16
+ dependencies:
17
+ - !ruby/object:Gem::Dependency
18
18
  name: aws
19
- requirement: &26752296 !ruby/object:Gem::Requirement
19
+ prerelease: false
20
+ requirement: &id001 !ruby/object:Gem::Requirement
20
21
  none: false
21
- requirements:
22
- - - ! '>='
23
- - !ruby/object:Gem::Version
24
- version: '0'
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: "0"
25
26
  type: :runtime
27
+ version_requirements: *id001
28
+ - !ruby/object:Gem::Dependency
29
+ name: concur
26
30
  prerelease: false
27
- version_requirements: *26752296
28
- description: ActiveRecord like interface for Amazon SimpleDB. Store, query, shard,
29
- etc. By http://www.appoxy.com
31
+ requirement: &id002 !ruby/object:Gem::Requirement
32
+ none: false
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: "0"
37
+ type: :runtime
38
+ version_requirements: *id002
39
+ description: ActiveRecord like interface for Amazon SimpleDB. Store, query, shard, etc. By http://www.appoxy.com
30
40
  email: travis@appoxy.com
31
41
  executables: []
42
+
32
43
  extensions: []
33
- extra_rdoc_files:
44
+
45
+ extra_rdoc_files:
34
46
  - README.markdown
35
- files:
47
+ files:
36
48
  - lib/simple_record.rb
37
49
  - lib/simple_record/active_sdb.rb
38
50
  - lib/simple_record/attributes.rb
@@ -48,79 +60,32 @@ files:
48
60
  - lib/simple_record/translations.rb
49
61
  - lib/simple_record/validations.rb
50
62
  - README.markdown
51
- - test/conversions_test.rb
52
- - test/model_with_enc.rb
53
- - test/my_base_model.rb
54
- - test/my_child_model.rb
55
- - test/my_model.rb
56
- - test/my_sharded_model.rb
57
- - test/my_simple_model.rb
58
- - test/paging_array_test.rb
59
- - test/temp.rb
60
- - test/temp_test.rb
61
- - test/test_base.rb
62
- - test/test_dirty.rb
63
- - test/test_encodings.rb
64
- - test/test_global_options.rb
65
- - test/test_helpers.rb
66
- - test/test_json.rb
67
- - test/test_lobs.rb
68
- - test/test_marshalled.rb
69
- - test/test_pagination.rb
70
- - test/test_rails3.rb
71
- - test/test_results_array.rb
72
- - test/test_shards.rb
73
- - test/test_simple_record.rb
74
- - test/test_usage.rb
75
- - test/test_validations.rb
76
- has_rdoc: true
77
63
  homepage: http://github.com/appoxy/simple_record/
78
64
  licenses: []
65
+
79
66
  post_install_message:
80
67
  rdoc_options: []
81
- require_paths:
68
+
69
+ require_paths:
82
70
  - lib
83
- required_ruby_version: !ruby/object:Gem::Requirement
71
+ required_ruby_version: !ruby/object:Gem::Requirement
84
72
  none: false
85
- requirements:
86
- - - ! '>='
87
- - !ruby/object:Gem::Version
88
- version: '0'
89
- required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: "0"
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
78
  none: false
91
- requirements:
92
- - - ! '>='
93
- - !ruby/object:Gem::Version
94
- version: '0'
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: "0"
95
83
  requirements: []
84
+
96
85
  rubyforge_project:
97
- rubygems_version: 1.5.1
86
+ rubygems_version: 1.7.2
98
87
  signing_key:
99
88
  specification_version: 3
100
89
  summary: ActiveRecord like interface for Amazon SimpleDB. By http://www.appoxy.com
101
- test_files:
102
- - test/conversions_test.rb
103
- - test/model_with_enc.rb
104
- - test/my_base_model.rb
105
- - test/my_child_model.rb
106
- - test/my_model.rb
107
- - test/my_sharded_model.rb
108
- - test/my_simple_model.rb
109
- - test/paging_array_test.rb
110
- - test/temp.rb
111
- - test/temp_test.rb
112
- - test/test_base.rb
113
- - test/test_dirty.rb
114
- - test/test_encodings.rb
115
- - test/test_global_options.rb
116
- - test/test_helpers.rb
117
- - test/test_json.rb
118
- - test/test_lobs.rb
119
- - test/test_marshalled.rb
120
- - test/test_pagination.rb
121
- - test/test_rails3.rb
122
- - test/test_results_array.rb
123
- - test/test_shards.rb
124
- - test/test_simple_record.rb
125
- - test/test_usage.rb
126
- - test/test_validations.rb
90
+ test_files: []
91
+
@@ -1,44 +0,0 @@
1
- require "yaml"
2
- require 'aws'
3
-
4
- require_relative "test_base"
5
- require_relative "../lib/simple_record"
6
- require_relative 'my_model'
7
- require_relative 'my_child_model'
8
-
9
- class ConversionsTest < TestBase
10
-
11
- def test_ints
12
- x = 0
13
- puts SimpleRecord::Translations.pad_and_offset(x)
14
- assert_equal "09223372036854775808", SimpleRecord::Translations.pad_and_offset(x)
15
-
16
- x = 1
17
- puts SimpleRecord::Translations.pad_and_offset(x)
18
- assert_equal "09223372036854775809", SimpleRecord::Translations.pad_and_offset(x)
19
-
20
- x = "09223372036854775838"
21
- puts SimpleRecord::Translations.un_offset_int(x)
22
- assert_equal 30, SimpleRecord::Translations.un_offset_int(x)
23
- end
24
-
25
- # All from examples here: http://tools.ietf.org/html/draft-wood-ldapext-float-00
26
- def test_floats
27
- zero = "3 000 0.0000000000000000"
28
- assert_equal zero, SimpleRecord::Translations.pad_and_offset(0.0)
29
-
30
- puts 'induced = ' + "3.25e5".to_f.to_s
31
-
32
- assert_equal "5 005 3.2500000000000000", SimpleRecord::Translations.pad_and_offset("3.25e5".to_f)
33
- assert_equal "4 994 8.4000000000000000", SimpleRecord::Translations.pad_and_offset("8.4e-5".to_f)
34
- assert_equal "4 992 8.4000000000000000", SimpleRecord::Translations.pad_and_offset("8.4e-7".to_f)
35
- assert_equal "3 000 0.0000000000000000", SimpleRecord::Translations.pad_and_offset("0.0e0".to_f)
36
- assert_equal "2 004 5.7500000000000000", SimpleRecord::Translations.pad_and_offset("-4.25e-4".to_f)
37
- assert_equal "2 004 3.6500000000000000", SimpleRecord::Translations.pad_and_offset("-6.35e-4".to_f)
38
- assert_equal "2 003 3.6500000000000000", SimpleRecord::Translations.pad_and_offset("-6.35e-3".to_f)
39
- assert_equal "1 895 6.0000000000000000", SimpleRecord::Translations.pad_and_offset("-4.0e105".to_f)
40
- assert_equal "1 894 6.0000000000000000", SimpleRecord::Translations.pad_and_offset("-4.0e105".to_f)
41
- assert_equal "1 894 4.0000000000000000", SimpleRecord::Translations.pad_and_offset("-6.0e105".to_f)
42
-
43
- end
44
- end