image_flux 1.0.2 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.circleci/config.yml +15 -5
- data/.rubocop.yml +42 -50
- data/README.md +12 -1
- data/image_flux.gemspec +4 -5
- data/lib/image_flux/attribute.rb +21 -2
- data/lib/image_flux/option.rb +133 -13
- data/lib/image_flux/origin.rb +7 -2
- data/lib/image_flux/version.rb +1 -1
- data/renovate.json +5 -0
- metadata +17 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
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,30 +2,36 @@ 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:
|
9
9
|
- checkout
|
10
10
|
|
11
|
+
- run:
|
12
|
+
name: Update rubygems
|
13
|
+
command: gem update --system
|
14
|
+
|
11
15
|
- run:
|
12
16
|
name: Update Bunndler
|
13
17
|
command: gem update bundler
|
14
18
|
|
15
19
|
- restore_cache:
|
16
20
|
keys:
|
17
|
-
-
|
18
|
-
-
|
21
|
+
- v2-dependencies-{{ checksum "image_flux.gemspec" }}
|
22
|
+
- v2-dependencies-
|
19
23
|
|
20
24
|
- run:
|
21
25
|
name: install dependencies
|
22
26
|
command: |
|
23
|
-
bundle
|
27
|
+
bundle config set --local path 'vendor/bundle'
|
28
|
+
bundle install --jobs=4 --retry=3
|
29
|
+
bundle update
|
24
30
|
|
25
31
|
- save_cache:
|
26
32
|
paths:
|
27
33
|
- ./vendor/bundle
|
28
|
-
key:
|
34
|
+
key: v2-dependencies-{{ checksum "image_flux.gemspec" }}
|
29
35
|
|
30
36
|
- run:
|
31
37
|
name: RSpec
|
@@ -37,6 +43,10 @@ jobs:
|
|
37
43
|
--out /tmp/test-results/rspec.xml \
|
38
44
|
--format progress
|
39
45
|
|
46
|
+
- run:
|
47
|
+
name: Rubocop
|
48
|
+
command: bundle exec rubocop
|
49
|
+
|
40
50
|
# collect reports
|
41
51
|
- store_test_results:
|
42
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
@@ -32,10 +32,21 @@ Or install it yourself as:
|
|
32
32
|
require 'image_flux'
|
33
33
|
origin = ImageFlux::Origin.new(domain: 'example.imageflux.jp')
|
34
34
|
|
35
|
-
origin.image_url(
|
35
|
+
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
|
|
@@ -23,11 +22,11 @@ Gem::Specification.new do |spec|
|
|
23
22
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
23
|
spec.require_paths = ['lib']
|
25
24
|
|
26
|
-
spec.add_development_dependency 'bundler', '
|
25
|
+
spec.add_development_dependency 'bundler', '>= 1.16'
|
26
|
+
spec.add_development_dependency 'coveralls_reborn'
|
27
27
|
spec.add_development_dependency 'ffaker'
|
28
|
-
spec.add_development_dependency 'rake', '~> 10.0'
|
29
28
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
30
29
|
spec.add_development_dependency 'rspec_junit_formatter'
|
30
|
+
spec.add_development_dependency 'rubocop'
|
31
31
|
spec.add_development_dependency 'simplecov'
|
32
|
-
spec.add_development_dependency 'coveralls'
|
33
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,14 +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
|
-
|
46
|
+
attribute :a, :integer, default: 1, aliases: %i[aspect], enum: {
|
47
|
+
scale: 0,
|
48
|
+
force_scale: 1,
|
49
|
+
crop: 2,
|
50
|
+
pad: 3
|
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
|
35
57
|
attribute :c, :integer_array, default: nil, aliases: %i[crop]
|
36
|
-
attribute :
|
37
|
-
attribute :g, :integer, default: 4, aliases: %i[gravity], enum: {
|
58
|
+
attribute :g, :integer, default: 5, aliases: %i[gravity], enum: {
|
38
59
|
top_left: 1,
|
39
60
|
top_center: 2,
|
40
61
|
top_right: 3,
|
@@ -45,19 +66,89 @@ class ImageFlux::Option
|
|
45
66
|
bottom_center: 8,
|
46
67
|
bottom_right: 9
|
47
68
|
}
|
48
|
-
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
|
49
104
|
validate do |value|
|
50
|
-
|
105
|
+
"rotate should be inclusion of #{ALLOWED_ROTATES.join(', ')}" unless ALLOWED_ROTATES.include?(value.to_s)
|
51
106
|
end
|
52
107
|
end
|
53
|
-
attribute :r, :
|
54
|
-
|
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
|
55
146
|
attribute :l, :string, default: nil
|
56
147
|
attribute :lx, :integer, default: nil
|
57
148
|
attribute :lxr, :integer, default: nil
|
58
149
|
attribute :ly, :integer, default: nil
|
59
150
|
attribute :lyr, :integer, default: nil
|
60
|
-
attribute :lg, :integer, default: 5, aliases: %i[
|
151
|
+
attribute :lg, :integer, default: 5, aliases: %i[], enum: {
|
61
152
|
top_left: 1,
|
62
153
|
top_center: 2,
|
63
154
|
top_right: 3,
|
@@ -68,8 +159,10 @@ class ImageFlux::Option
|
|
68
159
|
bottom_center: 8,
|
69
160
|
bottom_right: 9
|
70
161
|
}
|
162
|
+
|
71
163
|
# output attributes
|
72
|
-
|
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
|
73
166
|
attribute :f, :string, default: 'auto', aliases: %i[format] do
|
74
167
|
validate do |value|
|
75
168
|
"format should be inclusion of #{ALLOWED_FORMATS.join(', ')}" unless ALLOWED_FORMATS.include?(value.to_s)
|
@@ -77,6 +170,21 @@ class ImageFlux::Option
|
|
77
170
|
end
|
78
171
|
attribute :q, :integer, default: 75, aliases: %i[quality]
|
79
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
|
80
188
|
|
81
189
|
attribute :sig, :nonescape_string, default: nil
|
82
190
|
|
@@ -95,7 +203,7 @@ class ImageFlux::Option
|
|
95
203
|
@values[prefix_attr]
|
96
204
|
end
|
97
205
|
|
98
|
-
def to_query
|
206
|
+
def to_query
|
99
207
|
errors = []
|
100
208
|
queries = @values.to_a.map do |pair|
|
101
209
|
attribute = pair.first
|
@@ -107,4 +215,16 @@ class ImageFlux::Option
|
|
107
215
|
|
108
216
|
queries.reject(&:nil?).join(',')
|
109
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
|
110
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,31 +1,31 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: image_flux
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sho Kusano
|
8
|
-
autorequire:
|
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
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.16'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.16'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: coveralls_reborn
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
@@ -39,19 +39,19 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: ffaker
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '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: '
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -81,7 +81,7 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: rubocop
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
@@ -95,7 +95,7 @@ dependencies:
|
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: simplecov
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - ">="
|
@@ -133,11 +133,12 @@ files:
|
|
133
133
|
- lib/image_flux/option.rb
|
134
134
|
- lib/image_flux/origin.rb
|
135
135
|
- lib/image_flux/version.rb
|
136
|
+
- renovate.json
|
136
137
|
homepage: https://github.com/space-pirates-llc/image_flux
|
137
138
|
licenses:
|
138
139
|
- MIT
|
139
140
|
metadata: {}
|
140
|
-
post_install_message:
|
141
|
+
post_install_message:
|
141
142
|
rdoc_options: []
|
142
143
|
require_paths:
|
143
144
|
- lib
|
@@ -152,9 +153,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
152
153
|
- !ruby/object:Gem::Version
|
153
154
|
version: '0'
|
154
155
|
requirements: []
|
155
|
-
|
156
|
-
|
157
|
-
signing_key:
|
156
|
+
rubygems_version: 3.2.3
|
157
|
+
signing_key:
|
158
158
|
specification_version: 4
|
159
159
|
summary: URL builder for ImageFlux
|
160
160
|
test_files: []
|