activerecord_mass_insert 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b955518970b523bd4db4c1a1ff0f456bbbd2215d
4
- data.tar.gz: d190a9b6825700bf95fced9b9b55bd372b63eabd
3
+ metadata.gz: fa01ff53a01bb14c0926a26f816905205ffeffc2
4
+ data.tar.gz: bc10dde065d7f8782dd3b7e04bfe72c67a619d24
5
5
  SHA512:
6
- metadata.gz: 7cb4a29703ad023518508d7a0b6f7db0811a2d49fc6ad4bb9c99f0f05d2fbda163b2210785b7a610f181903e179782974c7a9a72ae768dced4b9e3e08698b0de
7
- data.tar.gz: aa6e97573a3635b817082f80ec13e225c7df46c42704dddbbeb120aec2b6bc0e7fabc9fd61a8eef4f93e2e8807f8f4ed176aa6a232687669bd17c54a3765149d
6
+ metadata.gz: 7464ccd801d7c378e710c2fa3cfb6a92074512e9c0268c4af828e3e93b6601222000e4dc6479aa89da39a47f3a1a240b383a7592f0f66e1504bc1c57c4d1815d
7
+ data.tar.gz: aa77057469cfc75cd67370239134422b568ff0176782e10d7f9f92d53690ee04044ff95484917cc4e882e71f1d7314da6fcf76c8b8f0cf981c45573b4fbb4fda
data/README.md CHANGED
@@ -19,7 +19,16 @@ Or install it yourself as:
19
19
  $ gem install activerecord_mass_insert
20
20
 
21
21
  ## Usage
22
+
22
23
  ```ruby
24
+ class ApplicationRecord < ActiveRecord::Base
25
+ self.abstract_class = true
26
+ extend ActiveRecord::MassInsert::Helper
27
+ end
28
+
29
+ class Dog < ApplicationRecord
30
+ end
31
+
23
32
  payload = '[{"name":"Madison","breed":"Golden","meta":{"rescue":false,"age":null}},{"name":"Daisy","meta":{"rescue":true,"age":18}},{"name":"Gracey","meta":{"rescue":false,"nickname":"Scoogie","age":11}},{"name":"Sadie","meta":{"rescue":true,"dingo_blood":true,"age":11}},{"name":"Raymond","meta":{"rescue":null,"nickname":"Radar","tail":false,"age":11}},{"name":"Nemo","meta":{"rescue":true,"number_of_ears":1,"age":2}}]'
24
33
 
25
34
  dog_ids = Dog.mass_insert(payload, :name, created_at: 'NOW()', updated_at: 'NOW()')
@@ -31,8 +40,8 @@ puts dogs.first.name # => Madison
31
40
  ```
32
41
 
33
42
  For a payload you can pass a JSON objects by itself, in a JSON array, or a ruby array. You can also
34
- pass a ruby object that responds to to_json by itself or in an array. JSON will never be parsed to ruby.
35
- This done to ensure no time is wasted parsing json twice.
43
+ pass a ruby object that responds to to_json by itself or in an array. nil payload is treated as an empty
44
+ json array. JSON will never be parsed to ruby. This done to ensure no time is wasted parsing json twice.
36
45
 
37
46
  ## Development
38
47
 
@@ -46,7 +55,6 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
46
55
 
47
56
  Bug reports and pull requests are welcome on GitHub at https://github.com/rovermicrover/activerecord_mass_insert.
48
57
 
49
-
50
58
  ## License
51
59
 
52
60
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -12,5 +12,3 @@ module ActiveRecord
12
12
  end
13
13
  end
14
14
  end
15
-
16
- ActiveRecord::Base.extend(ActiveRecord::MassInsert::Helper)
@@ -16,7 +16,9 @@ module ActiveRecord
16
16
  private
17
17
 
18
18
  def payload_to_json_array(new_payload)
19
- if new_payload.is_a?(Array) && new_payload.all? { |p| p.is_a?(String) }
19
+ if new_payload.nil?
20
+ new_payload = new_payload.to_s
21
+ elsif new_payload.is_a?(Array) && new_payload.all? { |p| p.is_a?(String) }
20
22
  # If payload is an array of strings, assume its an array
21
23
  # of json objects. contact them togther to form the
22
24
  # inner part of a json array.
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActiveRecord
4
4
  module MassInsert
5
- VERSION = [0, 0, 1].freeze
5
+ VERSION = [0, 1, 0].freeze
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord_mass_insert
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Rove