active_storage_base64 1.0.0 → 1.2.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
2
  SHA1:
3
- metadata.gz: 44449a327924040d5967252b57bcc967f07b568e
4
- data.tar.gz: cb42213139e6db2b629104f72e392965e6e659d3
3
+ metadata.gz: 8467d90fdcbc07a9672049395a208a4a10d32391
4
+ data.tar.gz: 961a61666f9a74011ab564875c013ec6461e402e
5
5
  SHA512:
6
- metadata.gz: 24750064b2e4a13f316b732fb6423ce0b8fb7f7d10cf862b7e0bab7aafa584096fb930c5d1900160511063a240613cc3eca4f3e1fbbe180ef53db092f7ab955d
7
- data.tar.gz: 80cdc756a28d7014a278e503696d1f5276f90faf14a499a4937759308c5ad0c566cb2b56e244564dff78ed09e5e44ec706e0a4ab5e8216f941dc9b7c62de5060
6
+ metadata.gz: af92f7ff33c42eba9cc2fdecabd06c36adb967a672df2b77e4bc047ff2dd65d907bd9d6de08f801cb5c84e0f94cbe32fd4bd61b5db8ed9ed3e063ea49ebf7c9e
7
+ data.tar.gz: f5638f30bf22ff55b917f2ed816711d3c351c9c5810953b2b1d035486860f075af389ab6f72fcdf2db2bc2ab91bd3ab3308471678ef7b670743dfc3d4a17cd8b
data/README.md CHANGED
@@ -59,7 +59,7 @@ class User < ActiveRecord::Base
59
59
  end
60
60
  ```
61
61
 
62
- on your controller you could do something like this:
62
+ on your controller you could do any of the following:
63
63
  ```ruby
64
64
  class UsersController < ApplicationController
65
65
  def create
@@ -69,17 +69,16 @@ class UsersController < ApplicationController
69
69
  private
70
70
 
71
71
  def user_params
72
- params.require(:user).permit(avatar: [:data], :username, :email)
72
+ params.require(:user).permit(avatar: :data, :username, :email)
73
73
  end
74
74
  end
75
75
  ```
76
76
 
77
- Or you could also do:
78
77
  ```ruby
79
78
  class UsersController < ApplicationController
80
79
  def create
81
80
  user = User.create(user_params)
82
- user.avatar.attach(params[:avatar])
81
+ user.avatar.attach(data: params[:avatar]) # params[:avatar] => 'data:image/png;base64,[base64 data]'
83
82
  end
84
83
 
85
84
  private
@@ -90,12 +89,30 @@ class UsersController < ApplicationController
90
89
  end
91
90
  ```
92
91
 
93
- Here's another option to achieve the same:
94
92
  ```ruby
95
93
  class UsersController < ApplicationController
96
94
  def create
97
95
  user = User.create(user_params)
98
- user.avatar = { data: params[:avatar] }
96
+ user.avatar.attach(avatar_params) # avatar_params => { data: 'data:image/png;base64,[base64 data]' }
97
+ end
98
+
99
+ private
100
+
101
+ def user_params
102
+ params.require(:user).permit(:username, :email)
103
+ end
104
+
105
+ def avatar_params
106
+ params.require(:avatar).permit(:data)
107
+ end
108
+ end
109
+ ```
110
+
111
+ ```ruby
112
+ class UsersController < ApplicationController
113
+ def create
114
+ user = User.create(user_params)
115
+ user.avatar = { data: params[:avatar] } # params[:avatar] => 'data:image/png;base64,[base64 data]'
99
116
  user.save
100
117
  end
101
118
 
@@ -115,7 +132,7 @@ Check the following example:
115
132
  class UsersController < ApplicationController
116
133
  def create
117
134
  user = User.create(user_params)
118
- user.avatar.attach(data: params[:avatar], filename: 'your_filename', content_type: 'content/type', identify: 'false')
135
+ user.avatar.attach(data: params[:avatar], filename: 'your_filename', content_type: 'content/type', identify: 'false') # params[:avatar] => 'data:image/png;base64,[base64 data]'
119
136
  end
120
137
 
121
138
  private
@@ -4,6 +4,8 @@ module ActiveStorageSupport
4
4
  module_function
5
5
 
6
6
  def attachment_from_data(attachment)
7
+ attachment = attachment.to_h if attachment.is_a?(ActionController::Parameters)
8
+
7
9
  if attachment.is_a?(Hash)
8
10
  attachment = attachment.symbolize_keys
9
11
  fill_attachment_data(attachment, attachment.delete(:data))
@@ -5,12 +5,14 @@ module ActiveStorageSupport
5
5
  module SupportForBase64
6
6
  extend ActiveSupport::Concern
7
7
  class_methods do
8
- def has_one_base64_attached(name, dependent: :purge_later)
9
- has_one_attached name, dependent: dependent
8
+ def has_one_base64_attached(name, dependent: :purge_later, service: nil, strict_loading: false)
9
+ has_one_attached name, dependent: dependent, service: service, strict_loading: strict_loading
10
10
 
11
11
  generated_association_methods.class_eval <<-CODE, __FILE__, __LINE__ + 1
12
+ # frozen_string_literal: true
12
13
  def #{name}
13
- @active_storage_attached_#{name} ||= ActiveStorageSupport::Base64One.new("#{name}", self)
14
+ @active_storage_attached ||= {}
15
+ @active_storage_attached[:#{name}] ||= ActiveStorageSupport::Base64One.new("#{name}", self)
14
16
  end
15
17
  def #{name}=(attachable)
16
18
  attachment_changes["#{name}"] =
@@ -25,12 +27,14 @@ module ActiveStorageSupport
25
27
  CODE
26
28
  end
27
29
 
28
- def has_many_base64_attached(name, dependent: :purge_later)
29
- has_many_attached name, dependent: dependent
30
+ def has_many_base64_attached(name, dependent: :purge_later, service: nil, strict_loading: false)
31
+ has_many_attached name, dependent: dependent, service: service, strict_loading: strict_loading
30
32
 
31
33
  generated_association_methods.class_eval <<-CODE, __FILE__, __LINE__ + 1
34
+ # frozen_string_literal: true
32
35
  def #{name}
33
- @active_storage_attached_#{name} ||= ActiveStorageSupport::Base64Many.new("#{name}", self)
36
+ @active_storage_attached ||= {}
37
+ @active_storage_attached[:#{name}] ||= ActiveStorageSupport::Base64Many.new("#{name}", self)
34
38
  end
35
39
  def #{name}=(attachables)
36
40
  if ActiveStorage.replace_on_assign_to_many
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: 1.0.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ricardo Cortio
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-23 00:00:00.000000000 Z
11
+ date: 2020-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '6.0'
19
+ version: '6.1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '6.0'
26
+ version: '6.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: pry-rails
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 4.8.1
47
+ version: 5.5.0
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 4.8.1
54
+ version: 5.5.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec-rails
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -84,16 +84,16 @@ dependencies:
84
84
  name: simplecov
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: 0.17.1
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0'
96
+ version: 0.17.1
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: sqlite3
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -114,19 +114,8 @@ executables: []
114
114
  extensions: []
115
115
  extra_rdoc_files: []
116
116
  files:
117
- - ".gitignore"
118
- - ".rspec"
119
- - ".rubocop.yml"
120
- - ".travis.yml"
121
- - CODE_OF_CONDUCT.md
122
- - CONTRIBUTING.md
123
- - Gemfile
124
117
  - LICENSE.txt
125
118
  - README.md
126
- - Rakefile
127
- - active_storage_base64.gemspec
128
- - config.reek
129
- - gemfiles/RailsHeadGemfile
130
119
  - lib/active_storage_base64.rb
131
120
  - lib/active_storage_support/base64_attach.rb
132
121
  - lib/active_storage_support/base64_many.rb
@@ -144,7 +133,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
144
133
  requirements:
145
134
  - - ">="
146
135
  - !ruby/object:Gem::Version
147
- version: 2.2.2
136
+ version: 2.5.0
148
137
  required_rubygems_version: !ruby/object:Gem::Requirement
149
138
  requirements:
150
139
  - - ">="
data/.gitignore DELETED
@@ -1,4 +0,0 @@
1
- Gemfile.lock
2
- spec/dummy/log
3
- spec/dummy/db/**.sqlite3
4
- /coverage/
data/.rspec DELETED
@@ -1 +0,0 @@
1
- --format d
data/.rubocop.yml DELETED
@@ -1,69 +0,0 @@
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
- ExcludedMethods:
23
- - class_methods
24
-
25
- Metrics/BlockNesting:
26
- Max: 4
27
-
28
- Metrics/ClassLength:
29
- CountComments: false # count full line comments?
30
- Max: 200
31
-
32
- # Avoid complex methods.
33
- Metrics/CyclomaticComplexity:
34
- Max: 7
35
-
36
- Metrics/MethodLength:
37
- CountComments: false # count full line comments?
38
- Max: 24
39
-
40
- Metrics/ModuleLength:
41
- CountComments: false # count full line comments?
42
- Max: 200
43
-
44
- Metrics/LineLength:
45
- Max: 100
46
- # To make it possible to copy or click on URIs in the code, we allow lines
47
- # containing a URI to be longer than Max.
48
- AllowURI: true
49
- URISchemes:
50
- - http
51
- - https
52
- Exclude:
53
- - spec/dummy/db/schema.rb
54
-
55
- Metrics/ParameterLists:
56
- Max: 5
57
- CountKeywordArgs: true
58
-
59
- Metrics/PerceivedComplexity:
60
- Max: 12
61
-
62
- Style/FrozenStringLiteralComment:
63
- Enabled: false
64
-
65
- Style/ModuleFunction:
66
- Enabled: false
67
-
68
- Naming/PredicateName:
69
- Enabled: false
data/.travis.yml DELETED
@@ -1,31 +0,0 @@
1
- language: ruby
2
-
3
- before_install:
4
- - gem install bundler -v "~> 1.17"
5
-
6
- rvm:
7
- - 2.5.0
8
- - 2.6.0
9
- - ruby-head
10
-
11
- matrix:
12
- allow_failures:
13
- - rvm: ruby-head
14
-
15
- sudo: false
16
-
17
- env:
18
- global:
19
- - CC_TEST_REPORTER_ID=7196b4aa257fde33f24463218af32db6a6efd23d9148204822f757fa614a093e
20
-
21
- before_script:
22
- - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
23
- - chmod +x ./cc-test-reporter
24
- - ./cc-test-reporter before-build
25
-
26
- script:
27
- - bundle exec rake code_analysis
28
- - bundle exec rspec
29
-
30
- after_script:
31
- - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
data/CODE_OF_CONDUCT.md DELETED
@@ -1,78 +0,0 @@
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 DELETED
@@ -1,42 +0,0 @@
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 DELETED
@@ -1,3 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
data/Rakefile DELETED
@@ -1,4 +0,0 @@
1
- task :code_analysis do
2
- sh 'bundle exec rubocop lib spec'
3
- sh 'bundle exec reek lib'
4
- end
@@ -1,29 +0,0 @@
1
- Gem::Specification.new do |s|
2
- s.name = 'active_storage_base64'
3
- s.version = '1.0.0'
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', '~> 6.0'
21
-
22
- # Development dependencies
23
- s.add_development_dependency 'pry-rails', '~> 0.3.6'
24
- s.add_development_dependency 'reek', '~> 4.8.1'
25
- s.add_development_dependency 'rspec-rails', '~> 3.8.0'
26
- s.add_development_dependency 'rubocop', '~> 0.56.0'
27
- s.add_development_dependency 'simplecov'
28
- s.add_development_dependency 'sqlite3', '1.4.1'
29
- end
data/config.reek DELETED
@@ -1,81 +0,0 @@
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
- DataClump:
13
- enabled: true
14
- max_copies: 2
15
- min_clump_size: 2
16
- DuplicateMethodCall:
17
- enabled: true
18
- exclude: []
19
- max_calls: 1
20
- allow_calls: []
21
- FeatureEnvy:
22
- enabled: true
23
- exclude: []
24
- InstanceVariableAssumption:
25
- enabled: false
26
- IrresponsibleModule:
27
- enabled: false
28
- exclude: []
29
- LongParameterList:
30
- enabled: true
31
- exclude: []
32
- max_params: 4
33
- overrides:
34
- initialize:
35
- max_params: 5
36
- LongYieldList:
37
- enabled: true
38
- exclude: []
39
- max_params: 3
40
- NestedIterators:
41
- enabled: true
42
- exclude: []
43
- max_allowed_nesting: 2
44
- ignore_iterators: []
45
- NilCheck:
46
- enabled: false
47
- exclude: []
48
- PrimaDonnaMethod:
49
- enabled: false
50
- exclude: []
51
- RepeatedConditional:
52
- enabled: true
53
- exclude: []
54
- max_ifs: 3
55
- TooManyInstanceVariables:
56
- enabled: true
57
- exclude: []
58
- max_instance_variables: 9
59
- TooManyMethods:
60
- enabled: true
61
- exclude: []
62
- max_methods: 25
63
- TooManyStatements:
64
- enabled: true
65
- exclude: []
66
- max_statements: 12
67
- UncommunicativeMethodName:
68
- enabled: false
69
- UncommunicativeModuleName:
70
- enabled: false
71
- UncommunicativeParameterName:
72
- enabled: false
73
- UncommunicativeVariableName:
74
- enabled: false
75
- UnusedParameters:
76
- enabled: true
77
- exclude: []
78
- UnusedPrivateMethod:
79
- enabled: false
80
- UtilityFunction:
81
- enabled: false
@@ -1,13 +0,0 @@
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