active_admin_simple_import 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/active_admin_simple_import.rb +34 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 38226349676d7a47d2ad19e06a3962a0438072f8
|
4
|
+
data.tar.gz: df84bb7b2a2c2a2e201642773c39e7710da20f1f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1f9fa46da37892368c1ad55894c0a79b8cd519d70332a017da7d864ab9b9785e12af7d37caf164b0c1bf7608004149ced38693a9cbf81aba6b3656d0c406d361
|
7
|
+
data.tar.gz: 8f2e134bfe34b60caf32b5a6bdacfa4dfa25be490370645c4c92c1352ca5390330fcde57ea715877ac2bb9819a9f76c00672b9825fd16537b970976e0dc18fed
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'active_admin'
|
2
|
+
|
3
|
+
module ActiveAdminSimpleImport
|
4
|
+
class Engine < Rails::Engine
|
5
|
+
config.mount_at = '/'
|
6
|
+
end
|
7
|
+
|
8
|
+
module DSL
|
9
|
+
def active_admin_import(options)
|
10
|
+
options = { exclusion_list: [], after_update: nil }
|
11
|
+
.merge options
|
12
|
+
|
13
|
+
collection_action :import, method: :get do
|
14
|
+
render 'import'
|
15
|
+
end
|
16
|
+
|
17
|
+
collection_action :do_import, method: :post do
|
18
|
+
rows = CSV.read params[:csv][:file].tempfile
|
19
|
+
attrs = rows.shift.map{ |a| a.parameterize('_').to_sym }
|
20
|
+
object_class = controller_name.singularize.camelize.constantize
|
21
|
+
objects = rows.map{ |row| Hash[*attrs.zip(row).flatten] }
|
22
|
+
objects.each do |object|
|
23
|
+
edited_object = object_class.find object.delete :id
|
24
|
+
edited_object.update_attributes object.except(*options[:exclusion_list])
|
25
|
+
next if options[:after_update].nil? || !options[:after_update].is_a?(Proc)
|
26
|
+
options[:after_update].call(edited_object, object)
|
27
|
+
end
|
28
|
+
redirect_to collection_path, notice: 'Zaimportowana plik CSV!'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
::ActiveAdmin::DSL.send(:include, ActiveAdminSimpleImport::DSL)
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: active_admin_simple_import
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Damian Romanów
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-13 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A simple hello world gem
|
14
|
+
email: damian.romanow@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/active_admin_simple_import.rb
|
20
|
+
homepage: http://rubygems.org/gems/active_admin_simple_import
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.4.7
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Hola!
|
44
|
+
test_files: []
|
45
|
+
has_rdoc:
|