paperclip-globalize3 2.3.0 → 3.0.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: 291f0de36becd34c190f413e9a6fd1e428032a28
4
- data.tar.gz: 35ae076aa0f3d691c4d4739ceb276b10b8612248
3
+ metadata.gz: ab76787f50ea1fc671e86d2a88514adaac3d15ba
4
+ data.tar.gz: 8831d59aaa2b52741be85a7561b2bce68a9c8a77
5
5
  SHA512:
6
- metadata.gz: 8cb9228fae277bcc58ce1985fee261419ae9361183caa9b9e83e5f3552898eeb38a5c142abdf25cc408c93017394a2341dc440483bdf1aa58cd0cf607f903ceb
7
- data.tar.gz: af489e4213a7dc6512fb624a52dad35d5a664c3355284df8c9fd29407c7b837415bdbc5235f481f6fa71a65fbd3f57b5ba0e88c7226a14cea7cd61db5261e3ac
6
+ metadata.gz: 8d5c3cd80b86f608871bfdf9d1ff6d69e6b987b37d133c65106fdc2c65f0789dd72c2878cb2f9d16b822b2c488d1c93c5d0b1cbcad834a2ef9a34df5f52fba8c
7
+ data.tar.gz: d466da7201f9421f8f3f4263e7557aab42cb4d06c26fb4ca66158b7875826ca6d84b6c1212cda9af525167ae511b5d80639c0377643face3132177b4da2b901e
data/.gitignore CHANGED
@@ -13,6 +13,7 @@ lib/bundler/man
13
13
  pkg
14
14
  rdoc
15
15
  spec/reports
16
+ spec/examples.txt
16
17
  test/tmp
17
18
  test/version_tmp
18
19
  tmp
data/.rubocop.yml ADDED
@@ -0,0 +1,44 @@
1
+ require: rubocop-rspec
2
+
3
+ inherit_from: .rubocop_todo.yml
4
+
5
+ AllCops:
6
+ Include:
7
+ - 'Appraisals'
8
+ - '**/*.gemspec'
9
+ - '**/*.rake'
10
+ - '**/*.gemfile'
11
+ - '**/Gemfile'
12
+ - '**/Rakefile'
13
+ - '**/Capfile'
14
+ TargetRubyVersion: 2.2
15
+
16
+ Layout/AlignHash:
17
+ EnforcedColonStyle: 'table'
18
+
19
+ Layout/AlignParameters:
20
+ EnforcedStyle: 'with_fixed_indentation'
21
+
22
+ Layout/DotPosition:
23
+ EnforcedStyle: 'trailing'
24
+
25
+ Layout/SpaceInsideHashLiteralBraces:
26
+ EnforcedStyle: 'no_space'
27
+
28
+ Metrics/AbcSize:
29
+ Exclude:
30
+ - 'lib/paperclip/globalize3/attachment.rb'
31
+
32
+ Metrics/MethodLength:
33
+ Exclude:
34
+ - 'lib/paperclip/globalize3/attachment.rb'
35
+
36
+ Metrics/LineLength:
37
+ Max: 120
38
+
39
+ Naming/VariableNumber:
40
+ EnforcedStyle: 'snake_case'
41
+
42
+ Style/EmptyElse:
43
+ Exclude:
44
+ - 'lib/paperclip/globalize3/attachment.rb'
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,35 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2018-02-07 16:16:24 +0100 using RuboCop version 0.52.1.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 3
10
+ # Configuration parameters: CountComments, ExcludedMethods.
11
+ Metrics/BlockLength:
12
+ Max: 152
13
+
14
+ # Offense count: 2
15
+ # Configuration parameters: .
16
+ # SupportedStyles: have_received, receive
17
+ RSpec/MessageSpies:
18
+ EnforcedStyle: receive
19
+
20
+ # Offense count: 1
21
+ # Configuration parameters: AggregateFailuresByDefault.
22
+ RSpec/MultipleExpectations:
23
+ Max: 2
24
+
25
+ # Offense count: 1
26
+ # Configuration parameters: Max.
27
+ RSpec/NestedGroups:
28
+ Exclude:
29
+ - 'spec/paperclip/globalize3/attachment_spec.rb'
30
+
31
+ # Offense count: 1
32
+ # Configuration parameters: IgnoreSymbolicNames.
33
+ RSpec/VerifiedDoubles:
34
+ Exclude:
35
+ - 'spec/paperclip/globalize3/attachment_spec.rb'
data/.travis.yml CHANGED
@@ -1,12 +1,18 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.0.0
4
- - 2.1.5
5
- - 2.2.0
6
- before_install: gem install bundler -v '~> 1.7.13'
3
+ - 2.2.2
4
+ - 2.3.5
5
+ - 2.4.3
6
+ before_install: gem install bundler -v '>= 1.13'
7
7
  script: "bundle exec rake spec"
8
8
  gemfile:
9
- - gemfiles/rails_4.0_pc_4_1.gemfile
10
- - gemfiles/rails_4.0_pc_4_2.gemfile
11
- - gemfiles/rails_4.2_pc_4_1.gemfile
12
9
  - gemfiles/rails_4.2_pc_4_2.gemfile
10
+ - gemfiles/rails_4.2_pc_4_3.gemfile
11
+ - gemfiles/rails_4.2_pc_5_0.gemfile
12
+ - gemfiles/rails_4.2_pc_5_2.gemfile
13
+ - gemfiles/rails_5.0_pc_4_2.gemfile
14
+ - gemfiles/rails_5.0_pc_5_0.gemfile
15
+ - gemfiles/rails_5.0_pc_5_2.gemfile
16
+ - gemfiles/rails_5.1_pc_4_2.gemfile
17
+ - gemfiles/rails_5.1_pc_5_0.gemfile
18
+ - gemfiles/rails_5.1_pc_5_2.gemfile
data/.yardopts ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ --output-dir doc
3
+ --no-private
4
+ --readme README.md
5
+ - CHANGELOG.md
data/Appraisals CHANGED
@@ -1,23 +1,55 @@
1
- # Rails 4.0
2
-
3
- appraise 'rails-4.0-pc-4-1' do
4
- gem 'rails', '~> 4.0.0'
5
- gem 'paperclip', '~> 4.1.0'
6
- end
1
+ # Rails 4.2
7
2
 
8
- appraise 'rails-4.0-pc-4-2' do
9
- gem 'rails', '~> 4.0.0'
3
+ appraise 'rails-4.2-pc-4-2' do
4
+ gem 'rails', '~> 4.2.0'
10
5
  gem 'paperclip', '~> 4.2.0'
11
6
  end
12
7
 
13
- # Rails 4.2
8
+ appraise 'rails-4.2-pc-4-3' do
9
+ gem 'rails', '~> 4.2.0'
10
+ gem 'paperclip', '~> 4.3.0'
11
+ end
14
12
 
15
- appraise 'rails-4.2-pc-4-1' do
13
+ appraise 'rails-4.2-pc-5-0' do
16
14
  gem 'rails', '~> 4.2.0'
17
- gem 'paperclip', '~> 4.1.0'
15
+ gem 'paperclip', '~> 5.0.0'
18
16
  end
19
17
 
20
- appraise 'rails-4.2-pc-4-2' do
18
+ appraise 'rails-4.2-pc-5-2' do
21
19
  gem 'rails', '~> 4.2.0'
20
+ gem 'paperclip', '~> 5.2.0'
21
+ end
22
+
23
+ # Rails 5.0
24
+
25
+ appraise 'rails-5.0-pc-4-2' do
26
+ gem 'rails', '~> 5.0.0'
22
27
  gem 'paperclip', '~> 4.2.0'
23
28
  end
29
+
30
+ appraise 'rails-5.0-pc-5-0' do
31
+ gem 'rails', '~> 5.0.0'
32
+ gem 'paperclip', '~> 5.0.0'
33
+ end
34
+
35
+ appraise 'rails-5.0-pc-5-2' do
36
+ gem 'rails', '~> 5.0.0'
37
+ gem 'paperclip', '~> 5.2.0'
38
+ end
39
+
40
+ # Rails 5.1
41
+
42
+ appraise 'rails-5.1-pc-4-2' do
43
+ gem 'rails', '~> 5.1.0'
44
+ gem 'paperclip', '~> 4.2.0'
45
+ end
46
+
47
+ appraise 'rails-5.1-pc-5-0' do
48
+ gem 'rails', '~> 5.1.0'
49
+ gem 'paperclip', '~> 5.0.0'
50
+ end
51
+
52
+ appraise 'rails-5.1-pc-5-2' do
53
+ gem 'rails', '~> 5.1.0'
54
+ gem 'paperclip', '~> 5.2.0'
55
+ end
data/CHANGELOG.md ADDED
@@ -0,0 +1,31 @@
1
+ # (unreleased)
2
+
3
+ * Bugfixes
4
+ * (none)
5
+ * Enhancements
6
+ * (none)
7
+
8
+ # 3.0.0 (2018-02-07)
9
+
10
+ * Breaking changes
11
+ * Drop support for ruby < 2.2.2
12
+ * Drop support for rails < 4.2
13
+ * Drop support for paperclip < 4.2
14
+ * Drop support for globalize < 5.0
15
+ * Move paperclip-globalize3.rb to paperclip/globalize3.rb
16
+ (if you manually require 'paperclip-globalize3', change it to 'paperclip/globalize3')
17
+ * Bugfixes
18
+ * (none)
19
+ * Enhancements
20
+ * Support ruby 2.3 and 2.4
21
+ * Test with paperclip 4.3
22
+ * Support paperclip 5.0/5.1/5.2
23
+ * Support rails 5.1
24
+ * Internal / development
25
+ * Bump dependencies
26
+ * Add rubocop
27
+ * Add yard
28
+
29
+ # 2.x and before
30
+
31
+ (Sorry, there was no CHANGELOG before, so please refer to github commits.)
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Paperclip::Globalize3
2
2
 
3
- [![Build Status](https://travis-ci.org/emjot/paperclip-globalize3.png?branch=2.x-stable)](https://travis-ci.org/emjot/paperclip-globalize3)
3
+ [![Build Status](https://travis-ci.org/emjot/paperclip-globalize3.png?branch=master)](https://travis-ci.org/emjot/paperclip-globalize3)
4
4
 
5
5
  Use locale-specific attachments in your Rails app with [paperclip](https://github.com/thoughtbot/paperclip) and
6
6
  [globalize](https://github.com/globalize/globalize).
@@ -11,17 +11,17 @@ Note that this implementation patches some methods in the `Paperclip::Attachment
11
11
 
12
12
  ## Compatibility
13
13
 
14
- This is a maintenance branch for previous (2.x) versions.
14
+ * paperclip 4.2 - 5.2
15
+ * globalize 5.x
16
+ * Rails 4.2/5.0/5.1
15
17
 
16
- Here, paperclip 4.1/4.2 and globalize 4.0/5.0 and rails 4.x are supported.
17
-
18
- For paperclip 3.x with globalize3 support please use the 1.x versions of this gem.
18
+ For support of previous paperclip / globalize / rails versions please refer to the 2.x versions of this gem.
19
19
 
20
20
  ## Installation
21
21
 
22
22
  Add this line to your application's Gemfile:
23
23
 
24
- gem 'paperclip-globalize3', '~> 2.3'
24
+ gem 'paperclip-globalize3'
25
25
 
26
26
  And then execute:
27
27
 
@@ -29,7 +29,7 @@ And then execute:
29
29
 
30
30
  Or install it yourself as:
31
31
 
32
- $ gem install paperclip-globalize3 -v '~> 2.3'
32
+ $ gem install paperclip-globalize3
33
33
 
34
34
  ## Usage
35
35
 
data/Rakefile CHANGED
@@ -5,14 +5,14 @@ require 'rspec/core/rake_task'
5
5
  require 'wwtd/tasks'
6
6
 
7
7
  desc 'Default: run all tests with all supported versions'
8
- task :default => :all
8
+ task default: :all
9
9
 
10
10
  desc 'Run tests with all supported Rails versions.'
11
- task :all => ["appraisal:install"] do
11
+ task all: ['appraisal:install'] do
12
12
  exec('rake appraisal spec')
13
13
  end
14
14
 
15
- task :local => "wwtd:local" # run all gemfiles with local ruby
15
+ task local: 'wwtd:local' # run all gemfiles with local ruby
16
16
 
17
17
  desc 'Run all tests'
18
18
  RSpec::Core::RakeTask.new('spec') do |t|
@@ -1,8 +1,8 @@
1
1
  # This file was generated by Appraisal
2
2
 
3
- source "https://rubygems.org"
3
+ source 'https://rubygems.org'
4
4
 
5
- gem "rails", "~> 4.2.0"
6
- gem "paperclip", "~> 4.2.0"
5
+ gem 'rails', '~> 4.2.0'
6
+ gem 'paperclip', '~> 4.2.0'
7
7
 
8
- gemspec :path=>"../"
8
+ gemspec path: '../'
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gem 'rails', '~> 4.2.0'
6
+ gem 'paperclip', '~> 4.3.0'
7
+
8
+ gemspec path: '../'
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gem 'rails', '~> 4.2.0'
6
+ gem 'paperclip', '~> 5.0.0'
7
+
8
+ gemspec path: '../'
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gem 'rails', '~> 4.2.0'
6
+ gem 'paperclip', '~> 5.2.0'
7
+
8
+ gemspec path: '../'
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gem 'rails', '~> 5.0.0'
6
+ gem 'paperclip', '~> 4.2.0'
7
+
8
+ gemspec path: '../'
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gem 'rails', '~> 5.0.0'
6
+ gem 'paperclip', '~> 5.0.0'
7
+
8
+ gemspec path: '../'
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gem 'rails', '~> 5.0.0'
6
+ gem 'paperclip', '~> 5.2.0'
7
+
8
+ gemspec path: '../'
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gem 'rails', '~> 5.1.0'
6
+ gem 'paperclip', '~> 4.2.0'
7
+
8
+ gemspec path: '../'
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gem 'rails', '~> 5.1.0'
6
+ gem 'paperclip', '~> 5.0.0'
7
+
8
+ gemspec path: '../'
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gem 'rails', '~> 5.1.0'
6
+ gem 'paperclip', '~> 5.2.0'
7
+
8
+ gemspec path: '../'
@@ -1,143 +1,98 @@
1
1
  module Paperclip
2
2
  module Globalize3
3
+ # Prepend to the paperclip `Attachment` class to transparently read and write
4
+ # your attachments in context of the current locale using globalize.
5
+ #
6
+ # E.g. `my_model.my_attachment` returns a different attachment when your
7
+ # current locale is 'en' compared to when your current locale is 'de'.
8
+ #
9
+ # Requires a :locale interpolation for your paperclip attachment(s) and the
10
+ # respective columns to be translated.
3
11
  module Attachment
12
+ def assign(uploaded_file)
13
+ @file =
14
+ if Paperclip::Attachment.default_options.key?(:adapter_options) # paperclip >= 5.2.0
15
+ Paperclip.io_adapters.for(uploaded_file, @options[:adapter_options])
16
+ else # paperclip < 5.2.0
17
+ Paperclip.io_adapters.for(uploaded_file)
18
+ end
19
+ ensure_required_accessors!
20
+ ensure_required_validations!
4
21
 
5
- def self.included(base)
6
- base.send :include, InstanceMethods
7
- base.send :alias_method_chain, :assign, :globalize3
8
- base.send :alias_method_chain, :clear, :globalize3
9
- base.send :alias_method_chain, :queue_all_for_delete, :globalize3
10
- base.send :alias_method_chain, :queue_some_for_delete, :globalize3
11
- end
12
-
13
- module InstanceMethods
14
- def assign_with_globalize3(uploaded_file)
15
- @file = Paperclip.io_adapters.for(uploaded_file)
16
- ensure_required_accessors!
17
- ensure_required_validations!
18
-
19
- if @file.assignment?
20
- clear(*only_process, :locales => Globalize.locale) # [paperclip-globalize3] only clear current locale
21
- if @file.nil?
22
- nil
23
- else
24
- assign_attributes
25
- post_process_file
26
- reset_file_if_original_reprocessed
27
- end
28
- else
22
+ if @file.assignment?
23
+ clear(*only_process, locales: Globalize.locale) # [paperclip-globalize3] only clear current locale
24
+ if @file.nil?
29
25
  nil
26
+ else
27
+ assign_attributes
28
+ post_process_file
29
+ reset_file_if_original_reprocessed
30
30
  end
31
+ else
32
+ nil
31
33
  end
34
+ end
32
35
 
33
- def clear_with_globalize3(*args)
34
- options = args.extract_options!
35
- styles_to_clear = args
36
- if styles_to_clear.any?
37
- queue_some_for_delete(*styles_to_clear, options)
38
- else
39
- queue_all_for_delete(options)
40
- @queued_for_write = {}
41
- @errors = {}
42
- end
36
+ def clear(*args)
37
+ options = args.extract_options!
38
+ styles_to_clear = args
39
+ if styles_to_clear.any?
40
+ queue_some_for_delete(*styles_to_clear, options)
41
+ else
42
+ queue_all_for_delete(options)
43
+ @queued_for_write = {}
44
+ @errors = {}
43
45
  end
46
+ end
44
47
 
45
- private
48
+ private
46
49
 
47
- def queue_all_for_delete_with_globalize3(options = {}) #:nodoc:
48
- with_locales_if_translated(options[:locales]) do
49
- queue_all_for_delete_without_globalize3
50
- end
50
+ def queue_all_for_delete(options = {}) #:nodoc:
51
+ with_locales_if_translated(options[:locales]) do
52
+ super()
51
53
  end
54
+ end
52
55
 
53
- def queue_some_for_delete_with_globalize3(*args)
54
- options = args.extract_options!
55
- styles = args
56
- with_locales_if_translated(options[:locales]) do
57
- queue_some_for_delete_without_globalize3(styles)
58
- end
56
+ def queue_some_for_delete(*args)
57
+ options = args.extract_options!
58
+ styles = args
59
+ with_locales_if_translated(options[:locales]) do
60
+ super(styles)
59
61
  end
62
+ end
60
63
 
61
- # If translated, execute the block for the given locales only (or for all translated locales if none are given).
62
- # If any locales are given, only those for which a translation exists are used.
63
- # If attachment is untranslated, simply execute the block.
64
- def with_locales_if_translated(with_locales = nil, &block)
65
- if instance.respond_to?(:translated_locales) && instance.translated?(:"#{name}_file_name")
66
- # TODO translated_locales are not present any more when this is called via destroy callback (unless 'translates' is defined AFTER 'has_attached_file' in the model class)
67
- with_locales =
68
- if with_locales.nil?
69
- [*instance.translated_locales]
70
- else
71
- [*with_locales] & instance.translated_locales
72
- end
73
- Globalize.with_locales(with_locales) { yield }
74
- else
75
- yield
76
- end
64
+ # Yields the given block in context of Globalize#with_locales, but handles these situations gracefully:
65
+ #
66
+ # * if it is not translated (=> then don't use Globalize)
67
+ # * if there are no locales given (=> then use all translated locales)
68
+ # * if there are `with_locales` requested for which there are no translations (=> then skip those)
69
+ #
70
+ # @param [Symbol, Array[Symbol], nil] with_locales only yield block for these translated locales
71
+ def with_locales_if_translated(with_locales = nil)
72
+ if translated?
73
+ locales = with_locales.nil? ? translated_locales : [*with_locales] & translated_locales
74
+ Globalize.with_locales(locales) { yield }
75
+ else
76
+ yield
77
77
  end
78
78
  end
79
79
 
80
- module Compatibility
81
- # The paperclip-globalize3 patches are based on paperclip 4.2 code;
82
- # this module needs to be included when trying to use with paperclip 4.1.
83
- module Paperclip41
84
- def assign_attributes
85
- @queued_for_write[:original] = @file
86
- assign_file_information
87
- assign_fingerprint(@file.fingerprint)
88
- assign_timestamps
89
- end
90
-
91
- def assign_file_information
92
- instance_write(:file_name, cleanup_filename(@file.original_filename))
93
- instance_write(:content_type, @file.content_type.to_s.strip)
94
- instance_write(:file_size, @file.size)
95
- end
96
-
97
- def assign_fingerprint(fingerprint)
98
- if instance_respond_to?(:fingerprint)
99
- instance_write(:fingerprint, fingerprint)
100
- end
101
- end
102
-
103
- def assign_timestamps
104
- if has_enabled_but_unset_created_at?
105
- instance_write(:created_at, Time.now)
106
- end
107
-
108
- instance_write(:updated_at, Time.now)
109
- end
110
-
111
- def post_process_file
112
- dirty!
113
-
114
- if post_processing
115
- post_process(*only_process)
116
- end
117
- end
80
+ # Whether both the model and the attachment are translated
81
+ def translated?
82
+ instance.respond_to?(:translated_locales) && instance.translated?(:"#{name}_file_name")
83
+ end
118
84
 
119
- def dirty!
120
- @dirty = true
121
- end
85
+ # Returns the locales for which there are translations for the model instance, if applicable
86
+ # (nil if the model or the attachment is not translated).
87
+ #
88
+ # @return [Array[Symbol], nil]
89
+ def translated_locales
90
+ return unless translated?
122
91
 
123
- def reset_file_if_original_reprocessed
124
- instance_write(:file_size, @queued_for_write[:original].size)
125
- assign_fingerprint(@queued_for_write[:original].fingerprint)
126
- reset_updater
127
- end
128
-
129
- def reset_updater
130
- if instance.respond_to?(updater)
131
- instance.send(updater)
132
- end
133
- end
134
-
135
- def updater
136
- :"#{name}_file_name_will_change!"
137
- end
138
- end
92
+ # TODO: translated_locales are not present any more when this is called via destroy callback
93
+ # (unless 'translates' is defined AFTER 'has_attached_file' in the model class)
94
+ instance.translated_locales
139
95
  end
140
-
141
96
  end
142
97
  end
143
98
  end
@@ -1,15 +1,12 @@
1
1
  module Paperclip
2
2
  module Globalize3
3
-
4
3
  # Like Bundler::GemHelper, but tags versions without the 'v' prefix (e.g. '1.0.0' instead of 'v1.0.0')
5
4
  class GemHelper < Bundler::GemHelper
6
-
7
5
  protected
8
6
 
9
7
  def version_tag
10
- "#{version}"
8
+ version.to_s
11
9
  end
12
-
13
10
  end
14
11
  end
15
12
  end
@@ -1,5 +1,5 @@
1
1
  module Paperclip
2
2
  module Globalize3
3
- VERSION = "2.3.0"
3
+ VERSION = '3.0.0'.freeze
4
4
  end
5
5
  end