active_storage_base64 1.0.0 → 1.1.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: b17bf224361116b0fe28122df341dc24e148255d
4
+ data.tar.gz: 9b4b5af7995be883632ce2151451a562bcd0eb83
5
5
  SHA512:
6
- metadata.gz: 24750064b2e4a13f316b732fb6423ce0b8fb7f7d10cf862b7e0bab7aafa584096fb930c5d1900160511063a240613cc3eca4f3e1fbbe180ef53db092f7ab955d
7
- data.tar.gz: 80cdc756a28d7014a278e503696d1f5276f90faf14a499a4937759308c5ad0c566cb2b56e244564dff78ed09e5e44ec706e0a4ab5e8216f941dc9b7c62de5060
6
+ metadata.gz: e5bc36b18b917e7a7963f0cb872d0b375c9ddb32c84479a0e3a6aaea6af3f982bb050335d1b462331e7ffcd6db258f40496f20d8319fefe382746b19d31dc6b5
7
+ data.tar.gz: d191c2cef8ee7052bf389323c70e214ef0d2696ce1a1dd7b98a767f0d3c5dbe14a0723229ac8275080980ddf3d1735137350d6bbbc1691582c1a0755bdd2d3ec
@@ -0,0 +1,127 @@
1
+ detectors:
2
+ Attribute:
3
+ enabled: false
4
+ exclude: []
5
+ BooleanParameter:
6
+ enabled: true
7
+ exclude: []
8
+ ClassVariable:
9
+ enabled: false
10
+ exclude: []
11
+ ControlParameter:
12
+ enabled: true
13
+ exclude: []
14
+ DataClump:
15
+ enabled: true
16
+ exclude: []
17
+ max_copies: 2
18
+ min_clump_size: 2
19
+ DuplicateMethodCall:
20
+ enabled: true
21
+ exclude: []
22
+ max_calls: 1
23
+ allow_calls: []
24
+ FeatureEnvy:
25
+ enabled: true
26
+ exclude: []
27
+ InstanceVariableAssumption:
28
+ enabled: false
29
+ IrresponsibleModule:
30
+ enabled: false
31
+ exclude: []
32
+ LongParameterList:
33
+ enabled: true
34
+ exclude: []
35
+ max_params: 4
36
+ overrides:
37
+ initialize:
38
+ max_params: 5
39
+ LongYieldList:
40
+ enabled: true
41
+ exclude: []
42
+ max_params: 3
43
+ ManualDispatch:
44
+ enabled: true
45
+ exclude: []
46
+ MissingSafeMethod:
47
+ enabled: false
48
+ exclude: []
49
+ ModuleInitialize:
50
+ enabled: true
51
+ exclude: []
52
+ NestedIterators:
53
+ enabled: true
54
+ exclude: []
55
+ max_allowed_nesting: 2
56
+ ignore_iterators: []
57
+ NilCheck:
58
+ enabled: false
59
+ exclude: []
60
+ RepeatedConditional:
61
+ enabled: true
62
+ exclude: []
63
+ max_ifs: 3
64
+ SubclassedFromCoreClass:
65
+ enabled: true
66
+ exclude: []
67
+ TooManyConstants:
68
+ enabled: true
69
+ exclude: []
70
+ max_constants: 5
71
+ TooManyInstanceVariables:
72
+ enabled: true
73
+ exclude: []
74
+ max_instance_variables: 9
75
+ TooManyMethods:
76
+ enabled: true
77
+ exclude: []
78
+ max_methods: 25
79
+ TooManyStatements:
80
+ enabled: true
81
+ exclude:
82
+ - initialize
83
+ max_statements: 12
84
+ UncommunicativeMethodName:
85
+ enabled: true
86
+ exclude:
87
+ - "ActiveStorageSupport::Base64Many#self.from_base64"
88
+ - "ActiveStorageSupport::Base64One#self.from_base64"
89
+ reject:
90
+ - "/^[a-z]$/"
91
+ - "/[0-9]$/"
92
+ - "/[A-Z]/"
93
+ accept: []
94
+ UncommunicativeModuleName:
95
+ enabled: true
96
+ exclude:
97
+ - "ActiveStorageSupport::SupportForBase64"
98
+ reject:
99
+ - "/^.$/"
100
+ - "/[0-9]$/"
101
+ accept:
102
+ - Inline::C
103
+ - "/V[0-9]/"
104
+ UncommunicativeParameterName:
105
+ enabled: true
106
+ exclude: []
107
+ reject:
108
+ - "/^.$/"
109
+ - "/[0-9]$/"
110
+ - "/[A-Z]/"
111
+ accept: []
112
+ UncommunicativeVariableName:
113
+ enabled: true
114
+ exclude: []
115
+ reject:
116
+ - "/^.$/"
117
+ - "/[0-9]$/"
118
+ - "/[A-Z]/"
119
+ accept:
120
+ - _
121
+ UnusedParameters:
122
+ enabled: true
123
+ exclude: []
124
+ UnusedPrivateMethod:
125
+ enabled: false
126
+ UtilityFunction:
127
+ enabled: false
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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'active_storage_base64'
3
- s.version = '1.0.0'
3
+ s.version = '1.1.0'
4
4
  s.summary = 'Base64 support for ActiveStorage'
5
5
  s.description = s.summary
6
6
 
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
21
21
 
22
22
  # Development dependencies
23
23
  s.add_development_dependency 'pry-rails', '~> 0.3.6'
24
- s.add_development_dependency 'reek', '~> 4.8.1'
24
+ s.add_development_dependency 'reek', '~> 5.5.0'
25
25
  s.add_development_dependency 'rspec-rails', '~> 3.8.0'
26
26
  s.add_development_dependency 'rubocop', '~> 0.56.0'
27
27
  s.add_development_dependency 'simplecov'
@@ -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))
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.1.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: 2019-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -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
@@ -115,6 +115,7 @@ extensions: []
115
115
  extra_rdoc_files: []
116
116
  files:
117
117
  - ".gitignore"
118
+ - ".reek.yml"
118
119
  - ".rspec"
119
120
  - ".rubocop.yml"
120
121
  - ".travis.yml"
@@ -125,7 +126,6 @@ files:
125
126
  - README.md
126
127
  - Rakefile
127
128
  - active_storage_base64.gemspec
128
- - config.reek
129
129
  - gemfiles/RailsHeadGemfile
130
130
  - lib/active_storage_base64.rb
131
131
  - lib/active_storage_support/base64_attach.rb
@@ -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