api_recipes 3.0.0.beta6 → 3.0.0.beta7

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
  SHA256:
3
- metadata.gz: cd978dd075770c8701ae9cb41204c649390016b2e697feb1a01e7b058c400673
4
- data.tar.gz: a8513c2f62b2089031cfbe93831e36aa757a32165c7cd0cb1bd2efb8add89144
3
+ metadata.gz: e74dee706cb23be6a067db39d719b50541d83183b705739d9a451806bfcc51b9
4
+ data.tar.gz: 91b784da2650e2f7af4a603b6ab1e5190336dd4db845b83ba59579936dd98f51
5
5
  SHA512:
6
- metadata.gz: ebffee15a5f424293845ebe0104c7127fc02c9e5b946fc6ece9b668e8b799c2606163c8f6b81cef185b43714586fb81b9a44c0a8075ed63d81452332383d78b9
7
- data.tar.gz: 76cbe576de29f0e141776addeb315ea16ab08a691672a9f4fb72e1c80a3181b3cb32fb98bab8fbf2be062160c5d560c97d78d56efd459c26f4e7931d48c77e2c
6
+ metadata.gz: b930031404cff1ef52d916145db794849902b4647aa7d5911a62d69d2310e1a97b6a24609f63f9da314913af39f9e98e2a9747306280538da6ef62d998e886c1
7
+ data.tar.gz: 69a9493844b49deec69eafdc8d7e1e7477d7e5d2cf3ad0d3e514e9597b6646d54991529c1462561f00707c2a1220fa71e94e5d265bdadef28d29a6d820ff08cf
data/README.md CHANGED
@@ -555,7 +555,6 @@ No segment of the value can be empty, `.` or `..`, so the value never climbs
555
555
  out of the path: `'a/../b'`, `'/a'` and `'a//b'` raise
556
556
  `ApiRecipes::InvalidVariable`. In a header or a parameter `{*name}` is text,
557
557
  a `host` refuses it, and `\{*name}` is text in a `path` and in a `base_url`.
558
- A portable recipe that uses `{*name}` declares `recipe.format: 2`.
559
558
 
560
559
  The value of a variable is a String, a Symbol or a number, and is kept as
561
560
  text. A value is checked for the place where it ends up. In a `host` it can contain
@@ -992,10 +991,7 @@ The rules, beyond those of every description:
992
991
  (`billing.recipe.yml`) are the same: lowercase letters, digits, `-` and `_`.
993
992
  - `recipe.name` and `recipe.version` are required. The version is text made of
994
993
  digits, letters and dots: write `'1.2'` between quotes. `format` is the
995
- version of the format: 1, or none, for most recipes; 2 for a recipe that
996
- uses a `{*name}` variable in its `base_url` or in the `path` of an endpoint,
997
- so that a version of the gem that does not know `{*name}` refuses it.
998
- `summary` and `homepage` are optional.
994
+ version of the format, today 1; `summary` and `homepage` are optional.
999
995
  - `host` is required. A variable can be the whole host, or stand before fixed
1000
996
  text that starts with a dot: `{account}.billing.example.com` and
1001
997
  `s3.{region}.example.com` are accepted, `api.example.{tld}` is not.
@@ -1083,11 +1079,11 @@ What the command does:
1083
1079
  declares is given by the application from now on. Only a variable with a
1084
1080
  default is declared in the recipe. In the `base_url` and in a `path` the
1085
1081
  variable is a `{*name}`, since 2.x put the value of the tag there with its
1086
- slashes, and the recipe then declares `recipe.format: 2`. A value of one or
1087
- more segments goes where 2.x sent it; one that starts or ends with a slash,
1088
- has two in a row or is empty, which 2.x joined, raises
1089
- `ApiRecipes::InvalidVariable` at the request: give it without those slashes.
1090
- The command says so when the default written in the tag is such a value.
1082
+ slashes. A value of one or more segments goes where 2.x sent it; one that
1083
+ starts or ends with a slash, has two in a row or is empty, which 2.x joined,
1084
+ raises `ApiRecipes::InvalidVariable` at the request: give it without those
1085
+ slashes. The command says so when the default written in the tag is such a
1086
+ value.
1091
1087
  - **A word in braces stays text**, as 2.x sent it, unless the file declares a
1092
1088
  variable with that name: it is written `\{word}` in a `path` and in the
1093
1089
  `base_url`, and a header or a parameter that holds one is given by a
@@ -77,7 +77,6 @@ module ApiRecipes
77
77
  @secret = []
78
78
  @given = {}
79
79
  @refs = {}
80
- @segments = false
81
80
  name, options = api(parsed(plain(source)))
82
81
  @name = name
83
82
  declared = options['variables']
@@ -87,7 +86,7 @@ module ApiRecipes
87
86
  refuse('already has the key recipe: rename the file to NAME.recipe.yml and check it') if options.key?('recipe')
88
87
 
89
88
  body = api_options(options)
90
- body = { 'recipe' => { 'name' => name, 'version' => @version, 'format' => @segments ? Internals::Recipe::SEGMENTS_FORMAT : Internals::Recipe::FORMATS.first } }.merge(body)
89
+ body = { 'recipe' => { 'name' => name, 'version' => @version, 'format' => Internals::Recipe::FORMATS.first } }.merge(body)
91
90
  # A variable that has no default needs no declaration: the recipe
92
91
  # uses it, and that makes it a variable that a value must be given to.
93
92
  written = @variables.reject { |_, spec| spec.empty? }
@@ -419,8 +418,7 @@ module ApiRecipes
419
418
 
420
419
  # A value where a recipe can have a variable.
421
420
  # star: in the base_url and in a path, where 2.x put the value of the
422
- # tag as it was, slashes included: the variable spans several segments,
423
- # and the recipe asks for the format that knows {*name}.
421
+ # tag as it was, slashes included: the variable spans several segments.
424
422
  def with_variables(value, where, fallback, star: false)
425
423
  return fixed(value, where) unless value.is_a?(String) && @token.match?(value)
426
424
 
@@ -428,7 +426,6 @@ module ApiRecipes
428
426
  tag = @tags[Regexp.last_match(1).to_i]
429
427
  variable = variable_for(tag, fallback, where, default: true)
430
428
  kept = @variables[variable].key?('default') ? ', with the default written in the tag' : ''
431
- @segments ||= star
432
429
  as_variable = "{#{'*' if star}#{variable}}"
433
430
  @changes << "#{shown(where)}: the ERB tag is now the variable #{as_variable}#{kept}"
434
431
  refused_default(where, variable) if star
@@ -31,26 +31,12 @@ module ApiRecipes
31
31
  raise ArgumentError, "placeholder '#{repeated}' is repeated in '#{string}'" if repeated
32
32
  @param_names = names.freeze
33
33
  @variable_names = @parts.select { |kind, _| VARIABLE_KINDS.include?(kind) }.map(&:last).uniq.freeze
34
- @segments = @parts.any? { |kind, _| kind == :segments }
35
- end
36
-
37
- # True when string, read as a path, has a {*name}. A string that is not
38
- # a valid path answers false: whoever compiles it reports why.
39
- def self.segments_variable?(string)
40
- parse(string.to_s).segments?
41
- rescue ArgumentError
42
- false
43
34
  end
44
35
 
45
36
  # param_names: the placeholders, which take an argument each, in order.
46
37
  # variable_names: the {variables} and {*variables} of the api, each once.
47
38
  attr_reader :param_names, :variable_names
48
39
 
49
- # Whether the path has a {*name}, whose value spans several segments.
50
- def segments?
51
- @segments
52
- end
53
-
54
40
  # The block, if given, is called with the name of a parameter, :slash when
55
41
  # its value (not a splat) contains '/' or :encoded when it contains a
56
42
  # sequence %XX, and the endpoint. It never receives the value.
@@ -10,9 +10,7 @@ module ApiRecipes
10
10
  class Recipe
11
11
  MAX_BYTES = 1_048_576
12
12
  SUFFIX = '.recipe.yml'
13
- FORMATS = [1, 2].freeze
14
- # The format that knows {*name}.
15
- SEGMENTS_FORMAT = 2
13
+ FORMATS = [1].freeze
16
14
  NAME = /\A[a-z0-9_][a-z0-9_-]{0,63}\z/
17
15
  VERSION = /\A[0-9A-Za-z]+(?:\.[0-9A-Za-z]+)*\z/
18
16
  MAX_VERSION = 32
@@ -120,8 +118,7 @@ module ApiRecipes
120
118
  refuse(refused) if refused
121
119
  name, options = one_api(data)
122
120
  problems = name_problems(name, file_name) + recipe_problems(name, options['recipe']) +
123
- verify_with_problems(name, options) + host_problems(options['host']) + size_problems(options) +
124
- segments_problems(options)
121
+ verify_with_problems(name, options) + host_problems(options['host']) + size_problems(options)
125
122
  refuse(problems) unless problems.empty?
126
123
 
127
124
  @name = name
@@ -285,29 +282,6 @@ module ApiRecipes
285
282
  problems
286
283
  end
287
284
 
288
- # A {*name} spans several segments, and a version of the gem that knows
289
- # only format 1 would send it as text: such a recipe declares format 2,
290
- # so that an older version refuses it. A \{*name} is text and asks
291
- # for nothing.
292
- def segments_problems(options)
293
- recipe = options['recipe']
294
- return [] unless recipe.is_a?(Hash) && [nil, 1].include?(recipe['format'])
295
- return [] unless segments_variable?(options['base_url']) || segments_in_paths?(options['endpoints'])
296
-
297
- ["uses {*name} in its base_url or in the path of an endpoint: write recipe.format: #{SEGMENTS_FORMAT}, " \
298
- 'so that an older api_recipes refuses it']
299
- end
300
-
301
- def segments_in_paths?(endpoints)
302
- return false unless endpoints.is_a?(Hash)
303
-
304
- endpoints.each_value.any? do |options|
305
- options.is_a?(Hash) && (segments_variable?(options['path']) || segments_in_paths?(options['endpoints']))
306
- end
307
- end
308
-
309
- def segments_variable?(value) = value.is_a?(String) && PathTemplate.segments_variable?(value)
310
-
311
285
  # A variable can be the whole host, or stand before fixed text that
312
286
  # starts with a dot: its value never decides where the host ends.
313
287
  def host_problems(host)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ApiRecipes
4
- VERSION = '3.0.0.beta6'
4
+ VERSION = '3.0.0.beta7'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api_recipes
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.beta6
4
+ version: 3.0.0.beta7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alessandro Verlato