ika 1.0.12 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +12 -2
  3. data/lib/ika.rb +22 -17
  4. data/lib/ika/version.rb +1 -1
  5. metadata +36 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dc3a9857afd1cd1f1b3e18273b2d698df2c4e19f
4
- data.tar.gz: 4153e44d62da2100bf8cef338868c3b229dc17f2
3
+ metadata.gz: f6ba4beaa3e44cba6dc7ae05c0cee0b2ce6f1643
4
+ data.tar.gz: 41df3e2109b55567e0adf4f5aa7ef8f5610245a6
5
5
  SHA512:
6
- metadata.gz: 3eac737c70afa348306879f02029ee5592a3dcc8e58b74348cb75095423c652b738b1f2058111fd689b551f98ce39a176aea5ad1f2faabf436e2c59d35a7204d
7
- data.tar.gz: 383ee4dfc605d8093b9cd69d2a6b0ad5673c6c78957396e76eac356c17a505f49b5058d8f8078687574d3d642b45d10d3834079b4cc04bba8a10ee6fd701fd62
6
+ metadata.gz: 5200687ec6745fba87492911e4226829452f847f41463132305c93a5e30b72c66cb9a85c5de7aba2b57cdb021f0ee21af4b4f9bdaa5184d646dc04bf2cc41fbb
7
+ data.tar.gz: b9913f5e9b904b5adacbe802ae62708bff64846c548d9bda011557b5d3aebd66fc11a12a307d56f181ea56eadeea27dfdab64d9d4821650372e50a08aa2a3616
data/README.md CHANGED
@@ -74,14 +74,24 @@ User.exist?(id: 2)
74
74
  # => false
75
75
  ```
76
76
 
77
+ ## Sync mode
78
+
79
+ Sync mode performs that ika deletes all data of importing models. For example, if exporting data includes that id is 1 and 2, and there are already exists data that id is 1, 2 and 3, sync importing deletes the data of id 3.
80
+
77
81
  ## Others
78
82
 
79
83
  * **DO NOT USE sync mode if you are using `include` option.**
80
84
  * If the same id exists, Ika uses `UPDATE`.
81
85
  * Uploaded files by `carrierwave` will be checked their md5 hash and do nothing if they exist and md5 is matched.
82
- * If already exists `import` or `export` methods, you can use `ika_import` or `ika_export` methods.
86
+ * If there already exists `import` or `export` methods, you can use `ika_import` or `ika_export` methods.
87
+
88
+ ## Contributing
89
+
90
+ ### Test
91
+
92
+ You need to run `bundle exec rake db:create db:migrate` on `spec/dummy` before testing.
83
93
 
84
94
  ## License
85
95
 
86
- Copyright (c) 2015 Aqutras
96
+ Copyright (c) 2015-2016 Aqutras
87
97
  This project rocks and uses MIT-LICENSE.
data/lib/ika.rb CHANGED
@@ -1,6 +1,5 @@
1
- if Rails.env == 'test'
2
- require 'carrierwave'
3
- end
1
+ require 'oj'
2
+ require 'carrierwave' if Rails.env == 'test'
4
3
  require 'carrierwave/serialization'
5
4
  require 'carrierwave/base64uploader'
6
5
 
@@ -14,7 +13,7 @@ module Ika
14
13
  if json_or_array.is_a?(Array)
15
14
  objects = json_or_array
16
15
  else
17
- objects = JSON.parse(json_or_array)
16
+ objects = Oj.load(json_or_array)
18
17
  objects = [objects] unless objects.is_a?(Array)
19
18
  end
20
19
  json_or_array = nil
@@ -76,6 +75,7 @@ module Ika
76
75
  end
77
76
 
78
77
  def ika_export(options = {}, objects = nil)
78
+ preset_json_with_raw_data = CarrierWave::Uploader::Base.json_with_raw_data
79
79
  CarrierWave::Uploader::Base.json_with_raw_data = true
80
80
  all_symbol = true
81
81
  options[:include] ||= []
@@ -87,26 +87,26 @@ module Ika
87
87
 
88
88
  if all_symbol
89
89
  json = objects.to_json(include: options[:include])
90
- CarrierWave::Uploader::Base.json_with_raw_data = false
90
+ CarrierWave::Uploader::Base.json_with_raw_data = preset_json_with_raw_data
91
91
  return json
92
92
  end
93
93
 
94
94
  whole_obj_arr = []
95
95
  objects.each do |object|
96
- obj_arr = JSON.parse(object.to_json)
96
+ obj_arr = Oj.load(object.to_json)
97
97
  options[:include].each do |relation|
98
98
  if relation.is_a?(::Hash)
99
99
  relation.keys.each do |property|
100
- obj_arr[property] = JSON.parse(object.try(property).export({include: relation[property]}, object.try(property)))
100
+ obj_arr[property.to_s] = Oj.load(object.try(property).export({include: relation[property]}, object.try(property)))
101
101
  end
102
102
  elsif relation.is_a?(Symbol)
103
- obj_arr[relation] = JSON.parse(object.try(relation).present? ? object.try(relation).to_json : '[]')
103
+ obj_arr[relation.to_s] = Oj.load(object.try(relation).present? ? object.try(relation).to_json : '[]')
104
104
  end
105
105
  end
106
106
  whole_obj_arr.push(obj_arr)
107
107
  end
108
- CarrierWave::Uploader::Base.json_with_raw_data = false
109
- JSON.generate(whole_obj_arr)
108
+ CarrierWave::Uploader::Base.json_with_raw_data = preset_json_with_raw_data
109
+ Oj.dump(whole_obj_arr)
110
110
  end
111
111
 
112
112
  def export(options = {}, objects = nil)
@@ -115,6 +115,7 @@ module Ika
115
115
  end
116
116
 
117
117
  def ika_export(options = {}, objects = nil)
118
+ preset_json_with_raw_data = CarrierWave::Uploader::Base.json_with_raw_data
118
119
  CarrierWave::Uploader::Base.json_with_raw_data = true
119
120
  objects ||= self
120
121
  all_symbol = true
@@ -125,23 +126,27 @@ module Ika
125
126
  end
126
127
 
127
128
  if all_symbol
128
- json = objects.to_json(include: options[:include])
129
- CarrierWave::Uploader::Base.json_with_raw_data = false
129
+ if objects.attributes.keys.include? 'type'
130
+ json = objects.to_json(include: options[:include], methods: :type)
131
+ else
132
+ json = objects.to_json(include: options[:include])
133
+ end
134
+ CarrierWave::Uploader::Base.json_with_raw_data = preset_json_with_raw_data
130
135
  return json
131
136
  end
132
137
 
133
- obj_hash = JSON.parse objects.to_json
138
+ obj_hash = Oj.load objects.to_json
134
139
  options[:include].each do |relation|
135
140
  if relation.is_a?(::Hash)
136
141
  relation.keys.each do |property|
137
- obj_hash[property] = JSON.parse(objects.try(property).includes(relation[property]).export({include: relation[property]}, objects.try(property)))
142
+ obj_hash[property.to_s] = Oj.load(objects.try(property).includes(relation[property]).export({include: relation[property]}, objects.try(property)))
138
143
  end
139
144
  elsif relation.is_a?(Symbol)
140
- obj_hash[relation] = JSON.parse(objects.try(relation).to_json)
145
+ obj_hash[relation.to_s] = Oj.load(objects.try(relation).to_json)
141
146
  end
142
147
  end
143
- CarrierWave::Uploader::Base.json_with_raw_data = false
144
- JSON.generate(obj_hash)
148
+ CarrierWave::Uploader::Base.json_with_raw_data = preset_json_with_raw_data
149
+ Oj.dump(obj_hash)
145
150
  end
146
151
 
147
152
  def export(options = {}, objects = nil)
data/lib/ika/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ika
2
- VERSION = '1.0.12'
2
+ VERSION = '1.1.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ika
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.12
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Makoto NAKAYA
@@ -9,22 +9,50 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-04-22 00:00:00.000000000 Z
12
+ date: 2017-09-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: rails
15
+ name: activerecord
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: 4.2.0
20
+ version: '4.0'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - "~>"
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '4.0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: oj
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rails
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '5.1'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
26
54
  - !ruby/object:Gem::Version
27
- version: 4.2.0
55
+ version: '5.1'
28
56
  - !ruby/object:Gem::Dependency
29
57
  name: sqlite3
30
58
  requirement: !ruby/object:Gem::Requirement
@@ -159,7 +187,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
159
187
  version: '0'
160
188
  requirements: []
161
189
  rubyforge_project:
162
- rubygems_version: 2.4.5
190
+ rubygems_version: 2.5.1
163
191
  signing_key:
164
192
  specification_version: 4
165
193
  summary: Implement Import/Export feature to ActiveRecord models.