smuggle 0.1.0 → 0.2.0

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
  SHA1:
3
- metadata.gz: 022c77b6c42d1bc37dcd416781313b5727f76e53
4
- data.tar.gz: bedb4e4033b1a61217546482d9b452f9a6f31f2f
3
+ metadata.gz: b542958f709628b6a1d1fce332e11074c8e00a4c
4
+ data.tar.gz: 8df40c91ed11cd51f8e5b526a31f630cff4a7d9f
5
5
  SHA512:
6
- metadata.gz: e3bad39a5ac3617b108ebf57a26f602d473ae0ca57627e609ad953425d40c7fc3a1942c3237cfba23fa4b1d3119b897dd454d9e138d731f591f35a555b621eea
7
- data.tar.gz: 464f39496e3dacec1d1b950b76f9234652b82402bf4084fd5256638f2bab4d682588998d1d5408665c03906bd49de959d8f3c872f8ca775d72d030478d34893c
6
+ metadata.gz: 187563335fa1100e557bdbbddc7c155f82f755746f546e435d49ac55053ae5e60ce1d8b97cd8e6112eefad5daed8ea6fa584f4791b76e99706a5d7625d310c9e
7
+ data.tar.gz: 11ffc896106586065d7673f3f31dc6c9c4b4c5f60735104d507cc8f70b433d2c3806af62592f4446143ee574e5e8da7f6e6f17df9bb1c4d1f74d6ed17bc6919a
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Smuggle
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/smuggle`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Is a gem to manage exports with ease, separating the logic from the models, resulting in a much cleaner codebase. Easy to use, with familiar structure.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ **Smuggle is not dependent on Rails**, you can use it on ActiveRecord models, as well as plain ruby objects and hashes.
6
6
 
7
7
  ## Installation
8
8
 
@@ -14,30 +14,99 @@ gem 'smuggle'
14
14
 
15
15
  And then execute:
16
16
 
17
- $ bundle
17
+ ```
18
+ $ bundle
19
+ ```
18
20
 
19
21
  Or install it yourself as:
20
22
 
21
- $ gem install smuggle
23
+ ```
24
+ $ gem install smuggle
25
+ ```
26
+
27
+ To generate the base exporter run:
28
+
29
+ ```
30
+ $ rails g smuggle:install
31
+ create app/exporters/application_exporter.rb
32
+ ```
33
+
34
+ To geneate an exporter, you can run the following command:
35
+
36
+ ```
37
+ $ rails g smuggle:exporter user
38
+ create app/exporters/user_exporter.rb
39
+ ```
40
+
41
+ You can also include the attributes you wish to export by running:
42
+
43
+ ```
44
+ $ rails g smuggle:exporter user email username created_at
45
+ create app/exporters/user_exporter.rb
46
+ ```
47
+
48
+ ## Example
49
+
50
+ Inside the `user_exporter.rb` file:
51
+
52
+ ```ruby
53
+ class UserExporter < ApplicationExporter
54
+ attributes :email, :username, :created_at
55
+ end
56
+ ```
57
+
58
+ Extra logic can be establish inside the exporter file, using the same name as the attribute:
59
+
60
+ ```ruby
61
+ class UserExporter < ApplicationExporter
62
+ attributes :email, :username, :created_at
63
+
64
+ def created_at
65
+ super.created_at.strftime("%m/%d/%Y")
66
+ end
67
+ end
68
+ ```
69
+
70
+ If there are no attributes defined in the exporter, all the attributes of the ActiveModel record will be included.
71
+ If it is a hash, then all values will be included.
22
72
 
23
73
  ## Usage
24
74
 
25
- TODO: Write usage instructions here
75
+ Generate the csv in the desired export controller simply call:
26
76
 
27
- ## Development
77
+ ```ruby
78
+ class User
79
+ attr_accessor :name
28
80
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
81
+ def initialize(name)
82
+ @name = name
83
+ end
84
+ end
30
85
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
86
+ class UserExporter < ApplicationExporter
87
+ attributes :name
88
+ end
89
+
90
+ users = [User.new('Rick Sanchez'), User.new('Morty Smith')]
91
+
92
+ Smuggle::Services::Export.call(scope: users, exporter: UserExporter)
93
+ # => "name\n" + "Rick Sanchez\n" + "Morty Smith\n"
94
+ ```
95
+
96
+ Or if you are using active record, the exporter class will be automatically resolved from the scope:
97
+
98
+ ```ruby
99
+ Smuggle::Services::Export.call(scope: User.all)
100
+ ```
32
101
 
33
102
  ## Contributing
34
103
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/smuggle. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
104
+ Bug reports and pull requests are welcome on GitHub at https://github.com/pablocrivella/smuggle.
36
105
 
37
- ## License
106
+ ## Todo
38
107
 
39
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
108
+ - Implement `importer` functionality
40
109
 
41
- ## Code of Conduct
110
+ ## License
42
111
 
43
- Everyone interacting in the Smuggle project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/smuggle/blob/master/CODE_OF_CONDUCT.md).
112
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,14 @@
1
+ Description:
2
+ Generates a exporter for a scope with the given name.
3
+ Additionally, you can pass the attributes you want to include in the export.
4
+
5
+ Example:
6
+ rails generate smuggle:exporter user first_name last_name
7
+
8
+ This will create:
9
+
10
+ # app/exporter/user_exporter.rb
11
+
12
+ class UserExporter < ApplicationExporter
13
+ attributes :first_name, :last_name
14
+ end
@@ -0,0 +1,13 @@
1
+ module Smuggle
2
+ module Generators
3
+ class ExporterGenerator < Rails::Generators::NamedBase
4
+ source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
5
+
6
+ argument :attributes, type: :array, required: false
7
+
8
+ def create_exporter
9
+ template 'exporter.rb', File.join('app/exporters', class_path, "#{file_name}_exporter.rb")
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,4 +1,4 @@
1
- class <%= scope.camelize %>Exporter < ApplicationExporter
1
+ class <%= class_name %>Exporter < ApplicationExporter
2
2
  <% if attributes -%>
3
3
  attributes <%= attributes.map { |attribute| ":#{attribute}" }.join(', ') %>
4
4
  <% end -%>
@@ -0,0 +1,3 @@
1
+
2
+ Description:
3
+ Generates an application exporter as a starting point for your application.
@@ -0,0 +1,11 @@
1
+ module Smuggle
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
5
+
6
+ def copy_application_exporter
7
+ template 'application_exporter.rb', 'app/exporters/application_exporter.rb'
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module Smuggle
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smuggle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pablo Crivella
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-31 00:00:00.000000000 Z
11
+ date: 2017-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -127,9 +127,12 @@ files:
127
127
  - Rakefile
128
128
  - bin/console
129
129
  - bin/setup
130
- - lib/generators/smuggle/smuggle_generator.rb
131
- - lib/generators/templates/exporters/application_exporter.rb
132
- - lib/generators/templates/exporters/exporter.rb
130
+ - lib/generators/smuggle/exporter/USAGE
131
+ - lib/generators/smuggle/exporter/exporter_generator.rb
132
+ - lib/generators/smuggle/exporter/templates/exporter.rb
133
+ - lib/generators/smuggle/install/USAGE
134
+ - lib/generators/smuggle/install/install_generator.rb
135
+ - lib/generators/smuggle/install/templates/application_exporter.rb
133
136
  - lib/smuggle.rb
134
137
  - lib/smuggle/engine.rb
135
138
  - lib/smuggle/exporter/base.rb
@@ -157,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
160
  version: '0'
158
161
  requirements: []
159
162
  rubyforge_project:
160
- rubygems_version: 2.6.12
163
+ rubygems_version: 2.6.13
161
164
  signing_key:
162
165
  specification_version: 4
163
166
  summary: It Exports stuff to CSV
@@ -1,27 +0,0 @@
1
- module Smuggle
2
- module Generators
3
- class SmuggleGenerator < Rails::Generators::Base
4
- namespace 'smuggle'
5
-
6
- source_root File.expand_path('../../templates/exporters', __FILE__)
7
-
8
- desc 'Generates an Exporter with the given NAME.' \
9
- 'Additionally, you can pass the attributes you want to include in the export'
10
-
11
- argument :scope, required: true,
12
- desc: 'The scope to create exporter for, e.g. users, comments'
13
-
14
- argument :attributes, type: :array, required: false,
15
- desc: 'Specify the attributes you want to export, these will also be the headers.'
16
-
17
- def create_initializer_file
18
- return if File.exist?('app/exporters/application_exporter.rb')
19
- copy_file 'application_exporter.rb', 'app/exporters/application_exporter.rb'
20
- end
21
-
22
- def create_exporter
23
- template 'exporter.rb', "app/exporters/#{scope.underscore}_exporter.rb"
24
- end
25
- end
26
- end
27
- end