simple_record 2.2.0 → 4.0.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6d82f7f10721f3429254cd5cbf854e2e77215c9b
4
+ data.tar.gz: 8e12f1815cff1df1e25bb2a867ea69fb26ebc1da
5
+ SHA512:
6
+ metadata.gz: ec8b1a17a7af48055349f0f3c1aa8fb65ef1643ea5b69064f20b0b60c69f0bd9a5fb2fb919750a4e7e69f8e0bbe0ad7ec2b364068308eea9cc4bdb4b67d43de9
7
+ data.tar.gz: b1843214f7d63f97b2a18e688a83be8bee04c5819cbcd78cc9faa49cdfd4af60343b8a9b74d162d6ed89b742590560122466f07c8b74f0fe96196168f28e53bd
@@ -27,7 +27,12 @@
27
27
  require 'aws'
28
28
  require 'base64'
29
29
  require 'active_support'
30
- require 'active_support/core_ext'
30
+ if ActiveSupport::VERSION::MAJOR >= 3
31
+ # had to do this due to some bug: https://github.com/rails/rails/issues/12876
32
+ # fix: https://github.com/railsmachine/shadow_puppet/pull/19/files
33
+ require 'active_support/deprecation'
34
+ require 'active_support/core_ext'
35
+ end
31
36
  begin
32
37
  # comment out line below to test rails2 validations
33
38
  require 'active_model'
@@ -98,6 +103,9 @@ module SimpleRecord
98
103
  def close_usage_log(type)
99
104
  return unless @usage_logging_options[type]
100
105
  @usage_logging_options[type][:file].close if @usage_logging_options[type][:file]
106
+ # unless we remove it, it will keep trying to log these events
107
+ # and will fail because the file is closed.
108
+ @usage_logging_options.delete(type)
101
109
  end
102
110
 
103
111
  def usage_logging_options
@@ -502,7 +510,7 @@ module SimpleRecord
502
510
  def create_or_update(options) #:nodoc:
503
511
  # puts 'create_or_update'
504
512
  ret = true
505
- _run_save_callbacks do
513
+ run_callbacks :save do
506
514
  result = new_record? ? create(options) : update(options)
507
515
  # puts 'save_callbacks result=' + result.inspect
508
516
  ret = result
@@ -513,7 +521,7 @@ module SimpleRecord
513
521
  def create(options) #:nodoc:
514
522
  puts '3 create'
515
523
  ret = true
516
- _run_create_callbacks do
524
+ run_callbacks :create do
517
525
  x = do_actual_save(options)
518
526
  # puts 'create old_save result=' + x.to_s
519
527
  ret = x
@@ -525,7 +533,7 @@ module SimpleRecord
525
533
  def update(options) #:nodoc:
526
534
  puts '3 update'
527
535
  ret = true
528
- _run_update_callbacks do
536
+ run_callbacks :update do
529
537
  x = do_actual_save(options)
530
538
  # puts 'update old_save result=' + x.to_s
531
539
  ret = x
@@ -773,20 +781,19 @@ module SimpleRecord
773
781
  results = []
774
782
  to_save = []
775
783
  if objects && objects.size > 0
776
- objects.each do |o|
777
- ok = o.pre_save(options)
778
- raise "Pre save failed on object [" + o.inspect + "]" if !ok
779
- results << ok
780
- next if !ok # todo: this shouldn't be here should it? raises above
781
- o.pre_save2
782
- to_save << Aws::SdbInterface::Item.new(o.id, o.attributes, true)
783
- if to_save.size == 25 # Max amount SDB will accept
784
- connection.batch_put_attributes(domain, to_save, options)
785
- to_save.clear
784
+ objects.each_slice(25) do |objs|
785
+ objs.each do |o|
786
+ ok = o.pre_save(options)
787
+ raise "Pre save failed on object [" + o.inspect + "]" if !ok
788
+ results << ok
789
+ next if !ok # todo: this shouldn't be here should it? raises above
790
+ o.pre_save2
791
+ to_save << Aws::SdbInterface::Item.new(o.id, o.attributes, true)
786
792
  end
793
+ connection.batch_put_attributes(domain, to_save, options)
794
+ to_save.clear
787
795
  end
788
796
  end
789
- connection.batch_put_attributes(domain, to_save, options) if to_save.size > 0
790
797
  objects.each do |o|
791
798
  o.save_lobs(nil)
792
799
  end
@@ -796,8 +803,9 @@ module SimpleRecord
796
803
  # Pass in an array of objects
797
804
  def self.batch_delete(objects, options={})
798
805
  if objects
799
- # 25 item limit, we should maybe handle this limit in here.
800
- connection.batch_delete_attributes @domain, objects.collect { |x| x.id }
806
+ objects.each_slice(25) do |objs|
807
+ connection.batch_delete_attributes @domain, objs.collect { |x| x.id }
808
+ end
801
809
  end
802
810
  end
803
811
 
@@ -844,7 +852,7 @@ module SimpleRecord
844
852
 
845
853
  def destroy
846
854
  if @@active_model
847
- _run_destroy_callbacks do
855
+ run_callbacks :destroy do
848
856
  delete
849
857
  end
850
858
  else
@@ -20,13 +20,7 @@
20
20
  # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
21
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
  #
23
-
24
- begin
25
- require 'uuidtools'
26
- rescue LoadError => e
27
- STDERR.puts("SimpleRecord requires the uuidtools gem. Run \'gem install uuidtools\' and try again.")
28
- exit
29
- end
23
+ require 'uuidtools'
30
24
 
31
25
  module SimpleRecord
32
26
 
@@ -355,7 +349,8 @@ module SimpleRecord
355
349
  end
356
350
 
357
351
  def generate_id # :nodoc:
358
- UUIDTools::UUID.timestamp_create().to_s
352
+ # mac address creation sometimes throws errors if mac address isn't available
353
+ UUIDTools::UUID.random_create().to_s
359
354
  end
360
355
 
361
356
  protected
@@ -219,24 +219,19 @@ module SimpleRecord
219
219
  define_dirty_methods(arg_s)
220
220
  end
221
221
 
222
- def has_many(*args)
223
- args.each do |arg|
224
- #okay, this creates an instance method with the pluralized name of the symbol passed to belongs_to
225
- send(:define_method, arg) do
226
- #when called, the method creates a new, very temporary instance of the Activerecordtosdb_subrecord class
227
- #It is passed the three initializers it needs:
228
- #note the first parameter is just a string by time new gets it, like "user"
229
- #the second and third parameters are still a variable when new gets it, like user_id
230
- return eval(%{Activerecordtosdb_subrecord_array.new('#{arg}', self.class.name ,id)})
231
- end
222
+ # allows foreign key through class_name
223
+ # i.e. options[:class_name] = 'User'
224
+ def has_many(association_id, options = {})
225
+
226
+ send(:define_method, association_id) do
227
+ return eval(%{Activerecordtosdb_subrecord_array.new('#{options[:class_name] ? options[:class_name] : association_id}', '#{options[:class_name] ? association_id.to_s : self.class.name}', id)})
232
228
  end
233
- #Disclaimer: this whole funciton just seems crazy to me, and a bit inefficient. But it was the clearest way I could think to do it code wise.
234
- #It's bad programming form (imo) to have a class method require something that isn't passed to it through it's variables.
235
- #I couldn't pass the id when calling find, since the original find doesn't work that way, so I was left with this.
236
229
  end
237
230
 
238
- def has_one(*args)
239
-
231
+ def has_many(association_id, options = {})
232
+ send(:define_method, association_id) do
233
+ return eval(%{Activerecordtosdb_subrecord_array.new('#{options[:class_name] ? options[:class_name] : association_id}', '#{options[:class_name] ? association_id.to_s : self.class.name}', id)}).first
234
+ end
240
235
  end
241
236
 
242
237
 
@@ -437,4 +432,4 @@ module SimpleRecord
437
432
  end
438
433
 
439
434
  end
440
- end
435
+ end
@@ -119,6 +119,8 @@ module SimpleRecord
119
119
  value = to_date(value)
120
120
  elsif att_meta.type == :boolean
121
121
  value = to_bool(value)
122
+ elsif att_meta.type == :float
123
+ value = Float(value)
122
124
  end
123
125
  value
124
126
  end
@@ -303,4 +305,4 @@ module SimpleRecord
303
305
  end
304
306
  end
305
307
 
306
- end
308
+ end
@@ -71,7 +71,9 @@ module SimpleRecord
71
71
  val = self.send(k)
72
72
  puts 'val=' + val.inspect
73
73
  if val
74
- ret = self.class.find(:first, :conditions=>["#{k}=?", val])
74
+ conditions = new_record? ? ["#{k}=?", val] : ["#{k}=? AND id != ?", val, self.id]
75
+
76
+ ret = self.class.find(:first, :conditions=>conditions)
75
77
  puts 'ret=' + ret.inspect
76
78
  if ret
77
79
  errors.add(k, "must be unique.")
metadata CHANGED
@@ -1,51 +1,112 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: simple_record
3
- version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 2.2.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 4.0.0
6
5
  platform: ruby
7
- authors:
6
+ authors:
8
7
  - Travis Reeder
9
8
  - Chad Arimura
10
9
  - RightScale
11
10
  autorequire:
12
11
  bindir: bin
13
12
  cert_chain: []
14
-
15
- date: 2011-07-08 00:00:00 Z
16
- dependencies:
17
- - !ruby/object:Gem::Dependency
18
- name: aws
13
+ date: 2012-01-12 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: uuidtools
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
19
23
  prerelease: false
20
- requirement: &id001 !ruby/object:Gem::Requirement
21
- none: false
22
- requirements:
23
- - - ">="
24
- - !ruby/object:Gem::Version
25
- version: "0"
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - '>='
27
+ - !ruby/object:Gem::Version
28
+ version: '0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: activesupport
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
26
36
  type: :runtime
27
- version_requirements: *id001
28
- - !ruby/object:Gem::Dependency
29
- name: concur
30
37
  prerelease: false
31
- requirement: &id002 !ruby/object:Gem::Requirement
32
- none: false
33
- requirements:
34
- - - ">="
35
- - !ruby/object:Gem::Version
36
- version: "0"
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: i18n
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ - !ruby/object:Gem::Dependency
58
+ name: jeweler
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ - !ruby/object:Gem::Dependency
72
+ name: aws
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
37
78
  type: :runtime
38
- version_requirements: *id002
39
- description: ActiveRecord like interface for Amazon SimpleDB. Store, query, shard, etc. By http://www.appoxy.com
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ - !ruby/object:Gem::Dependency
86
+ name: concur
87
+ requirement: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ type: :runtime
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ description: ActiveRecord like interface for Amazon SimpleDB. Store, query, shard,
100
+ etc. By http://www.appoxy.com
40
101
  email: travis@appoxy.com
41
102
  executables: []
42
-
43
103
  extensions: []
44
-
45
- extra_rdoc_files:
104
+ extra_rdoc_files:
105
+ - LICENSE.markdown
106
+ - README.markdown
107
+ files:
46
108
  - LICENSE.markdown
47
109
  - README.markdown
48
- files:
49
110
  - lib/simple_record.rb
50
111
  - lib/simple_record/active_sdb.rb
51
112
  - lib/simple_record/attributes.rb
@@ -60,34 +121,27 @@ files:
60
121
  - lib/simple_record/stats.rb
61
122
  - lib/simple_record/translations.rb
62
123
  - lib/simple_record/validations.rb
63
- - LICENSE.markdown
64
- - README.markdown
65
124
  homepage: http://github.com/appoxy/simple_record/
66
125
  licenses: []
67
-
126
+ metadata: {}
68
127
  post_install_message:
69
128
  rdoc_options: []
70
-
71
- require_paths:
129
+ require_paths:
72
130
  - lib
73
- required_ruby_version: !ruby/object:Gem::Requirement
74
- none: false
75
- requirements:
76
- - - ">="
77
- - !ruby/object:Gem::Version
78
- version: "0"
79
- required_rubygems_version: !ruby/object:Gem::Requirement
80
- none: false
81
- requirements:
82
- - - ">="
83
- - !ruby/object:Gem::Version
84
- version: "0"
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - '>='
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - '>='
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
85
141
  requirements: []
86
-
87
142
  rubyforge_project:
88
- rubygems_version: 1.8.5
143
+ rubygems_version: 2.2.2
89
144
  signing_key:
90
- specification_version: 3
145
+ specification_version: 4
91
146
  summary: ActiveRecord like interface for Amazon SimpleDB. By http://www.appoxy.com
92
147
  test_files: []
93
-