idata 0.1.25 → 0.1.26

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/iexport +16 -5
  3. data/lib/idata/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6e16b69f104f9c8098ea825a6f577d72fc69da11
4
- data.tar.gz: 34f311bac4c9a547c2885199de374330c5e6ac5f
3
+ metadata.gz: 7615b5632f23a4d6a9f12ae44516ba1a985c71d9
4
+ data.tar.gz: 1de25681e830eba21537288a82a36b5d0a4658e6
5
5
  SHA512:
6
- metadata.gz: 2b6f9a1013a17610307ca5019811981a83e0c87ba31cc3cf46e371434b244bdd7456f8c3674df11466e5f38a72333cedbe2647136ee06f349e8531c59f90a461
7
- data.tar.gz: fc7a3349bc137e8d5d8a60b54fd919a6d7d5bf65bf05ee366095d9cb623e5678c945879c29612901e8f30b54bd3d43c2b2c05f22f3e072c5b0df7b5d8e65c766
6
+ metadata.gz: 8c38b43eac63a08f792b2fee967ec6aaa59e12e446a92641f4c5c7fb6a783ff210ac2925ba5051d4a27b2e7c0bd7e7f1678a6e7df43d9040d5294c44a0fa13a1
7
+ data.tar.gz: 7f8a19d9c36edb2a5a1d2521b457cb631671755838f626f13b0f9f12339812c71ceebfb2af445350ef779158e6748fd4320115f537fcd4b3e8b934c800224eff
data/bin/iexport CHANGED
@@ -219,7 +219,7 @@ end
219
219
 
220
220
  CSV.open($options[:output], "wb", :quote_char => $options[:quote_char], :col_sep => $options[:delim], :row_sep => $options[:linebreak], :force_quotes => $options[:quotes]) do |csv|
221
221
  if $options[:query]
222
- scope = Product.find_by_sql($options[:query])
222
+ scope = ActiveRecord::Base.connection.execute($options[:query])
223
223
  else
224
224
  scope = Product.select($options[:select]).where($options[:where])
225
225
  end
@@ -227,14 +227,25 @@ CSV.open($options[:output], "wb", :quote_char => $options[:quote_char], :col_sep
227
227
  first = scope.first
228
228
 
229
229
  if first
230
- csv << first.attributes.delete_if{|k,v| k.nil? || $options[:exclude].include?(k) }.keys if $options[:headers]
230
+ if $options[:query]
231
+ csv << first.delete_if{|k,v| k.nil? || $options[:exclude].include?(k) }.keys if $options[:headers]
232
+ else
233
+ csv << first.attributes.delete_if{|k,v| k.nil? || $options[:exclude].include?(k) }.keys if $options[:headers]
234
+ end
231
235
  else
232
- # only use .column_names when table is empty, to ensure fields match values
233
- csv << Product.column_names if $options[:headers]
236
+ unless $options[:query]
237
+ # only use .column_names when table is empty, to ensure fields match values
238
+ csv << Product.column_names if $options[:headers]
239
+ end
234
240
  end
235
241
 
236
242
  scope.each do |item|
237
- attrs = item.attributes.delete_if{|k,v| k.nil? || $options[:exclude].include?(k) }.values
243
+ if $options[:query]
244
+ attrs = item.delete_if{|k,v| k.nil? || $options[:exclude].include?(k) }.values
245
+ else
246
+ attrs = item.attributes.delete_if{|k,v| k.nil? || $options[:exclude].include?(k) }.values
247
+ end
248
+
238
249
  if !$options[:quote_empty]
239
250
  attrs.map!{|e| e == "" ? nil : e }
240
251
  end
data/lib/idata/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Idata
2
- VERSION = "0.1.25"
2
+ VERSION = "0.1.26"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: idata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.25
4
+ version: 0.1.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nghi Pham