carrierwave-blitline 0.1.0 → 0.2.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
- SHA1:
3
- metadata.gz: bcdab1946c051e221bdf9f7327168fa69d69a0ef
4
- data.tar.gz: d8a451c3dba65f7e20090e7aa1479404d521781f
2
+ SHA256:
3
+ metadata.gz: 7321893581e7f320dd4f97a0b68d57d7e9047863887e6a1c91fae9159ba391f2
4
+ data.tar.gz: 68c2ea79350ed4d47e06a1477a1bd48b5d11123bb3eb3ff73b8866ccde94c359
5
5
  SHA512:
6
- metadata.gz: 0f1ea11ece56e432a29ba8e2dac504453a23c8f24c2081d0e4be48d158166e984907dc3dfee535ca57c4a12ca1475a73179bc76476e341e0c3a9270778f7a979
7
- data.tar.gz: e278d95e4367a0df37580083ec3a76d8534a55aa504ce3ed2a4af5d720e18c5ea7be28cb3af71bfab6c93fee566db54f47f7d46a5f0a9a517bf88fa63b315f49
6
+ metadata.gz: 9ed4f4c07b32a58f894fa5fc45cf4641ef6d15f00e3177e83936e2840283df57b82218690aff79206033d6329dd155c7514f67f1e0e06c83bcc08049d8b26917
7
+ data.tar.gz: db9adcef477a9711f7920d7003315c561803162a82284dc2f7b9a78126a5f3543e103b7b2c96c7246cf797aae625b30e8c2ed12acee74d84f01940de5dfe8cbd
@@ -0,0 +1,112 @@
1
+ # Ruby CircleCI 2.0 configuration file
2
+ #
3
+ # Check https://circleci.com/docs/2.0/language-ruby/ for more details
4
+ #
5
+ version: 2
6
+ jobs:
7
+ build:
8
+ environment:
9
+ CC_TEST_REPORTER_ID: 6f037067f424fa130712bb6a48398f25de184f86997b11990abbde61f2b07d7a
10
+
11
+ docker:
12
+ # specify the version you desire here
13
+ - image: circleci/ruby:2.5
14
+
15
+ working_directory: ~/carrierwave-blitline
16
+
17
+ steps:
18
+ - checkout
19
+
20
+ # Download and cache dependencies
21
+ - restore_cache:
22
+ keys:
23
+ - v1-dependencies-{{ checksum "Gemfile.lock" }}
24
+ # fallback to using the latest cache if no exact match is found
25
+ - v1-dependencies-
26
+
27
+ - run:
28
+ name: install dependencies
29
+ command: |
30
+ bundle install --jobs=4 --retry=3 --path vendor/bundle
31
+
32
+ - run:
33
+ name: Download CodeClimate
34
+ command: curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
35
+
36
+ - run:
37
+ name: "Change Permissions on CodeClimate"
38
+ command: chmod +x ./cc-test-reporter
39
+
40
+ - save_cache:
41
+ paths:
42
+ - ./vendor/bundle
43
+ key: v1-dependencies-{{ checksum "Gemfile.lock" }}
44
+
45
+ - run:
46
+ name: "Prepare CC test reporter"
47
+ command: ./cc-test-reporter before-build
48
+
49
+ # run tests!
50
+ - run:
51
+ name: Run Rspec
52
+ command: |
53
+ mkdir /tmp/test-results
54
+ TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
55
+
56
+ bundle exec rspec --format progress \
57
+ --format RspecJunitFormatter \
58
+ --out /tmp/test-results/rspec.xml \
59
+ --format progress \
60
+ $TEST_FILES
61
+
62
+ - run:
63
+ name: "Report CodeClimate"
64
+ command: ./cc-test-reporter after-build --exit-code 0
65
+
66
+ # collect reports
67
+ - store_test_results:
68
+ path: /tmp/test-results
69
+ - store_artifacts:
70
+ path: /tmp/test-results
71
+ destination: test-results
72
+ audit:
73
+ docker:
74
+ # specify the version you desire here
75
+ - image: circleci/ruby:2.5
76
+
77
+ working_directory: ~/carrierwave-blitline
78
+
79
+ steps:
80
+ - checkout
81
+
82
+ # Download and cache dependencies
83
+ - restore_cache:
84
+ keys:
85
+ - v1-dependencies-{{ checksum "Gemfile.lock" }}
86
+ # fallback to using the latest cache if no exact match is found
87
+ - v1-dependencies-
88
+
89
+ - run:
90
+ name: install dependencies
91
+ command: |
92
+ bundle install --jobs=4 --retry=3 --path vendor/bundle
93
+
94
+ - save_cache:
95
+ paths:
96
+ - ./vendor/bundle
97
+ key: v1-dependencies-{{ checksum "Gemfile.lock" }}
98
+
99
+ - run:
100
+ name: Bunder Audit
101
+ command: gem install bundle-audit && bundle-audit check --update
102
+
103
+ - run:
104
+ name: Code Style Check
105
+ command: rubocop lib --display-style-guide -c ./.rubocop.yml
106
+
107
+ workflows:
108
+ version: 2
109
+ build_and_audit:
110
+ jobs:
111
+ - build
112
+ - audit
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,60 @@
1
+ inherit_gem:
2
+
3
+ AllCops:
4
+ UseCache: true
5
+ DisplayCopNames: true
6
+ DisplayStyleGuide: true
7
+ TargetRubyVersion: 2.4
8
+ # Include:
9
+ Exclude:
10
+ - 'Gemfile'
11
+ - 'db/**/*'
12
+ - 'config/**/*'
13
+ - 'script/**/*'
14
+ - '**/Rakefile'
15
+ - '**/config.ru'
16
+
17
+ StringLiterals:
18
+ Enabled: false
19
+
20
+ Layout/EmptyLinesAroundClassBody:
21
+ Enabled: false
22
+
23
+ Layout/EmptyLines:
24
+ Enabled: false
25
+
26
+ Layout/EmptyLinesAroundBlockBody:
27
+ Exclude:
28
+ - 'spec/**/*'
29
+
30
+ Style/FrozenStringLiteralComment:
31
+ Enabled: false
32
+
33
+ Style/EmptyMethod:
34
+ Enabled: false
35
+
36
+ Rails:
37
+ Enabled: false
38
+
39
+ Metrics/LineLength:
40
+ Max: 90
41
+
42
+ Metrics/MethodLength:
43
+ Max: 20
44
+
45
+ Metrics/AbcSize:
46
+ Enabled: false
47
+
48
+ Lint/AmbiguousBlockAssociation:
49
+ Exclude:
50
+ - 'spec/**/*'
51
+
52
+ Metrics/BlockLength:
53
+ Exclude:
54
+ - 'spec/**/*'
55
+
56
+ Layout/ExtraSpacing:
57
+ Enabled: false
58
+
59
+ Layout/SpaceAroundOperators:
60
+ Enabled: false
data/README.md CHANGED
@@ -1,3 +1,12 @@
1
+ [![Latest Version](https://img.shields.io/gem/v/carrierwave-blitline.svg)](https://rubygems.org/gems/carrierwave-blitline)
2
+ [![CircleCI](https://circleci.com/gh/KatanaCode/carrierwave-blitline.svg?style=svg)](https://circleci.com/gh/KatanaCode/carrierwave-blitline)
3
+ [![Downloads](https://img.shields.io/github/downloads/katanacode/carrierwave-blitline/total.svg)](https://img.shields.io/github/downloads/katanacode/carrierwave-blitline/total.svg)
4
+ [![Maintainability](https://api.codeclimate.com/v1/badges/fdd8cffc25d6002a68df/maintainability)](https://codeclimate.com/github/KatanaCode/carrierwave-blitline/maintainability)
5
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/fdd8cffc25d6002a68df/test_coverage)](https://codeclimate.com/github/KatanaCode/carrierwave-blitline/test_coverage)
6
+
7
+
8
+ ---
9
+
1
10
  # Carrierwave::Blitline
2
11
 
3
12
  This gem is still under construction but it basically works in its current form.
@@ -5,7 +5,7 @@ require 'carrierwave/blitline/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "carrierwave-blitline"
8
- spec.version = Carrierwave::Blitline::VERSION
8
+ spec.version = CarrierWave::Blitline::VERSION
9
9
  spec.authors = ["Bodacious"]
10
10
  spec.email = ["team@katanacode.com"]
11
11
 
@@ -20,7 +20,11 @@ Gem::Specification.new do |spec|
20
20
  spec.require_paths = ["lib"]
21
21
 
22
22
  spec.add_dependency "blitline", "~> 2.8"
23
-
23
+ spec.add_dependency "activesupport", ">= 3.0.0", "<6.0.0"
24
24
  spec.add_development_dependency "bundler", "~> 1.13"
25
25
  spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec"
27
+ spec.add_development_dependency "rspec_junit_formatter"
28
+ spec.add_development_dependency "simplecov"
29
+ spec.add_development_dependency "rubocop"
26
30
  end
@@ -1,11 +1,13 @@
1
- # From the Blitline gem
2
1
  module CarrierWave
2
+ # Extend the behaviour of CarrierWave to support Blitline services
3
3
  module Blitline
4
+ # frozen_string_literal: true
4
5
 
6
+ # From the Blitline gem
5
7
  require "blitline"
6
-
8
+ require "active_support/core_ext/module/delegation"
9
+ require "active_support/concern"
7
10
  require "carrierwave/blitline/version"
8
- require "carrierwave/blitline/class_methods"
9
11
  require "carrierwave/blitline/image_version"
10
12
  require "carrierwave/blitline/function"
11
13
  require "carrierwave/blitline/image_version_function_presenter"
@@ -19,6 +21,9 @@ module CarrierWave
19
21
  # Blitline API version
20
22
  BLITLINE_VERSION = 1.21
21
23
 
24
+ ##
25
+ #
26
+ UNIQUE_IDENTIFIER_TEMPLATE = "%<app_name>_%<rails_env>_%<token>".freeze
22
27
 
23
28
  # Extends the including class with ClassMethods, add an after_store callback
24
29
  # and includes ImageMagick if required.
@@ -49,15 +54,16 @@ module CarrierWave
49
54
  # Blitline gem.
50
55
  #
51
56
  # file - not used within the method, but required for the callback to function
52
- def rip_process_images(file)
57
+ def rip_process_images(_file)
53
58
  return unless rip_can_begin_processing?
54
59
  Rails.logger.tagged("Blitline") { |l| l.debug(job_hash.to_json) }
55
60
  blitline_service.add_job_via_hash(job_hash)
56
61
  begin
57
62
  blitline_service.post_jobs
58
- rescue => e
63
+ rescue StandardError => e
59
64
  Rails.logger.tagged("Blitline") do |logger|
60
- logger.error "ERROR: Blitline processing error for #{model.class.name}"
65
+ logger.error format("ERROR: Blitline processing error for %<class>\n%<message>",
66
+ class: model.class.name, message: e.message)
61
67
  end
62
68
  end
63
69
  end
@@ -74,9 +80,9 @@ module CarrierWave
74
80
 
75
81
  # Returns a Hash for each function included in the Blitline API post
76
82
  def functions
77
- blitline_image_versions.map { |version|
83
+ blitline_image_versions.map do |version|
78
84
  ImageVersionFunctionPresenter.new(version, self).to_hash
79
- }
85
+ end
80
86
  end
81
87
 
82
88
  # sends a request to Blitline to re-process themain image and all versions
@@ -92,17 +98,19 @@ module CarrierWave
92
98
  #
93
99
  # Returns a boolean
94
100
  def rip_can_begin_processing?
95
- process_via_blitline? and not self.class.name.include? "::"
101
+ process_via_blitline? && (!self.class.name.include? "::")
96
102
  end
97
103
 
98
104
  def filename
99
- if file
100
- "#{model.class.to_s.underscore}.#{file.extension}"
101
- end
105
+ "#{model.class.to_s.underscore}.#{file.extension}" if file
102
106
  end
103
107
 
104
108
  def unique_identifier
105
- @unique_identifier ||= "#{Rails.application.class.name}_#{Rails.env}_#{SecureRandom.base64(10)}"
109
+ @unique_identifier ||= begin
110
+ format(UNIQUE_IDENTIFIER_TEMPLATE, app_name: Rails.application.class.name,
111
+ rails_env: Rails.env,
112
+ token: SecureRandom.base64(10))
113
+ end
106
114
  end
107
115
 
108
116
  def file_name_for_version(version)
@@ -117,18 +125,18 @@ module CarrierWave
117
125
  send("params_for_#{function_name}", *args)
118
126
  end
119
127
 
120
- def params_for_no_op(*args)
121
- return {}
128
+ def params_for_no_op(*_args)
129
+ {}
122
130
  end
123
131
 
124
132
  def params_for_resize_to_fill(*args)
125
133
  args.flatten!
126
- return { width: args.first, height: args.last }
134
+ { width: args.first, height: args.last }
127
135
  end
128
136
 
129
137
  def params_for_resize_to_fit(*args)
130
138
  args.flatten!
131
- return { width: args.first, height: args.last }
139
+ { width: args.first, height: args.last }
132
140
  end
133
141
 
134
142
 
@@ -139,5 +147,30 @@ module CarrierWave
139
147
  @blitline_service ||= ::Blitline.new
140
148
  end
141
149
 
150
+ # Class methods to extend your Uploader classes
151
+ module ClassMethods
152
+ def version(name, &block)
153
+ blitline_image_versions << ImageVersion.new(name, &block)
154
+ # If process_via_blitline? is true, we still want to register the version with
155
+ # the Uploader, but we don't want to define the conversions.
156
+ if process_via_blitline?
157
+ super(name) {}
158
+ else
159
+ super(name, &block)
160
+ end
161
+ end
162
+
163
+ def blitline_image_versions
164
+ @blitline_image_versions ||= [ImageVersion.new(nil)]
165
+ end
166
+
167
+ def process_via_blitline(value = true)
168
+ @process_via_blitline = value
169
+ end
170
+
171
+ def process_via_blitline?
172
+ defined?(@process_via_blitline) && @process_via_blitline == true
173
+ end
174
+ end
142
175
  end
143
176
  end
@@ -1,10 +1,7 @@
1
1
  module CarrierWave
2
2
  module Blitline
3
-
4
3
  # A Struct class for storing name and params for each function parameter.
5
4
  # See also: ImageVersionFunctionPresenter
6
- class Function < Struct.new(:name, :params)
7
- end
8
-
5
+ Function = Struct.new(:name, :params)
9
6
  end
10
- end
7
+ end
@@ -1,6 +1,5 @@
1
1
  module CarrierWave
2
2
  module Blitline
3
-
4
3
  # An instance of an ImageVersion for Blitline API.
5
4
  #
6
5
  # When the process() version is called in an Uploader class, we store the version
@@ -48,7 +47,7 @@ module CarrierWave
48
47
  if primary_function.nil?
49
48
  self.primary_function = function
50
49
  else
51
- self.secondary_functions << function
50
+ secondary_functions << function
52
51
  end
53
52
  end
54
53
 
@@ -65,7 +64,5 @@ module CarrierWave
65
64
  end
66
65
 
67
66
  end
68
-
69
67
  end
70
-
71
68
  end
@@ -1,6 +1,5 @@
1
1
  module CarrierWave
2
2
  module Blitline
3
-
4
3
  # A presenter class for converting an image version to a JSON param for the Blitline
5
4
  # API.
6
5
  class ImageVersionFunctionPresenter
@@ -51,32 +50,38 @@ module CarrierWave
51
50
  "s3_destination": {
52
51
  "bucket": {
53
52
  "name": ENV["S3_BUCKET_NAME"],
54
- "location": ENV["S3_BUCKET_REGION"],
53
+ "location": ENV["S3_BUCKET_REGION"]
55
54
  },
56
55
  "key": file_name_for_version(version)
57
56
  }
58
57
  },
59
- "functions": secondary_functions.map { |function|
60
- {
61
- "name": function.name,
62
- "params": params_for_function(function.name,function.params),
63
- "save": {
64
- "image_identifier": unique_identifier,
65
- "s3_destination": {
66
- "bucket": {
67
- "name": ENV["S3_BUCKET_NAME"],
68
- "location": ENV["S3_BUCKET_REGION"],
69
- },
70
- "key": file_name_for_version(version)
71
- }
58
+ "functions": functions_hashes
59
+ }
60
+ end
61
+
62
+
63
+ private
64
+
65
+
66
+ def functions_hashes
67
+ secondary_functions.map do |function|
68
+ {
69
+ "name": function.name,
70
+ "params": params_for_function(function.name, function.params),
71
+ "save": {
72
+ "image_identifier": unique_identifier,
73
+ "s3_destination": {
74
+ "bucket": {
75
+ "name": ENV["S3_BUCKET_NAME"],
76
+ "location": ENV["S3_BUCKET_REGION"]
77
+ },
78
+ "key": file_name_for_version(version)
72
79
  }
73
80
  }
74
81
  }
75
- }
82
+ end
76
83
  end
77
84
 
78
85
  end
79
-
80
86
  end
81
-
82
87
  end
@@ -1,5 +1,5 @@
1
- module Carrierwave
1
+ module CarrierWave
2
2
  module Blitline
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carrierwave-blitline
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bodacious
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-27 00:00:00.000000000 Z
11
+ date: 2018-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: blitline
@@ -24,6 +24,26 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 3.0.0
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: 6.0.0
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 3.0.0
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: 6.0.0
27
47
  - !ruby/object:Gem::Dependency
28
48
  name: bundler
29
49
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +72,62 @@ dependencies:
52
72
  - - "~>"
53
73
  - !ruby/object:Gem::Version
54
74
  version: '10.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rspec
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: rspec_junit_formatter
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: simplecov
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ - !ruby/object:Gem::Dependency
118
+ name: rubocop
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
55
131
  description: Integrates the carrierwave gem with Blitline image API. (Still under
56
132
  development)
57
133
  email:
@@ -60,7 +136,10 @@ executables: []
60
136
  extensions: []
61
137
  extra_rdoc_files: []
62
138
  files:
139
+ - ".circleci/config.yml"
63
140
  - ".gitignore"
141
+ - ".rspec"
142
+ - ".rubocop.yml"
64
143
  - Gemfile
65
144
  - LICENSE.txt
66
145
  - README.md
@@ -69,7 +148,6 @@ files:
69
148
  - bin/setup
70
149
  - carrierwave-blitline.gemspec
71
150
  - lib/carrierwave/blitline.rb
72
- - lib/carrierwave/blitline/class_methods.rb
73
151
  - lib/carrierwave/blitline/function.rb
74
152
  - lib/carrierwave/blitline/image_version.rb
75
153
  - lib/carrierwave/blitline/image_version_function_presenter.rb
@@ -94,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
172
  version: '0'
95
173
  requirements: []
96
174
  rubyforge_project:
97
- rubygems_version: 2.6.3
175
+ rubygems_version: 2.7.6
98
176
  signing_key:
99
177
  specification_version: 4
100
178
  summary: Integrates Blitline image processing with Carrierwave
@@ -1,33 +0,0 @@
1
- # Class methods to be included in Blitline module
2
- module CarrierWave
3
- module Blitline
4
-
5
- module ClassMethods
6
-
7
- def version(name, &block)
8
- blitline_image_versions << ImageVersion.new(name, &block)
9
- # If process_via_blitline? is true, we still want to register the version with
10
- # the Uploader, but we don't want to define the conversions.
11
- if process_via_blitline?
12
- super(name) {}
13
- else
14
- super(name, &block)
15
- end
16
- end
17
-
18
- def blitline_image_versions
19
- @blitline_versions ||= [ImageVersion.new(nil)]
20
- end
21
-
22
- def process_via_blitline(value = true)
23
- @@process_via_blitline = value
24
- end
25
-
26
- def process_via_blitline?
27
- defined?(@@process_via_blitline) && @@process_via_blitline == true
28
- end
29
-
30
- end
31
- end
32
-
33
- end