active_model_exporters 0.4.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 03178fbe3efee04338ae0b983c1735ab8210bbae
4
- data.tar.gz: 5c817ded73966c108483d1b9267a27118b952603
2
+ SHA256:
3
+ metadata.gz: a2668e81feb94e20b496c164c3685971953f0144819230cb81b0d42e00b6d3ab
4
+ data.tar.gz: 3dd86e1588cd35816828a6657c14d118cfceede16bb47c462e5e40f6902a8ec0
5
5
  SHA512:
6
- metadata.gz: 8fbf388b7903dedf9b430f5f132182f8ed31ce941de76fd08fd1990dd0a8bd2304e2b96ea099942c7faaa67c562e54b6d268c0d3040bb89405f9a4b41ae600f9
7
- data.tar.gz: bdc49d7d07bf6bafa4a6454d9ff7e2ca292e196891a6f86463b6ed0bfaff370abf576211a5106fe9591285bd4cb286366d1d7de313ce6e7f295ad937e88fa7dd
6
+ metadata.gz: 9e608871ec7e7170ba105ffd70e54f55d543cee670d4fa744f1b0b64f185a995d6fa394ebd79c91de4a30889b906156f54d6d163e16370f8e02094fb6f540730
7
+ data.tar.gz: 40652890a32acdbb4f25fe434b531d406ad356f32917066e2ca068e22878b35e35f8039dd3cdbec5863ac7b91f5024ac15d1adaafaadc5eb421f2f72a0c0a94e
data/.gitignore CHANGED
@@ -1,18 +1,11 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
9
  coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
18
- .rvmrc
10
+ .ruby-version
11
+ Gemfile.lock
data/.travis.yml CHANGED
@@ -1,7 +1,20 @@
1
+ cache: bundler
1
2
  language: ruby
3
+
2
4
  rvm:
3
- - 2.0.0
4
- - 2.1.8
5
- - 2.2.4
6
- - 2.3.0
7
- - ruby-head
5
+ - 2.6.6
6
+ - 2.7.2
7
+ - 3.0.0
8
+
9
+ before_install:
10
+ - gem install bundler -v 2.0.2
11
+
12
+ gemfile:
13
+ - gemfiles/rails_5.2.gemfile
14
+ - gemfiles/rails_6.0.gemfile
15
+ - gemfiles/rails_6.1.gemfile
16
+
17
+ matrix:
18
+ allow_failures:
19
+ - gemfile: gemfiles/rails_5.2.gemfile
20
+ rvm: 3.0.0
data/Appraisals ADDED
@@ -0,0 +1,11 @@
1
+ appraise 'rails-5.2' do
2
+ gem 'rails', '~> 5.2.0'
3
+ end
4
+
5
+ appraise 'rails-6.0' do
6
+ gem 'rails', '~> 6.0.0'
7
+ end
8
+
9
+ appraise 'rails-6.1' do
10
+ gem 'rails', '~> 6.1.0'
11
+ end
data/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # CHANGELOG
2
2
 
3
+ ### Version 0.5.2
4
+ * Add rails version supported 6.
5
+ * Minimum ruby version supported 2.6.X.
6
+ * Remove support for ruby 2.4.X.
7
+ * Avoid defining new methods in exporter.
8
+ * Update code base to use bundler 2.X.X.
9
+
10
+ ### Version 0.5.1
11
+ * Add rails version supported 5.2.X.
12
+ * Minimum ruby version supported 2.5.0.
13
+
14
+ ### Version 0.5.0
15
+ * Rails versions supported 4.X.X and 5.X.X.
16
+ * Minimum ruby version supported 2.2.2.
17
+
18
+ ### Version 0.4.1
19
+ * Improvements: Moving dependecies to .gemspec
20
+
3
21
  ### Version 0.4.0
4
22
  * Ruby ~> 1.9.3 is not longer supported.
5
23
  * activemodel version dependency >= 4.0.
@@ -8,10 +26,10 @@
8
26
  * Adding support to export a single resource.
9
27
 
10
28
  ### Version 0.3.1
11
- * Fixing errors with rails 4.2+.
29
+ * Fixing errors with rails 4.2.X.
12
30
 
13
31
  ### Version 0.3.0
14
- * Adding support to rails 4.2+.
32
+ * Adding support to rails 4.2.X.
15
33
 
16
34
  ### Version 0.2.0
17
35
  * Using I18n translations in file headers.
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at alejandrodevs@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile CHANGED
@@ -1,6 +1,2 @@
1
1
  source 'https://rubygems.org'
2
-
3
2
  gemspec
4
- gem 'coveralls', require: false
5
- gem 'rails'
6
- gem 'sqlite3'
data/LICENSE.txt CHANGED
@@ -1,22 +1,21 @@
1
- Copyright (c) 2014 Alejandro Gutiérrez
1
+ The MIT License (MIT)
2
2
 
3
- MIT License
3
+ Copyright (c) 2019 Alejandro Gutiérrez
4
4
 
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
12
11
 
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
15
14
 
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -1,22 +1,28 @@
1
1
  # ActiveModel::Exporters
2
- [![Build Status](https://travis-ci.org/alejandrodevs/active_model_exporters.png?branch=master)](https://travis-ci.org/alejandrodevs/active_model_exporters) [![Coverage Status](https://coveralls.io/repos/github/alejandrodevs/active_model_exporters/badge.svg?branch=master)](https://coveralls.io/github/alejandrodevs/active_model_exporters?branch=master)
2
+ [![Build Status](https://travis-ci.com/alejandrodevs/active_model_exporters.svg?branch=master)](https://travis-ci.org/alejandrodevs/active_model_exporters) [![Coverage Status](https://coveralls.io/repos/github/alejandrodevs/active_model_exporters/badge.svg?branch=master)](https://coveralls.io/github/alejandrodevs/active_model_exporters?branch=master)
3
3
 
4
- `ActiveModel::Exporters` aims to provide an easy way to export
5
- collections of `ActiveModel` or `ActiveRecord` objects.
6
- It's based on object-oriented development and inspired on
7
- [active_model_serializers](https://github.com/rails-api/active_model_serializers).
4
+ `ActiveModel::Exporters` aims to provide an easy way to export collections of `ActiveModel` or `ActiveRecord` objects. It's based on object-oriented development and inspired on [active_model_serializers](https://github.com/rails-api/active_model_serializers).
8
5
 
9
6
  ## Installation
10
7
 
11
- Add this line to your Gemfile:
8
+ Add this line to your application's Gemfile:
9
+
12
10
  ```ruby
13
11
  gem 'active_model_exporters'
14
12
  ```
15
- Run the bundle command to install it.
16
13
 
17
- ## Getting started
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install active_model_exporters
21
+
22
+ ## Usage
18
23
 
19
24
  Generate an exporter in `app/exporters/post_exporter.rb`:
25
+
20
26
  ```ruby
21
27
  class PostExporter < ActiveModel::Exporter
22
28
  attributes :id, :title, :content
@@ -24,6 +30,7 @@ end
24
30
  ```
25
31
 
26
32
  In your controller:
33
+
27
34
  ```ruby
28
35
  class PostsController < ApplicationController
29
36
  def index
@@ -38,26 +45,34 @@ end
38
45
  ```
39
46
 
40
47
  ### Custom exporter
48
+
41
49
  To specify a custom exporter for each object, you can do the next in your controller:
50
+
42
51
  ```ruby
43
52
  render csv: @posts, exporter: OtherPostExporter
44
53
  ```
45
54
 
46
55
  ### Custom filename
56
+
47
57
  By default filename is the pluralized collection type. Example: `posts.xls`.
48
58
  To specify another, you can do the next:
59
+
49
60
  ```ruby
50
61
  render xls: @posts, filename: 'super_posts.xls'
51
62
  ```
52
63
 
53
64
  ### Custom encode format
65
+
54
66
  By default encode format is `iso-8859-1`. You can change it doing the next:
67
+
55
68
  ```ruby
56
69
  render csv: @posts, encode: 'UTF-8'
57
70
  ```
58
71
 
59
72
  ### Computed properties
73
+
60
74
  As `ActiveModel::Serializers` does, you can access the object being exported as `object`.
75
+
61
76
  ```ruby
62
77
  class UserExporter < ActiveModel::Exporter
63
78
  attributes :first_name, :last_name, :full_name
@@ -71,7 +86,9 @@ end
71
86
  ### Exporter scope
72
87
 
73
88
  #### 1. Default scope
89
+
74
90
  As `ActiveModel::Serializers` does, you can access to the current user via `scope`.
91
+
75
92
  ```ruby
76
93
  class UserExporter < ActiveModel::Exporter
77
94
  attributes :name, :email
@@ -83,13 +100,17 @@ end
83
100
  ```
84
101
 
85
102
  #### 2. Explicit scope
103
+
86
104
  In your controller, include the scope option:
105
+
87
106
  ```ruby
88
107
  render csv: @posts, scope: current_admin
89
108
  ```
90
109
 
91
110
  #### 3. Calling exportation_scope
111
+
92
112
  In your controller, set the exportation scope:
113
+
93
114
  ```ruby
94
115
  class PostsController < ApplicationController
95
116
  exportation_scope :current_admin
@@ -101,8 +122,9 @@ end
101
122
  ```
102
123
 
103
124
  ### Filter attributes
104
- As `ActiveModel::Serializers` does, you can reject some attributes
105
- according to your business rules:
125
+
126
+ As `ActiveModel::Serializers` does, you can reject some attributes according to your business rules:
127
+
106
128
  ```ruby
107
129
  class UserExporter < ActiveModel::Exporter
108
130
  attributes :name, :email, :address
@@ -116,13 +138,27 @@ class UserExporter < ActiveModel::Exporter
116
138
  end
117
139
  end
118
140
  ```
141
+
119
142
  Rejected attributes will be blank in the downloaded file.
120
143
 
121
144
  ### Headers
145
+
122
146
  `ActiveModel::Exporters` uses I18n translations in file headers.
123
147
 
148
+ ## Development
149
+
150
+ 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.
151
+
152
+ 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).
153
+
124
154
  ## Contributing
125
155
 
126
- New feature or code refactoring? Submit a pull request that implements it. Don't forget to write your tests and include a CHANGELOG with your updates.
156
+ Bug reports and pull requests are welcome on GitHub at https://github.com/alejandrodevs/active_model_exporters. 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.
157
+
158
+ ## License
159
+
160
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
161
+
162
+ ## Code of Conduct
127
163
 
128
- Thank you!
164
+ Everyone interacting in the ActiveModel::Exporters project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/alejandrodevs/active_model_exporters/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile CHANGED
@@ -1,9 +1,10 @@
1
1
  require 'bundler/gem_tasks'
2
2
  require 'rake/testtask'
3
3
 
4
- Rake::TestTask.new do |t|
4
+ Rake::TestTask.new(:test) do |t|
5
5
  t.libs << 'test'
6
- t.pattern = 'test/**/*_test.rb'
6
+ t.libs << 'lib'
7
+ t.test_files = FileList['test/**/*_test.rb']
7
8
  end
8
9
 
9
10
  task default: :test
@@ -1,6 +1,5 @@
1
- # coding: utf-8
2
-
3
- $:.unshift File.expand_path("../lib", __FILE__)
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require 'active_model/exporter/version'
5
4
 
6
5
  Gem::Specification.new do |spec|
@@ -8,17 +7,30 @@ Gem::Specification.new do |spec|
8
7
  spec.version = ActiveModel::Exporter::VERSION
9
8
  spec.authors = ['Alejandro Gutiérrez']
10
9
  spec.email = ['alejandrodevs@gmail.com']
11
- spec.description = 'A simple way to export data in Rails.'
12
10
  spec.summary = 'A simple way to export data in Rails.'
11
+ spec.description = 'A simple way to export data in Rails.'
13
12
  spec.homepage = 'https://github.com/alejandrodevs/active_model_exporters'
14
13
  spec.license = 'MIT'
15
14
 
16
- spec.files = `git ls-files`.split($/)
17
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
15
+ spec.metadata['homepage_uri'] = spec.homepage
16
+ spec.metadata['source_code_uri'] = spec.homepage
17
+ spec.metadata['changelog_uri'] = "#{spec.homepage}/blob/master/LICENSE.txt"
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ end
24
+ spec.bindir = 'exe'
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
26
  spec.require_paths = ['lib']
19
27
 
20
- spec.required_ruby_version = '>= 2.0.0'
28
+ spec.add_development_dependency 'rake', '~> 13.0'
29
+ spec.add_development_dependency 'bundler', '~> 2.2'
30
+ spec.add_development_dependency 'sqlite3', '~> 1.4'
31
+ spec.add_development_dependency 'minitest', '~> 5.14'
32
+ spec.add_development_dependency 'appraisal', '~> 2.4'
33
+ spec.add_development_dependency 'coveralls', '~> 0.8'
21
34
 
22
- spec.add_dependency 'activemodel', '>= 4.0'
23
- spec.add_development_dependency 'rails', '>= 4.0'
35
+ spec.add_dependency 'rails', '>= 5.2'
24
36
  end