active_storage_base64 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.rspec +1 -0
- data/.rubocop.yml +67 -0
- data/.travis.yml +17 -0
- data/CODE_OF_CONDUCT.md +78 -0
- data/CONTRIBUTING.md +42 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +21 -0
- data/README.md +165 -0
- data/Rakefile +4 -0
- data/active_storage_base64.gemspec +28 -0
- data/config.reek +83 -0
- data/gemfiles/RailsHeadGemfile +13 -0
- data/lib/active_storage_support/base64_attach.rb +20 -0
- data/lib/active_storage_support/base64_many.rb +13 -0
- data/lib/active_storage_support/base64_one.rb +8 -0
- data/lib/active_storage_support/support_for_base64.rb +39 -0
- metadata +24 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36dfcca56fbad7ca9bb0d860b2d192d1ac6fd78b49e82e3056e271de47e52103
|
4
|
+
data.tar.gz: b9919fc691756b718216656cd8bf58e6a8a4b2c02f27946ba828caa854233161
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fbf1cf11a8b1decc8a12c5af113a75fc5ad17b9c8fd2b2190e4252f160bcdc6dc0790ed178b4b6d5230ba18730aef279c1e7e22239feb183c090f71b48b11287
|
7
|
+
data.tar.gz: ce40b3239c679243468cfcd93e45ae1d8b825a123bda0dcc5989a2ec3693fc286971f02feabbaf42cfe3ae1058d00caf4182686e02b9a71bfcb650df2e8fc1af
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--format d
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
Documentation:
|
2
|
+
Enabled: false
|
3
|
+
|
4
|
+
Layout/SpaceBeforeFirstArg:
|
5
|
+
Exclude:
|
6
|
+
|
7
|
+
Lint/AmbiguousBlockAssociation:
|
8
|
+
Exclude:
|
9
|
+
- spec/**/*
|
10
|
+
|
11
|
+
Metrics/AbcSize:
|
12
|
+
# The ABC size is a calculated magnitude, so this number can be an Integer or
|
13
|
+
# a Float.
|
14
|
+
Max: 15
|
15
|
+
|
16
|
+
Metrics/BlockLength:
|
17
|
+
CountComments: false # count full line comments?
|
18
|
+
Max: 25
|
19
|
+
Exclude:
|
20
|
+
- config/**/*
|
21
|
+
- spec/**/*
|
22
|
+
|
23
|
+
Metrics/BlockNesting:
|
24
|
+
Max: 4
|
25
|
+
|
26
|
+
Metrics/ClassLength:
|
27
|
+
CountComments: false # count full line comments?
|
28
|
+
Max: 200
|
29
|
+
|
30
|
+
# Avoid complex methods.
|
31
|
+
Metrics/CyclomaticComplexity:
|
32
|
+
Max: 7
|
33
|
+
|
34
|
+
Metrics/MethodLength:
|
35
|
+
CountComments: false # count full line comments?
|
36
|
+
Max: 24
|
37
|
+
|
38
|
+
Metrics/ModuleLength:
|
39
|
+
CountComments: false # count full line comments?
|
40
|
+
Max: 200
|
41
|
+
|
42
|
+
Metrics/LineLength:
|
43
|
+
Max: 100
|
44
|
+
# To make it possible to copy or click on URIs in the code, we allow lines
|
45
|
+
# containing a URI to be longer than Max.
|
46
|
+
AllowURI: true
|
47
|
+
URISchemes:
|
48
|
+
- http
|
49
|
+
- https
|
50
|
+
Exclude:
|
51
|
+
- spec/dummy/db/schema.rb
|
52
|
+
|
53
|
+
Metrics/ParameterLists:
|
54
|
+
Max: 5
|
55
|
+
CountKeywordArgs: true
|
56
|
+
|
57
|
+
Metrics/PerceivedComplexity:
|
58
|
+
Max: 12
|
59
|
+
|
60
|
+
Style/FrozenStringLiteralComment:
|
61
|
+
Enabled: false
|
62
|
+
|
63
|
+
Style/ModuleFunction:
|
64
|
+
Enabled: false
|
65
|
+
|
66
|
+
Naming/PredicateName:
|
67
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,78 @@
|
|
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, sex characteristics, gender identity and expression,
|
9
|
+
level of experience, education, socio-economic status, nationality, personal
|
10
|
+
appearance, race, religion, or sexual identity and orientation.
|
11
|
+
|
12
|
+
Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
|
18
|
+
* Using welcoming and inclusive language
|
19
|
+
* Being respectful of differing viewpoints and experiences
|
20
|
+
* Gracefully accepting constructive criticism
|
21
|
+
* Focusing on what is best for the community
|
22
|
+
* Showing empathy towards other community members
|
23
|
+
|
24
|
+
|
25
|
+
Examples of unacceptable behavior by participants include:
|
26
|
+
|
27
|
+
|
28
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
29
|
+
advances
|
30
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
31
|
+
* Public or private harassment
|
32
|
+
* Publishing others’ private information, such as a physical or electronic
|
33
|
+
address, without explicit permission
|
34
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
35
|
+
professional setting
|
36
|
+
|
37
|
+
|
38
|
+
Our Responsibilities
|
39
|
+
|
40
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
41
|
+
behavior and are expected to take appropriate and fair corrective action in
|
42
|
+
response to any instances of unacceptable behavior.
|
43
|
+
|
44
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
45
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
46
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
47
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
48
|
+
threatening, offensive, or harmful.
|
49
|
+
|
50
|
+
Scope
|
51
|
+
|
52
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
53
|
+
when an individual is representing the project or its community. Examples of
|
54
|
+
representing a project or community include using an official project e-mail
|
55
|
+
address, posting via an official social media account, or acting as an appointed
|
56
|
+
representative at an online or offline event. Representation of a project may be
|
57
|
+
further defined and clarified by project maintainers.
|
58
|
+
|
59
|
+
Enforcement
|
60
|
+
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
62
|
+
reported by contacting the project team at ricardo@rootstrap.com. All
|
63
|
+
complaints will be reviewed and investigated and will result in a response that
|
64
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
65
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
66
|
+
Further details of specific enforcement policies may be posted separately.
|
67
|
+
|
68
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
69
|
+
faith may face temporary or permanent repercussions as determined by other
|
70
|
+
members of the project’s leadership.
|
71
|
+
|
72
|
+
Attribution
|
73
|
+
|
74
|
+
This Code of Conduct is adapted from the Contributor Covenant, version 1.4,
|
75
|
+
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
|
76
|
+
|
77
|
+
For answers to common questions about this code of conduct, see
|
78
|
+
https://www.contributor-covenant.org/faq
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
## Contributing ##
|
2
|
+
|
3
|
+
You can contribute to this repo if you have an issue, found a bug or think there's some functionality required that would add value to the gem. To do so, please check if there's not already an [issue](https://github.com/rootstrap/active-storage-base64/issues) for that, if you find there's not, create a new one with as much detail as possible.
|
4
|
+
|
5
|
+
If you want to contribute with code as well, please follow the next steps:
|
6
|
+
|
7
|
+
1. Read, understand and agree to our [code of conduct](https://github.com/rootstrap/active-storage-base64/blob/master/CODE_OF_CONDUCT.md)
|
8
|
+
2. [Fork the repo](https://help.github.com/articles/about-forks/)
|
9
|
+
3. Clone the project into your machine:
|
10
|
+
`$ git clone git@github.com:[YOUR GITHUB USERNAME]/active-storage-base64.git`
|
11
|
+
4. Access the repo:
|
12
|
+
`$ cd active-storage-base64`
|
13
|
+
5. Create your feature/bugfix branch:
|
14
|
+
`$ git checkout -b your_new_feature`
|
15
|
+
or
|
16
|
+
`$ git checkout -b fix/your_fix` in case of a bug fix
|
17
|
+
(if your PR is to address an existing issue, it would be good to name the branch after the issue, for example: if you are trying to solve issue 182, then a good idea for the branch name would be `182_your_new_feature`)
|
18
|
+
6. Write tests for your changes (feature/bug)
|
19
|
+
7. Code your (feature/bugfix)
|
20
|
+
8. Run the code analysis tool by doing:
|
21
|
+
`$ rake code_analysis`
|
22
|
+
9. Run the tests:
|
23
|
+
`$ bundle exec rspec`
|
24
|
+
All tests must pass. If all tests (both code analysis and rspec) do pass, then you are ready to go to the next step:
|
25
|
+
10. Commit your changes:
|
26
|
+
`$ git commit -m 'Your feature or bugfix title'`
|
27
|
+
11. Push to the branch `$ git push origin your_new_feature`
|
28
|
+
12. Create a new [pull request](https://help.github.com/articles/creating-a-pull-request/)
|
29
|
+
|
30
|
+
Some helpful guides that will help you know how we work:
|
31
|
+
1. [Code review](https://github.com/rootstrap/tech-guides/tree/master/code-review)
|
32
|
+
2. [GIT workflow](https://github.com/rootstrap/tech-guides/tree/master/git)
|
33
|
+
3. [Ruby style guide](https://github.com/rootstrap/tech-guides/tree/master/ruby)
|
34
|
+
4. [Rails style guide](https://github.com/rootstrap/tech-guides/blob/master/ruby/rails.md)
|
35
|
+
5. [RSpec style guide](https://github.com/rootstrap/tech-guides/blob/master/ruby/rspec/README.md)
|
36
|
+
|
37
|
+
For more information or guides like the ones mentioned above, please check our [tech guides](https://github.com/rootstrap/tech-guides). Keep in mind that the more you know about these guides, the easier it will be for your code to get approved and merged.
|
38
|
+
|
39
|
+
Note: We work with one commit per pull request, so if you make your commit and realize you were missing something or want to add something more to it, don't create a new commit with the changes, but use `$ git commit --amend` instead. This same principle also applies for when changes are requested on an open pull request.
|
40
|
+
|
41
|
+
|
42
|
+
Thank you very much for your time and for considering helping in this project.
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2018 Rootstrap
|
4
|
+
|
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:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/rootstrap/active-storage-base64.svg?branch=master)](https://travis-ci.org/rootstrap/active-storage-base64)
|
2
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/0da0a0901cedd72aeb10/maintainability)](https://codeclimate.com/github/rootstrap/active-storage-base64/maintainability)
|
3
|
+
|
4
|
+
# ActiveStorageBase64
|
5
|
+
|
6
|
+
Gem used to add support for base64 images for Rails's ActiveStorage.
|
7
|
+
|
8
|
+
## Getting Started
|
9
|
+
|
10
|
+
In order to get the gem working on your project you just need to add the gem to your project like this:
|
11
|
+
```ruby
|
12
|
+
gem 'active-storage-base64'
|
13
|
+
```
|
14
|
+
|
15
|
+
### Prerequisites
|
16
|
+
|
17
|
+
The only two prerequisites for using this gem are having Rails version 5.2.0 or higher installed on your project and having ActiveStorage setup properly (for more information on how to do this, check this [Active Storage Overview](https://edgeguides.rubyonrails.org/active_storage_overview.html))
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
gem 'rails', '5.2.0'
|
21
|
+
```
|
22
|
+
|
23
|
+
### Installing
|
24
|
+
|
25
|
+
In order to use the gem's functionality, you'll need to include the module into your ActiveRecord inheriting class.
|
26
|
+
For example:
|
27
|
+
```ruby
|
28
|
+
class User < ActiveRecord::Base
|
29
|
+
include ActiveStorageSupport::SupportForBase64
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
Note:
|
34
|
+
We highly recomment using an alternative class that inherits from ActiveRecord and includes the module so instead of including the module for each of your classes, you make them inherit from this new class, check below:
|
35
|
+
```ruby
|
36
|
+
class ApplicationRecord < ActiveRecord::Base
|
37
|
+
include ActiveStorageSupport::SupportForBase64
|
38
|
+
end
|
39
|
+
|
40
|
+
class User < ApplicationRecord
|
41
|
+
has_one_base64_attached :avatar
|
42
|
+
end
|
43
|
+
```
|
44
|
+
|
45
|
+
After you have the module included in your class you'll be able to use the following two helper methods for working with base64 files:
|
46
|
+
When you need a single image attached:
|
47
|
+
```ruby
|
48
|
+
has_one_base64_attached
|
49
|
+
```
|
50
|
+
and when you need multiple files attached:
|
51
|
+
```ruby
|
52
|
+
has_many_base64_attached
|
53
|
+
```
|
54
|
+
These helpers will work just like the `has_one_attached` and `has_many_attached` helper methods from ActiveStorage.
|
55
|
+
|
56
|
+
A working example for this, assuming we have a model `User` with only an `avatar` attached would be:
|
57
|
+
```ruby
|
58
|
+
class User < ActiveRecord::Base
|
59
|
+
include ActiveStorageSupport::SupportForBase64
|
60
|
+
|
61
|
+
has_one_base64_attached :avatar
|
62
|
+
end
|
63
|
+
```
|
64
|
+
|
65
|
+
on your controller you could do something like this:
|
66
|
+
```ruby
|
67
|
+
class UsersController < ApplicationController
|
68
|
+
def create
|
69
|
+
user = User.create(user_params)
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def user_params
|
75
|
+
params.require(:user).permit(:avatar[data:], :username, :email)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
```
|
79
|
+
|
80
|
+
Or you could also do:
|
81
|
+
```ruby
|
82
|
+
class UsersController < ApplicationController
|
83
|
+
def create
|
84
|
+
user = User.create(user_params)
|
85
|
+
user.avatar.attach(params[:avatar])
|
86
|
+
end
|
87
|
+
|
88
|
+
private
|
89
|
+
|
90
|
+
def user_params
|
91
|
+
params.require(:user).permit(:username, :email)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
```
|
95
|
+
|
96
|
+
Here's another option to achieve the same:
|
97
|
+
```ruby
|
98
|
+
class UsersController < ApplicationController
|
99
|
+
def create
|
100
|
+
user = User.create(user_params)
|
101
|
+
user.avatar = params[:avatar]
|
102
|
+
end
|
103
|
+
|
104
|
+
private
|
105
|
+
|
106
|
+
def user_params
|
107
|
+
params.require(:user).permit(:username, :email)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
```
|
111
|
+
|
112
|
+
## Specifying a filename or content_type
|
113
|
+
|
114
|
+
If you are willing to add a specific filename to your attachment, or send in a specific content_type for your file, you can use `data:` to attach the base64 data and specify your `filename:`, `content_type:` and/or `identify:` hash keys.
|
115
|
+
Check the following example:
|
116
|
+
```ruby
|
117
|
+
class UsersController < ApplicationController
|
118
|
+
def create
|
119
|
+
user = User.create(user_params)
|
120
|
+
user.avatar.attach(data: params[:avatar], filename: 'your_filename', content_type: 'content/type', identify: 'false')
|
121
|
+
end
|
122
|
+
|
123
|
+
private
|
124
|
+
|
125
|
+
def user_params
|
126
|
+
params.require(:user).permit(:username, :email)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
```
|
130
|
+
Or, in case you want to have the avatar attached as soon as the user is created you can do:
|
131
|
+
```ruby
|
132
|
+
class UsersController < ApplicationController
|
133
|
+
def create
|
134
|
+
user = User.create(user_params)
|
135
|
+
end
|
136
|
+
|
137
|
+
private
|
138
|
+
|
139
|
+
def user_params
|
140
|
+
params.require(:user).permit(:username, :email, avatar:[:data,
|
141
|
+
:filename,
|
142
|
+
:content_type,
|
143
|
+
:identify])
|
144
|
+
end
|
145
|
+
end
|
146
|
+
```
|
147
|
+
|
148
|
+
For more information on how to work with ActiveStorage, please check the [Active Storage Overview](https://edgeguides.rubyonrails.org/active_storage_overview.html) mentioned above, all points in there apply to this gem as well.
|
149
|
+
|
150
|
+
## Contributing
|
151
|
+
|
152
|
+
Please read our [CONTRIBUTING](https://github.com/rootstrap/active-storage-base64/blob/master/CONTRIBUTING.md) and our [CODE_OF_CONDUCT](https://github.com/rootstrap/active-storage-base64/blob/master/CODE_OF_CONDUCT.md) files for details on our code of conduct, and the process for submitting pull requests to us.
|
153
|
+
|
154
|
+
## Author
|
155
|
+
|
156
|
+
*Ricardo Cortio*
|
157
|
+
|
158
|
+
## License
|
159
|
+
|
160
|
+
This project is licensed under the MIT License - see the [LICENSE](https://github.com/rootstrap/active-storage-base64/blob/master/LICENSE.txt) file for details
|
161
|
+
|
162
|
+
## Acknowledgments
|
163
|
+
|
164
|
+
Special thanks to the people who helped with guidance and ensuring code quality in this project:
|
165
|
+
*Santiago Bartesaghi, Santiago Vidal and Matias Mansilla.*
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'active_storage_base64'
|
3
|
+
s.version = '0.1.1'
|
4
|
+
s.summary = 'Base64 support for ActiveStorage'
|
5
|
+
s.description = s.summary
|
6
|
+
|
7
|
+
s.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
8
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
9
|
+
end
|
10
|
+
|
11
|
+
s.require_paths = ['lib']
|
12
|
+
s.authors = ['Ricardo Cortio']
|
13
|
+
s.license = 'MIT'
|
14
|
+
s.homepage = 'https://github.com/rootstrap/active-storage-base64'
|
15
|
+
s.email = 'ricardo@rootstrap.com'
|
16
|
+
|
17
|
+
s.required_ruby_version = ">= 2.2.2"
|
18
|
+
|
19
|
+
# Dependencies
|
20
|
+
s.add_dependency 'rails', '~> 5.2.0', '<= 5.2.2'
|
21
|
+
|
22
|
+
# Development dependencies
|
23
|
+
s.add_development_dependency 'rubocop', '~> 0.56.0'
|
24
|
+
s.add_development_dependency 'reek', '~> 4.8.1'
|
25
|
+
s.add_development_dependency 'rspec-rails', '~> 3.8.0'
|
26
|
+
s.add_development_dependency 'sqlite3', '1.3.13'
|
27
|
+
s.add_development_dependency 'pry-rails', '~> 0.3.6'
|
28
|
+
end
|
data/config.reek
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
Attribute:
|
2
|
+
enabled: false
|
3
|
+
exclude: []
|
4
|
+
BooleanParameter:
|
5
|
+
enabled: true
|
6
|
+
exclude: []
|
7
|
+
ClassVariable:
|
8
|
+
enabled: false
|
9
|
+
exclude: []
|
10
|
+
ControlParameter:
|
11
|
+
enabled: true
|
12
|
+
exclude: []
|
13
|
+
DataClump:
|
14
|
+
enabled: true
|
15
|
+
exclude: []
|
16
|
+
max_copies: 2
|
17
|
+
min_clump_size: 2
|
18
|
+
DuplicateMethodCall:
|
19
|
+
enabled: true
|
20
|
+
exclude: []
|
21
|
+
max_calls: 1
|
22
|
+
allow_calls: []
|
23
|
+
FeatureEnvy:
|
24
|
+
enabled: true
|
25
|
+
exclude: []
|
26
|
+
InstanceVariableAssumption:
|
27
|
+
enabled: false
|
28
|
+
IrresponsibleModule:
|
29
|
+
enabled: false
|
30
|
+
exclude: []
|
31
|
+
LongParameterList:
|
32
|
+
enabled: true
|
33
|
+
exclude: []
|
34
|
+
max_params: 4
|
35
|
+
overrides:
|
36
|
+
initialize:
|
37
|
+
max_params: 5
|
38
|
+
LongYieldList:
|
39
|
+
enabled: true
|
40
|
+
exclude: []
|
41
|
+
max_params: 3
|
42
|
+
NestedIterators:
|
43
|
+
enabled: true
|
44
|
+
exclude: []
|
45
|
+
max_allowed_nesting: 2
|
46
|
+
ignore_iterators: []
|
47
|
+
NilCheck:
|
48
|
+
enabled: false
|
49
|
+
exclude: []
|
50
|
+
PrimaDonnaMethod:
|
51
|
+
enabled: false
|
52
|
+
exclude: []
|
53
|
+
RepeatedConditional:
|
54
|
+
enabled: true
|
55
|
+
exclude: []
|
56
|
+
max_ifs: 3
|
57
|
+
TooManyInstanceVariables:
|
58
|
+
enabled: true
|
59
|
+
exclude: []
|
60
|
+
max_instance_variables: 9
|
61
|
+
TooManyMethods:
|
62
|
+
enabled: true
|
63
|
+
exclude: []
|
64
|
+
max_methods: 25
|
65
|
+
TooManyStatements:
|
66
|
+
enabled: true
|
67
|
+
exclude: []
|
68
|
+
max_statements: 12
|
69
|
+
UncommunicativeMethodName:
|
70
|
+
enabled: false
|
71
|
+
UncommunicativeModuleName:
|
72
|
+
enabled: false
|
73
|
+
UncommunicativeParameterName:
|
74
|
+
enabled: false
|
75
|
+
UncommunicativeVariableName:
|
76
|
+
enabled: false
|
77
|
+
UnusedParameters:
|
78
|
+
enabled: true
|
79
|
+
exclude: []
|
80
|
+
UnusedPrivateMethod:
|
81
|
+
enabled: false
|
82
|
+
UtilityFunction:
|
83
|
+
enabled: false
|
@@ -0,0 +1,13 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
4
|
+
|
5
|
+
gem "rails", github: "rails/rails", branch: "master", require: false
|
6
|
+
|
7
|
+
group :test do
|
8
|
+
gem 'rubocop', '~> 0.56.0'
|
9
|
+
gem 'reek', '~> 4.8.1'
|
10
|
+
gem 'rspec-rails', '~> 3.8.0'
|
11
|
+
gem 'sqlite3', '1.3.13'
|
12
|
+
gem 'pry-rails', '~> 0.3.6'
|
13
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# Helper method to decode a base64 file and create a StringIO file
|
2
|
+
module ActiveStorageSupport
|
3
|
+
module Base64Attach
|
4
|
+
module_function
|
5
|
+
|
6
|
+
def attachment_from_data(attachment)
|
7
|
+
if attachment.is_a?(Hash)
|
8
|
+
base64_data = attachment.delete(:data)
|
9
|
+
if base64_data.try(:is_a?, String) && base64_data =~ /^data:(.*?);(.*?),(.*)$/
|
10
|
+
|
11
|
+
attachment[:io] = StringIO.new(Base64.decode64(Regexp.last_match(3)))
|
12
|
+
attachment[:content_type] = Regexp.last_match(1) unless attachment[:content_type]
|
13
|
+
attachment[:filename] = Time.current.to_i.to_s unless attachment[:filename]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
attachment
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module ActiveStorageSupport
|
2
|
+
class Base64Many < ActiveStorage::Attached::Many
|
3
|
+
def attach(*attachables)
|
4
|
+
super base64_attachments(attachables)
|
5
|
+
end
|
6
|
+
|
7
|
+
def base64_attachments(attachments)
|
8
|
+
attachments.flatten.map do |attachment|
|
9
|
+
ActiveStorageSupport::Base64Attach.attachment_from_data(attachment)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
require 'active_storage/attached'
|
3
|
+
|
4
|
+
module ActiveStorageSupport
|
5
|
+
module SupportForBase64
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
class_methods do
|
8
|
+
def has_one_base64_attached(name, dependent: :purge_later)
|
9
|
+
has_one_attached name, dependent: dependent
|
10
|
+
|
11
|
+
class_eval <<-CODE, __FILE__, __LINE__ + 1
|
12
|
+
def #{name}
|
13
|
+
@active_storage_attached_#{name} ||=
|
14
|
+
ActiveStorageSupport::Base64One.new("#{name}", self, dependent: #{dependent == :purge_later ? ':purge_later' : 'false'})
|
15
|
+
end
|
16
|
+
|
17
|
+
def #{name}=(data)
|
18
|
+
#{name}.attach(data)
|
19
|
+
end
|
20
|
+
CODE
|
21
|
+
end
|
22
|
+
|
23
|
+
def has_many_base64_attached(name, dependent: :purge_later)
|
24
|
+
has_many_attached name, dependent: dependent
|
25
|
+
|
26
|
+
class_eval <<-CODE, __FILE__, __LINE__ + 1
|
27
|
+
def #{name}
|
28
|
+
@active_storage_attached_#{name} ||=
|
29
|
+
ActiveStorageSupport::Base64Many.new("#{name}", self, dependent: #{dependent == :purge_later ? ':purge_later' : 'false'})
|
30
|
+
end
|
31
|
+
|
32
|
+
def #{name}=(attachables)
|
33
|
+
#{name}.attach(attachables)
|
34
|
+
end
|
35
|
+
CODE
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_storage_base64
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Ricardo Cortio
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -100,14 +100,31 @@ dependencies:
|
|
100
100
|
- - "~>"
|
101
101
|
- !ruby/object:Gem::Version
|
102
102
|
version: 0.3.6
|
103
|
-
description:
|
104
|
-
email:
|
103
|
+
description: Base64 support for ActiveStorage
|
104
|
+
email: ricardo@rootstrap.com
|
105
105
|
executables: []
|
106
106
|
extensions: []
|
107
107
|
extra_rdoc_files: []
|
108
108
|
files:
|
109
|
+
- ".gitignore"
|
110
|
+
- ".rspec"
|
111
|
+
- ".rubocop.yml"
|
112
|
+
- ".travis.yml"
|
113
|
+
- CODE_OF_CONDUCT.md
|
114
|
+
- CONTRIBUTING.md
|
115
|
+
- Gemfile
|
116
|
+
- LICENSE.txt
|
117
|
+
- README.md
|
118
|
+
- Rakefile
|
119
|
+
- active_storage_base64.gemspec
|
120
|
+
- config.reek
|
121
|
+
- gemfiles/RailsHeadGemfile
|
109
122
|
- lib/active_storage_base64.rb
|
110
|
-
|
123
|
+
- lib/active_storage_support/base64_attach.rb
|
124
|
+
- lib/active_storage_support/base64_many.rb
|
125
|
+
- lib/active_storage_support/base64_one.rb
|
126
|
+
- lib/active_storage_support/support_for_base64.rb
|
127
|
+
homepage: https://github.com/rootstrap/active-storage-base64
|
111
128
|
licenses:
|
112
129
|
- MIT
|
113
130
|
metadata: {}
|
@@ -130,5 +147,5 @@ rubyforge_project:
|
|
130
147
|
rubygems_version: 2.7.7
|
131
148
|
signing_key:
|
132
149
|
specification_version: 4
|
133
|
-
summary:
|
150
|
+
summary: Base64 support for ActiveStorage
|
134
151
|
test_files: []
|