image_flux 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +11 -5
- data/.rubocop.yml +42 -50
- data/README.md +11 -0
- data/image_flux.gemspec +3 -3
- data/lib/image_flux/attribute.rb +21 -2
- data/lib/image_flux/option.rb +128 -13
- data/lib/image_flux/origin.rb +7 -2
- data/lib/image_flux/version.rb +1 -1
- data/renovate.json +5 -0
- metadata +20 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f04717f6c8a7171ed05a425305e8b186b70d8a5f30e17f34b970ae4069f5e5b
|
4
|
+
data.tar.gz: 7af62a9d8fdf0dfe46b6fd052fd6e1e9d37661893694edb895acb9ba86e3b41f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 933d58c01fb5f19bc00d82078bdee46083044b2e38b43764b44fc74bd5ff3e4fb988308a78a2d6add7bc5e2f8d8f634a0f2c3e05de4e212fb72b7cd40b1c5438
|
7
|
+
data.tar.gz: 5fa56b297858154ea41d0e510cae82fead63ea7f5aef024d6f996f951b883d35f7e3622f0fd9f3b0ca485374c9a9354dc2ce68955ecfb7c6a6c4bf6dd429f781
|
data/.circleci/config.yml
CHANGED
@@ -2,7 +2,7 @@ version: 2
|
|
2
2
|
jobs:
|
3
3
|
build:
|
4
4
|
docker:
|
5
|
-
|
5
|
+
- image: circleci/ruby:3.0.0
|
6
6
|
working_directory: ~/repo
|
7
7
|
|
8
8
|
steps:
|
@@ -18,18 +18,20 @@ jobs:
|
|
18
18
|
|
19
19
|
- restore_cache:
|
20
20
|
keys:
|
21
|
-
-
|
22
|
-
-
|
21
|
+
- v2-dependencies-{{ checksum "image_flux.gemspec" }}
|
22
|
+
- v2-dependencies-
|
23
23
|
|
24
24
|
- run:
|
25
25
|
name: install dependencies
|
26
26
|
command: |
|
27
|
-
bundle
|
27
|
+
bundle config set --local path 'vendor/bundle'
|
28
|
+
bundle install --jobs=4 --retry=3
|
29
|
+
bundle update
|
28
30
|
|
29
31
|
- save_cache:
|
30
32
|
paths:
|
31
33
|
- ./vendor/bundle
|
32
|
-
key:
|
34
|
+
key: v2-dependencies-{{ checksum "image_flux.gemspec" }}
|
33
35
|
|
34
36
|
- run:
|
35
37
|
name: RSpec
|
@@ -41,6 +43,10 @@ jobs:
|
|
41
43
|
--out /tmp/test-results/rspec.xml \
|
42
44
|
--format progress
|
43
45
|
|
46
|
+
- run:
|
47
|
+
name: Rubocop
|
48
|
+
command: bundle exec rubocop
|
49
|
+
|
44
50
|
# collect reports
|
45
51
|
- store_test_results:
|
46
52
|
path: /tmp/test-results
|
data/.rubocop.yml
CHANGED
@@ -1,82 +1,74 @@
|
|
1
1
|
AllCops:
|
2
|
+
SuggestExtensions: false
|
3
|
+
NewCops: enable
|
4
|
+
Include:
|
5
|
+
- '**/Gemfile'
|
6
|
+
- '**/Rakefile'
|
7
|
+
- '**/*.rake'
|
8
|
+
- '**/*.rb'
|
9
|
+
- '**/*.gemspec'
|
10
|
+
Exclude:
|
11
|
+
- 'bin/**/*'
|
12
|
+
- 'vendor/bundle/**/*'
|
2
13
|
DisplayCopNames: true
|
3
|
-
DisplayStyleGuide: true
|
4
14
|
|
5
|
-
|
15
|
+
Style/Alias:
|
16
|
+
EnforcedStyle: prefer_alias_method
|
17
|
+
|
18
|
+
Layout/ParameterAlignment:
|
6
19
|
EnforcedStyle: with_fixed_indentation
|
7
20
|
|
8
21
|
Style/ClassAndModuleChildren:
|
9
22
|
EnforcedStyle: compact
|
10
|
-
Exclude:
|
11
|
-
- config/application.rb
|
12
23
|
|
13
24
|
Style/Documentation:
|
14
25
|
Enabled: false
|
15
26
|
|
27
|
+
Layout/EmptyLines:
|
28
|
+
Exclude:
|
29
|
+
- '**/Gemfile'
|
30
|
+
|
16
31
|
Style/FrozenStringLiteralComment:
|
17
|
-
|
18
|
-
|
32
|
+
Exclude:
|
33
|
+
- '**/Gemfile'
|
34
|
+
|
35
|
+
Naming/FileName:
|
36
|
+
Exclude:
|
37
|
+
- '**/Gemfile'
|
38
|
+
- '**/Guardfile'
|
19
39
|
|
20
40
|
Style/RegexpLiteral:
|
21
41
|
EnforcedStyle: percent_r
|
42
|
+
AllowInnerSlashes: false
|
22
43
|
|
23
|
-
|
24
|
-
|
25
|
-
Metrics/AbcSize:
|
26
|
-
Max: 15
|
44
|
+
Style/MutableConstant:
|
45
|
+
Enabled: false
|
27
46
|
|
28
47
|
Metrics/BlockLength:
|
29
|
-
CountComments: false
|
30
|
-
Max: 25
|
31
|
-
ExcludedMethods: []
|
32
48
|
Exclude:
|
33
|
-
-
|
49
|
+
- 'test/**/*'
|
50
|
+
- 'spec/**/*'
|
34
51
|
|
35
|
-
|
36
|
-
|
37
|
-
Max: 3
|
52
|
+
Layout/LineLength:
|
53
|
+
Max: 240
|
38
54
|
|
39
55
|
Metrics/ClassLength:
|
40
|
-
CountComments: false
|
41
56
|
Max: 200
|
42
57
|
|
43
|
-
Metrics/CyclomaticComplexity:
|
44
|
-
Max: 12
|
45
|
-
|
46
|
-
Metrics/LineLength:
|
47
|
-
Max: 180
|
48
|
-
|
49
58
|
Metrics/MethodLength:
|
50
59
|
Max: 20
|
51
60
|
|
52
|
-
Metrics/
|
53
|
-
Max:
|
61
|
+
Metrics/AbcSize:
|
62
|
+
Max: 35
|
54
63
|
|
55
|
-
Metrics/
|
56
|
-
Max:
|
64
|
+
Metrics/CyclomaticComplexity:
|
65
|
+
Max: 20
|
57
66
|
|
58
67
|
Metrics/PerceivedComplexity:
|
59
|
-
Max:
|
60
|
-
|
61
|
-
#################### Lint ##################################
|
62
|
-
|
63
|
-
Lint/UnusedBlockArgument:
|
64
|
-
IgnoreEmptyBlocks: true
|
65
|
-
AllowUnusedKeywordArguments: true
|
66
|
-
|
67
|
-
Lint/UnusedMethodArgument:
|
68
|
-
AllowUnusedKeywordArguments: true
|
69
|
-
IgnoreEmptyMethods: true
|
70
|
-
|
71
|
-
#################### Performance ###########################
|
72
|
-
|
73
|
-
Performance/DoubleStartEndWith:
|
74
|
-
IncludeActiveSupportAliases: false
|
75
|
-
|
76
|
-
Performance/RedundantMerge:
|
77
|
-
MaxKeyValuePairs: 2
|
68
|
+
Max: 20
|
78
69
|
|
79
|
-
|
70
|
+
Metrics/ParameterLists:
|
71
|
+
Max: 6
|
80
72
|
|
81
|
-
|
82
|
-
|
73
|
+
Gemspec/RequiredRubyVersion:
|
74
|
+
Enabled: false
|
data/README.md
CHANGED
@@ -36,6 +36,17 @@ origin.image_url('/original.jpg', width: 100)
|
|
36
36
|
# => https://example.imageflux.jp/c/w=100/original.jpg
|
37
37
|
```
|
38
38
|
|
39
|
+
### Generate option with class
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
option = ImageFlux::Option.new()
|
43
|
+
option.width = 100
|
44
|
+
option.overlay = [
|
45
|
+
{ w: 100, path: '/hello-world.png' },
|
46
|
+
]
|
47
|
+
origin.image_url('/original.jpg', option)
|
48
|
+
```
|
49
|
+
|
39
50
|
## Development
|
40
51
|
|
41
52
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/image_flux.gemspec
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
|
2
1
|
# frozen_string_literal: true
|
3
2
|
|
4
|
-
lib = File.expand_path('
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
5
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
5
|
require 'image_flux/version'
|
7
6
|
|
@@ -24,9 +23,10 @@ Gem::Specification.new do |spec|
|
|
24
23
|
spec.require_paths = ['lib']
|
25
24
|
|
26
25
|
spec.add_development_dependency 'bundler', '>= 1.16'
|
26
|
+
spec.add_development_dependency 'coveralls_reborn'
|
27
27
|
spec.add_development_dependency 'ffaker'
|
28
28
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
29
29
|
spec.add_development_dependency 'rspec_junit_formatter'
|
30
|
+
spec.add_development_dependency 'rubocop'
|
30
31
|
spec.add_development_dependency 'simplecov'
|
31
|
-
spec.add_development_dependency 'coveralls_reborn'
|
32
32
|
end
|
data/lib/image_flux/attribute.rb
CHANGED
@@ -23,12 +23,15 @@ class ImageFlux::Attribute
|
|
23
23
|
@enum ? @enum.fetch(value) { value } : value
|
24
24
|
end
|
25
25
|
|
26
|
+
# rubocop:disable Metrics/MethodLength
|
26
27
|
def querize(value, ignore_default: true)
|
27
28
|
value = expand(value)
|
28
29
|
return nil if !@query || (ignore_default && default == value)
|
29
30
|
|
30
31
|
value = case type
|
31
|
-
when :
|
32
|
+
when :overlay
|
33
|
+
return querize_overlay(value)
|
34
|
+
when :string, Regexp
|
32
35
|
value.to_s
|
33
36
|
when :integer
|
34
37
|
value.to_i.to_s
|
@@ -40,12 +43,26 @@ class ImageFlux::Attribute
|
|
40
43
|
value.map(&:to_f).join(':')
|
41
44
|
when :boolean
|
42
45
|
value ? '1' : '0'
|
46
|
+
when :path
|
47
|
+
return nil
|
43
48
|
else
|
44
49
|
value
|
45
50
|
end
|
46
51
|
|
47
52
|
"#{name}=#{value}"
|
48
53
|
end
|
54
|
+
# rubocop:enable Metrics/MethodLength
|
55
|
+
|
56
|
+
def querize_overlay(value)
|
57
|
+
values = [value].flatten
|
58
|
+
values.map do |val|
|
59
|
+
option = val.is_a?(Hash) ? ImageFlux::Option.new(val) : val
|
60
|
+
path = option.path.to_s
|
61
|
+
path = "/#{path}" unless path.start_with?('/')
|
62
|
+
query = "#{option.to_query}#{URI.encode_www_form_component(path)}"
|
63
|
+
"l=(#{query})"
|
64
|
+
end.join(',')
|
65
|
+
end
|
49
66
|
|
50
67
|
def validate!(value)
|
51
68
|
errors = []
|
@@ -59,7 +76,7 @@ class ImageFlux::Attribute
|
|
59
76
|
|
60
77
|
def validate_type(value)
|
61
78
|
check = case type
|
62
|
-
when :string
|
79
|
+
when :string, :path
|
63
80
|
value.is_a?(String) || value.respond_to?(:to_s)
|
64
81
|
when :integer
|
65
82
|
value.is_a?(Integer) || value.respond_to?(:to_i)
|
@@ -71,6 +88,8 @@ class ImageFlux::Attribute
|
|
71
88
|
value.is_a?(Array) && value.all? { |elem| elem.is_a?(Float) || elem.respond_to?(:to_i) }
|
72
89
|
when :boolean
|
73
90
|
value.is_a?(TrueClass) || value.is_a?(FalseClass)
|
91
|
+
when Regexp
|
92
|
+
value.respond_to?(:to_s) && type.match?(value.to_s)
|
74
93
|
else
|
75
94
|
true
|
76
95
|
end
|
data/lib/image_flux/option.rb
CHANGED
@@ -5,6 +5,13 @@ require 'image_flux/attribute'
|
|
5
5
|
require 'image_flux/error'
|
6
6
|
|
7
7
|
class ImageFlux::Option
|
8
|
+
REGEXP_INTEGER = %r{\d+}
|
9
|
+
REGEXP_FLOAT = %r{\d+(?:\.\d+)?}
|
10
|
+
|
11
|
+
REGEXP_UNSHARP = %r{\A#{REGEXP_INTEGER}x#{REGEXP_FLOAT}(?:\+#{REGEXP_FLOAT}){1,2}\z}x
|
12
|
+
REGEXP_BLUR = %r{\A#{REGEXP_INTEGER}x#{REGEXP_FLOAT}\z}x
|
13
|
+
REGEXP_MASK = %r{\A(?:white|black|alpha)(?::[01])?\z}
|
14
|
+
|
8
15
|
def self.attributes
|
9
16
|
@attributes ||= []
|
10
17
|
end
|
@@ -14,12 +21,17 @@ class ImageFlux::Option
|
|
14
21
|
end
|
15
22
|
|
16
23
|
def self.attribute(name, type, options = {}, &block)
|
17
|
-
attribute = ImageFlux::Attribute.new(name, type, options)
|
24
|
+
attribute = ImageFlux::Attribute.new(name, type, **options)
|
18
25
|
attribute.instance_eval(&block) if block_given?
|
19
26
|
key_pairs[attribute.name] = attribute
|
20
27
|
attribute.aliases.each do |key|
|
21
28
|
key_pairs[key] = attribute
|
22
29
|
end
|
30
|
+
names = [name] + (options[:aliases] || [])
|
31
|
+
names.each do |n|
|
32
|
+
define_method(:"#{n}") { @values[attribute] }
|
33
|
+
define_method(:"#{n}=") { |val| @values[attribute] = val }
|
34
|
+
end
|
23
35
|
|
24
36
|
attributes.push(attribute)
|
25
37
|
end
|
@@ -27,19 +39,23 @@ class ImageFlux::Option
|
|
27
39
|
# Predefined prefix path
|
28
40
|
attribute :prefix, :string, default: nil, query: false
|
29
41
|
|
30
|
-
#
|
42
|
+
# scaling attributes
|
43
|
+
# https://console.imageflux.jp/docs/image/conversion-parameters#scaling
|
31
44
|
attribute :w, :integer, default: nil, aliases: %i[width]
|
32
45
|
attribute :h, :integer, default: nil, aliases: %i[height]
|
33
|
-
attribute :
|
34
|
-
attribute :a, :integer, default: 1, aliases: %i[aspect], enum:{
|
46
|
+
attribute :a, :integer, default: 1, aliases: %i[aspect], enum: {
|
35
47
|
scale: 0,
|
36
48
|
force_scale: 1,
|
37
49
|
crop: 2,
|
38
50
|
pad: 3
|
39
51
|
}
|
52
|
+
attribute :b, :string, default: 'ffffff', aliases: %i[background] do
|
53
|
+
validate do |value|
|
54
|
+
'b should be a color code' unless value.to_s =~ %r{\A[0-9a-fA-F]{6}\z}
|
55
|
+
end
|
56
|
+
end
|
40
57
|
attribute :c, :integer_array, default: nil, aliases: %i[crop]
|
41
|
-
attribute :
|
42
|
-
attribute :g, :integer, default: 4, aliases: %i[gravity], enum: {
|
58
|
+
attribute :g, :integer, default: 5, aliases: %i[gravity], enum: {
|
43
59
|
top_left: 1,
|
44
60
|
top_center: 2,
|
45
61
|
top_right: 3,
|
@@ -50,19 +66,89 @@ class ImageFlux::Option
|
|
50
66
|
bottom_center: 8,
|
51
67
|
bottom_right: 9
|
52
68
|
}
|
53
|
-
attribute :
|
69
|
+
attribute :u, :boolean, default: true, aliases: %i[upscale]
|
70
|
+
|
71
|
+
# clipping attributes
|
72
|
+
# ref: https://console.imageflux.jp/docs/image/conversion-parameters#clipping
|
73
|
+
attribute :ic, :integer_array, default: nil, aliases: %i[input_clipping]
|
74
|
+
attribute :icr, :float_array, default: nil, aliases: %i[input_clipping_range]
|
75
|
+
attribute :ig, :integer, default: nil, aliases: %i[input_gravity], enum: {
|
76
|
+
top_left: 1,
|
77
|
+
top_center: 2,
|
78
|
+
top_right: 3,
|
79
|
+
middle_left: 4,
|
80
|
+
middle_center: 5,
|
81
|
+
middle_right: 6,
|
82
|
+
bottom_left: 7,
|
83
|
+
bottom_center: 8,
|
84
|
+
bottom_right: 9
|
85
|
+
}
|
86
|
+
attribute :c, :integer_array, default: nil, aliases: %i[oc output_clipping]
|
87
|
+
attribute :cr, :float_array, default: nil, aliases: %i[ocr output_clipping_range]
|
88
|
+
attribute :og, :integer, default: nil, aliases: %i[output_gravity], enum: {
|
89
|
+
top_left: 1,
|
90
|
+
top_center: 2,
|
91
|
+
top_right: 3,
|
92
|
+
middle_left: 4,
|
93
|
+
middle_center: 5,
|
94
|
+
middle_right: 6,
|
95
|
+
bottom_left: 7,
|
96
|
+
bottom_center: 8,
|
97
|
+
bottom_right: 9
|
98
|
+
}
|
99
|
+
|
100
|
+
# rotation attributes
|
101
|
+
# ref: https://console.imageflux.jp/docs/image/conversion-parameters#rotation
|
102
|
+
ALLOWED_ROTATES = %w[1 2 3 4 5 6 7 8 auto].freeze
|
103
|
+
attribute :ir, :string, default: '1', aliases: %i[input_rotate] do
|
54
104
|
validate do |value|
|
55
|
-
|
105
|
+
"rotate should be inclusion of #{ALLOWED_ROTATES.join(', ')}" unless ALLOWED_ROTATES.include?(value.to_s)
|
56
106
|
end
|
57
107
|
end
|
58
|
-
attribute :r, :
|
59
|
-
|
108
|
+
attribute :r, :string, default: '1', aliases: %i[or rotate output_rotate] do
|
109
|
+
validate do |value|
|
110
|
+
"rotate should be inclusion of #{ALLOWED_ROTATES.join(', ')}" unless ALLOWED_ROTATES.include?(value.to_s)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
# filter attributes
|
115
|
+
# ref: https://console.imageflux.jp/docs/image/conversion-parameters#filter
|
116
|
+
attribute :unsharp, REGEXP_UNSHARP, default: nil, aliases: %i[]
|
117
|
+
attribute :blur, REGEXP_BLUR, default: nil, aliases: %i[]
|
118
|
+
attribute :grayscale, :integer, default: nil, aliases: %i[]
|
119
|
+
attribute :sepia, :integer, default: nil, aliases: %i[]
|
120
|
+
attribute :brightnes, :integer, default: nil, aliases: %i[]
|
121
|
+
attribute :contrast, :integer, default: nil, aliases: %i[]
|
122
|
+
attribute :invert, :integer, default: nil, aliases: %i[]
|
123
|
+
|
124
|
+
# overlay attribute
|
125
|
+
attribute :overlay, :overlay, default: nil
|
126
|
+
attribute :path, :path, default: nil
|
127
|
+
attribute :x, :integer, default: 0
|
128
|
+
attribute :xr, :float, default: nil
|
129
|
+
attribute :y, :integer, default: 0
|
130
|
+
attribute :yr, :float, default: nil
|
131
|
+
attribute :lg, :integer, default: 5, aliases: %i[], enum: {
|
132
|
+
top_left: 1,
|
133
|
+
top_center: 2,
|
134
|
+
top_right: 3,
|
135
|
+
middle_left: 4,
|
136
|
+
middle_center: 5,
|
137
|
+
middle_right: 6,
|
138
|
+
bottom_left: 7,
|
139
|
+
bottom_center: 8,
|
140
|
+
bottom_right: 9
|
141
|
+
}
|
142
|
+
attribute :mask, REGEXP_MASK, default: nil
|
143
|
+
|
144
|
+
# old overlay attributes
|
145
|
+
# ref: https://console.imageflux.jp/docs/image/conversion-parameters#%E7%94%BB%E5%83%8F%E4%BD%8D%E7%BD%AE%E3%81%AE%E6%8C%87%E5%AE%9A-%E5%8F%A4%E3%81%84%E5%BD%A2%E5%BC%8F
|
60
146
|
attribute :l, :string, default: nil
|
61
147
|
attribute :lx, :integer, default: nil
|
62
148
|
attribute :lxr, :integer, default: nil
|
63
149
|
attribute :ly, :integer, default: nil
|
64
150
|
attribute :lyr, :integer, default: nil
|
65
|
-
attribute :lg, :integer, default: 5, aliases: %i[
|
151
|
+
attribute :lg, :integer, default: 5, aliases: %i[], enum: {
|
66
152
|
top_left: 1,
|
67
153
|
top_center: 2,
|
68
154
|
top_right: 3,
|
@@ -73,8 +159,10 @@ class ImageFlux::Option
|
|
73
159
|
bottom_center: 8,
|
74
160
|
bottom_right: 9
|
75
161
|
}
|
162
|
+
|
76
163
|
# output attributes
|
77
|
-
|
164
|
+
# ref: https://console.imageflux.jp/docs/image/conversion-parameters#output
|
165
|
+
ALLOWED_FORMATS = %w[auto jpg png gif webp:jpeg webp:png webp:auto].freeze
|
78
166
|
attribute :f, :string, default: 'auto', aliases: %i[format] do
|
79
167
|
validate do |value|
|
80
168
|
"format should be inclusion of #{ALLOWED_FORMATS.join(', ')}" unless ALLOWED_FORMATS.include?(value.to_s)
|
@@ -82,6 +170,21 @@ class ImageFlux::Option
|
|
82
170
|
end
|
83
171
|
attribute :q, :integer, default: 75, aliases: %i[quality]
|
84
172
|
attribute :o, :boolean, default: true, aliases: %i[optimize]
|
173
|
+
attribute :lossless, :boolean, default: nil, aliases: %i[]
|
174
|
+
attribute :s, :integer, default: 1, aliases: %i[strip], enum: {
|
175
|
+
strip: 1,
|
176
|
+
strip_without_orientation: 2
|
177
|
+
}
|
178
|
+
|
179
|
+
# through attributes
|
180
|
+
# https://console.imageflux.jp/docs/image/conversion-parameters#through
|
181
|
+
ALLOWED_THROUGH_FORMATS = %w[jpg png gif].freeze
|
182
|
+
attribute :t, :string, aliases: %i[through] do
|
183
|
+
validate do |_value|
|
184
|
+
values = values.to_s.split(':')
|
185
|
+
"format should be inclusion of #{ALLOWED_THROUGH_FORMATS.join(', ')}" unless values.all? { |format| ALLOWED_THROUGH_FORMATS.includes?(format) }
|
186
|
+
end
|
187
|
+
end
|
85
188
|
|
86
189
|
attribute :sig, :nonescape_string, default: nil
|
87
190
|
|
@@ -100,7 +203,7 @@ class ImageFlux::Option
|
|
100
203
|
@values[prefix_attr]
|
101
204
|
end
|
102
205
|
|
103
|
-
def to_query
|
206
|
+
def to_query
|
104
207
|
errors = []
|
105
208
|
queries = @values.to_a.map do |pair|
|
106
209
|
attribute = pair.first
|
@@ -112,4 +215,16 @@ class ImageFlux::Option
|
|
112
215
|
|
113
216
|
queries.reject(&:nil?).join(',')
|
114
217
|
end
|
218
|
+
|
219
|
+
def to_h
|
220
|
+
hash = {}
|
221
|
+
@values.each_pair do |attribute, val|
|
222
|
+
hash[attribute.name] = val
|
223
|
+
end
|
224
|
+
hash
|
225
|
+
end
|
226
|
+
|
227
|
+
def merge(other)
|
228
|
+
to_h.merge(other)
|
229
|
+
end
|
115
230
|
end
|
data/lib/image_flux/origin.rb
CHANGED
@@ -7,6 +7,7 @@ require 'image_flux'
|
|
7
7
|
|
8
8
|
class ImageFlux::Origin
|
9
9
|
attr_reader :domain, :scheme, :signing_version, :signing_secret
|
10
|
+
|
10
11
|
def initialize(domain:, scheme: 'https', signing_version: '1', signing_secret: nil, **_options)
|
11
12
|
@domain = domain.to_s
|
12
13
|
@scheme = scheme.to_s
|
@@ -21,8 +22,7 @@ class ImageFlux::Origin
|
|
21
22
|
def image_url(path, options = {})
|
22
23
|
path = "/#{path}" unless path.start_with?('/')
|
23
24
|
|
24
|
-
|
25
|
-
opt = ImageFlux::Option.new(options)
|
25
|
+
opt = options.is_a?(ImageFlux::Option) ? options : ImageFlux::Option.new(options)
|
26
26
|
|
27
27
|
path = "#{opt.prefix_path}#{path}" if opt.prefix_path
|
28
28
|
query = opt.to_query
|
@@ -30,6 +30,11 @@ class ImageFlux::Origin
|
|
30
30
|
url = base_url.dup
|
31
31
|
url.path = query.length.zero? ? path : "/c/#{opt.to_query}#{path}"
|
32
32
|
|
33
|
+
if @signing_secret
|
34
|
+
signed_opt = ImageFlux::Option.new(options.merge(sig: sign(url.path)))
|
35
|
+
url.path = "/c/#{signed_opt.to_query}#{path}"
|
36
|
+
end
|
37
|
+
|
33
38
|
url
|
34
39
|
end
|
35
40
|
|
data/lib/image_flux/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: image_flux
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sho Kusano
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: coveralls_reborn
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: ffaker
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -67,7 +81,7 @@ dependencies:
|
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
84
|
+
name: rubocop
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
87
|
- - ">="
|
@@ -81,7 +95,7 @@ dependencies:
|
|
81
95
|
- !ruby/object:Gem::Version
|
82
96
|
version: '0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
98
|
+
name: simplecov
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
86
100
|
requirements:
|
87
101
|
- - ">="
|
@@ -119,6 +133,7 @@ files:
|
|
119
133
|
- lib/image_flux/option.rb
|
120
134
|
- lib/image_flux/origin.rb
|
121
135
|
- lib/image_flux/version.rb
|
136
|
+
- renovate.json
|
122
137
|
homepage: https://github.com/space-pirates-llc/image_flux
|
123
138
|
licenses:
|
124
139
|
- MIT
|
@@ -138,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
153
|
- !ruby/object:Gem::Version
|
139
154
|
version: '0'
|
140
155
|
requirements: []
|
141
|
-
rubygems_version: 3.
|
156
|
+
rubygems_version: 3.2.3
|
142
157
|
signing_key:
|
143
158
|
specification_version: 4
|
144
159
|
summary: URL builder for ImageFlux
|