kuppayam 0.1.36 → 0.1.37

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 33e1150c434795f4e6ca0b222be8d79d87e81ea3dd6081150862c19d6f028939
4
- data.tar.gz: 246c1f3abc61107110317898568cbf096e2e5a226cf046357d7881bf713ac5bf
3
+ metadata.gz: d0d53aeb096234dd00bc3724f3010a4725f7042f4bd80c49d70d46afc5061b8f
4
+ data.tar.gz: 36517488c881016e74bb3197d2783bbffe50d3ac639e6b8e5e2d69448cf0ca6e
5
5
  SHA512:
6
- metadata.gz: 14f700b6c85e40b46158f1473f2e741391078112c4dc46b4ae5f6eb48010df41119b97f2b2b9f9a1df84d3c082b3aa73fd2631df2f20ffc18306029e6d78e738
7
- data.tar.gz: aa725f60777e4d27ed90a4de8afb0e735d29ddf8a34aa6955e972ca41b434d531bbecff00874eac205f7c3877b88fdc9e33a8d0d61b08e7b70a26fe163c282a5
6
+ metadata.gz: 179cc93b5a8eb5501465a1b531f8993fc84f00e234943030d0c474d10bc94b405fd40535cddeeebb648134dbea10f25b1fdab30ac2ccc939f495a0d6be0d569d
7
+ data.tar.gz: 3f551bfd959b18b5e3140fbb9b241be1f44582a52c051142111944fcde360cd7b95fdf213806814810f5109f41b5e06ab69f49ebcd936d74f8ad479679b49d69
File without changes
@@ -101,6 +101,9 @@ module Kuppayam
101
101
  end
102
102
  end
103
103
 
104
+ # Import Data from Various Files
105
+ # -------------------------------
106
+
104
107
  def check_file_type_and_import(path, single_transaction=true, verbose=true)
105
108
  if File.exists?(path)
106
109
  if File.extname(path) == ".csv"
@@ -211,7 +214,8 @@ module Kuppayam
211
214
 
212
215
  def walk_and_import(start, single_transaction=true, verbose=true)
213
216
  puts "Importing Files from the Folder '#{start.to_s}'".yellow if verbose
214
- Dir.foreach(start) do |x|
217
+ items = Dir.foreach(start).sort_by {|x| x }
218
+ items.each do |x|
215
219
  next if x.starts_with?("master")
216
220
  next unless x.ends_with?(".csv")
217
221
  path = File.join(start, x)
@@ -237,6 +241,55 @@ module Kuppayam
237
241
  end
238
242
  end
239
243
 
244
+ # Import Images
245
+ # -------------
246
+
247
+ def import_image(image_path, object_class_name, finder_method, image_class_name, verbose=true)
248
+
249
+ filename = File.basename(image_path, File.extname(image_path))
250
+
251
+ imageable_object = object_class_name.constantize.where("#{finder_method} = ?", filename).first
252
+ image_object = image_class_name.constantize.new
253
+ image_object.imageable = imageable_object
254
+ image_object.image = File.open(image_path)
255
+
256
+ if image_object.valid?
257
+ image_object.save
258
+ else
259
+ puts ""
260
+ puts "Error while saving #{filename} - #{image_path}".red
261
+ puts ""
262
+ end
263
+ end
264
+
265
+ def walk_and_import_images(start, object_class_name, finder_method, image_class_name, verbose=true)
266
+ puts "Importing Images from the Folder '#{start.to_s}'".yellow if verbose
267
+ items = Dir.foreach(start).sort_by {|x| x }
268
+ items.each do |x|
269
+ path = File.join(start, x)
270
+ if x == "." or x == ".."
271
+ next
272
+ elsif File.directory?(path)
273
+ self.walk_and_import_images(path, object_class_name, finder_method, image_class_name, verbose)
274
+ else
275
+ next unless [".png", ".jpg", "jpeg"].include?(File.extname(x.downcase))
276
+ self.import_image(path, object_class_name, finder_method, image_class_name, verbose)
277
+ end
278
+ end
279
+ end
280
+
281
+ def import_image_recursively(path, object_class_name, finder_method, image_class_name, verbose=true)
282
+ print_memory_usage do
283
+ print_time_spent do
284
+ if Dir.exists?(path)
285
+ self.walk_and_import_images(path, object_class_name, finder_method, image_class_name, verbose)
286
+ else
287
+ puts "Import Folder not found: '#{path.to_s}'.".red if verbose
288
+ end
289
+ end
290
+ end
291
+ end
292
+
240
293
  def import_data_file(path, single_transaction=true, verbose=true)
241
294
  print_memory_usage do
242
295
  print_time_spent do
@@ -1,3 +1,3 @@
1
1
  module Kuppayam
2
- VERSION = '0.1.36'
2
+ VERSION = '0.1.37'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kuppayam
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.36
4
+ version: 0.1.37
5
5
  platform: ruby
6
6
  authors:
7
7
  - kpvarma
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-16 00:00:00.000000000 Z
11
+ date: 2018-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -460,6 +460,7 @@ files:
460
460
  - app/views/kuppayam/api/docs/_navbar.html.erb
461
461
  - app/views/kuppayam/api/docs/_navigation.html.erb
462
462
  - app/views/kuppayam/api/docs/show.html.erb
463
+ - app/views/kuppayam/base/show.html.erb
463
464
  - app/views/kuppayam/documents/_crop_form.html.erb
464
465
  - app/views/kuppayam/documents/_form.html.erb
465
466
  - app/views/kuppayam/documents/_new.html.erb