praxis 2.0.pre.1 → 2.0.pre.2

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: 66fe6c957729cb25f0696e23a380423d00ff30e51a838df8e575496db0894e5f
4
- data.tar.gz: ca436e9dff7c965063d6787e6bbbd4f5178ba08b98124f98881f35ce5c5d5f22
3
+ metadata.gz: f23deb4aca50709972c23925ed41fde1fe98baaf7e865513b7f047611bd3af3d
4
+ data.tar.gz: 512839b90d37a8ac2cb67a7a14f32a8353160d15ef43d0066c860ec95da3002e
5
5
  SHA512:
6
- metadata.gz: cfc68735d454382c9adc26c880bf0f4a3fda03df4de7b24e439071b576b97bf8a6fa0006e5c48c78ad82034c4c11461a1848caea535bd36457b4517cec17c536
7
- data.tar.gz: 0b3f4143a20db3a80ceea7666f5b24af63d907fcdd9aecd1b7d3ca78b4b500756999d98b7bc5e85372be14bf7a5c16d65da0268e7c5565b24b4e35956fd21bf3
6
+ metadata.gz: 19ff50cbc1d7c9b003725f96122cfab8c8c221f54d8df5a142299ad260dcb2f9597d504e6761c18badee02a768d18dab81dc76425abda01704a9e61f0aae3769
7
+ data.tar.gz: 3b2885d5e46d68848541dfed03dabe8cc1df71a430d1fdd42fc330035f544fee5b05291cf8087c00a51c987c2087e4f6e2a502522566e61a88f50e0adee4a71f
data/.travis.yml CHANGED
@@ -1,28 +1,13 @@
1
- language: ruby
2
- cache: bundler
3
1
  sudo: false
2
+ language: ruby
4
3
  rvm:
5
- - 2.3
6
4
  - 2.4
7
5
  - 2.5
8
6
  - 2.6
7
+ - 2.7
8
+ script:
9
+ - bundle exec rspec spec
9
10
  branches:
10
11
  only:
11
12
  - master
12
- before_install:
13
- - gem update --system # Due to: https://github.com/travis-ci/travis-ci/issues/8978
14
- # Leaving all API browser testing commented out as there are some very node dependencies that
15
- # need to be worked out and updated
16
- # node_js:
17
- # - "0.10"
18
- # before_install:
19
- # - nvm install 0.10
20
- # - node --version
21
- # - cd lib/api_browser
22
- # - npm install
23
- # - cd ../..
24
- # script:
25
- # - bundle exec rspec spec
26
- # - cd lib/api_browser
27
- # - npm test
28
- # - cd ../..
13
+ - /.*/
@@ -25,7 +25,7 @@ module Praxis
25
25
  # Defining the existence without any other options can only mean that it is required (otherwise it is a useless definition)
26
26
  options[:required] = true if options.empty?
27
27
  end
28
- key name , String, options
28
+ key name , String, **options
29
29
  end
30
30
 
31
31
  # Override the attribute to really call "key" in the hash (for temporary backwards compat)
@@ -76,7 +76,7 @@ module Praxis
76
76
 
77
77
  def update_attribute(attribute, options, block)
78
78
  attribute.options.merge!(options)
79
- attribute.type.attributes(options, &block)
79
+ attribute.type.attributes(**options, &block)
80
80
  end
81
81
 
82
82
  def response(name, type=nil, **args, &block)
@@ -114,7 +114,7 @@ module Praxis
114
114
 
115
115
  def config(key=nil, type=Attributor::Struct, **opts, &block)
116
116
  if block_given? || (type==Attributor::Struct && !opts.empty? )
117
- @config.define(key, type, opts, &block)
117
+ @config.define(key, type, **opts, &block)
118
118
  else
119
119
  @config.get
120
120
  end
data/lib/praxis/config.rb CHANGED
@@ -54,7 +54,7 @@ module Praxis
54
54
  )
55
55
  end
56
56
  top.options.merge!(opts)
57
- top.type.attributes(opts, &block)
57
+ top.type.attributes(**opts, &block)
58
58
  else
59
59
  @attribute.attributes[key] = Attributor::Attribute.new(type, opts, &block)
60
60
  end
@@ -146,7 +146,8 @@ module Praxis
146
146
  if self.parameters.empty?
147
147
  self
148
148
  else
149
- MediaTypeIdentifier.load(type: self.type, subtype: self.subtype, suffix: self.suffix)
149
+ val = {type: self.type, subtype: self.subtype, suffix: self.suffix}
150
+ MediaTypeIdentifier.load(val)
150
151
  end
151
152
  end
152
153
 
@@ -21,7 +21,7 @@ module Praxis
21
21
  end
22
22
 
23
23
  def self.instrument(name, payload = {}, &block)
24
- ActiveSupport::Notifications.instrument(name, payload, &block)
24
+ ActiveSupport::Notifications.instrument(name, **payload, &block)
25
25
  end
26
26
 
27
27
  def self.subscribe(*args, &block)
@@ -49,7 +49,7 @@ module Praxis
49
49
  unless base_attributes.empty?
50
50
  params do
51
51
  base_attributes.each do |base_name, base_attribute|
52
- attribute base_name, base_attribute.type, base_attribute.options
52
+ attribute base_name, base_attribute.type, **base_attribute.options
53
53
  end
54
54
  end
55
55
  end
@@ -87,9 +87,9 @@ module Praxis
87
87
  @display_name = string
88
88
  end
89
89
 
90
- def on_finalize
90
+ def on_finalize(&block)
91
91
  if block_given?
92
- @on_finalize << Proc.new
92
+ @on_finalize << proc(&block)
93
93
  end
94
94
 
95
95
  @on_finalize
@@ -168,7 +168,7 @@ module Praxis
168
168
 
169
169
  parent_attribute = parent_action.params.attributes[parent_name]
170
170
 
171
- attribute name, parent_attribute.type, parent_attribute.options
171
+ attribute name, parent_attribute.type, **parent_attribute.options
172
172
  end
173
173
  end
174
174
  end
@@ -221,7 +221,7 @@ module Praxis
221
221
  end
222
222
 
223
223
  def to_href( params )
224
- canonical_path.primary_route.path.expand(params)
224
+ canonical_path.primary_route.path.expand(params.transform_values(&:to_s))
225
225
  end
226
226
 
227
227
  def parse_href(path)
data/lib/praxis/route.rb CHANGED
@@ -24,7 +24,7 @@ module Praxis
24
24
  path_params = example_hash.select{|k,v| path_param_keys.include? k }
25
25
  # Let's generate the example only using required params, to avoid mixing incompatible parameters
26
26
  query_params = example_hash.select{|k,v| required_query_param_keys.include? k }
27
- example = { verb: self.verb, url: self.path.expand(path_params), query_params: query_params }
27
+ example = { verb: self.verb, url: self.path.expand(path_params.transform_values(&:to_s)), query_params: query_params }
28
28
 
29
29
  end
30
30
 
@@ -55,7 +55,7 @@ module Praxis
55
55
  path = (base + path).gsub('//','/')
56
56
  # Reject our own options
57
57
  route_name = options.delete(:name);
58
- pattern = Mustermann.new(path, {ignore_unknown_options: true}.merge( options ))
58
+ pattern = Mustermann.new(path, **{ignore_unknown_options: true}.merge( options ))
59
59
  route = Route.new(verb, pattern, version, name: route_name, prefixed_path: prefixed_path, **options)
60
60
  @routes << route
61
61
  route
data/lib/praxis/trait.rb CHANGED
@@ -76,7 +76,7 @@ module Praxis
76
76
  dsl_compiler: ActionDefinition::HeadersDSLCompiler,
77
77
  case_insensitive_load: true
78
78
  }
79
- Attributor::Hash.of(key: String).construct(Proc.new {}, hash_opts)
79
+ Attributor::Hash.of(key: String).construct(Proc.new {}, **hash_opts)
80
80
  else
81
81
  Attributor::Hash.construct(Proc.new {})
82
82
  end
@@ -32,8 +32,8 @@ module Praxis
32
32
  #
33
33
  # @return [String] the string-representation of this type's identifier
34
34
  def identifier(identifier=nil)
35
- return @identifier.to_s unless identifier
36
- (@identifier = MediaTypeIdentifier.load(identifier)).to_s
35
+ return @identifier unless identifier
36
+ @identifier = MediaTypeIdentifier.load(identifier)
37
37
  end
38
38
  end
39
39
 
@@ -12,7 +12,7 @@ module Praxis
12
12
  return value if value.kind_of?(self) || value.nil?
13
13
 
14
14
  unless (value.kind_of?(::String) && ! content_type.nil?)
15
- raise Attributor::CoercionError, context: context, from: value.class, to: self.name, value: value
15
+ raise Attributor::CoercionError.new(context: context, from: value.class, to: self.name, value: value)
16
16
  end
17
17
 
18
18
  headers = {'Content-Type' => content_type}
@@ -14,7 +14,7 @@ module Praxis
14
14
 
15
15
  def update_attribute(attribute, options, block)
16
16
  attribute.options.merge!(options)
17
- attribute.type.attributes(options, &block)
17
+ attribute.type.attributes(**options, &block)
18
18
  end
19
19
 
20
20
  def create_attribute(type=Attributor::Struct, **opts, &block)
@@ -83,7 +83,7 @@ module Praxis
83
83
 
84
84
  self.multiple << name if multiple
85
85
 
86
- compiler = Attributor::DSLCompiler.new(self, opts)
86
+ compiler = Attributor::DSLCompiler.new(self, **opts)
87
87
 
88
88
  if filename
89
89
  filename_attribute = compiler.define('filename', String, required: true)
@@ -218,7 +218,7 @@ module Praxis
218
218
  attr_accessor :preamble
219
219
  attr_reader :content_type
220
220
 
221
- def initialize(content_type: self.class.identifier)
221
+ def initialize(content_type: self.class.identifier.to_s)
222
222
  self.content_type = content_type
223
223
  end
224
224
 
@@ -1,3 +1,3 @@
1
1
  module Praxis
2
- VERSION = '2.0.pre.1'
2
+ VERSION = '2.0.pre.2'
3
3
  end
data/praxis.gemspec CHANGED
@@ -21,11 +21,11 @@ Gem::Specification.new do |spec|
21
21
  spec.executables << 'praxis'
22
22
 
23
23
  spec.add_dependency 'rack', '>= 1'
24
- spec.add_dependency 'mustermann', '>=0', '<=1'
24
+ spec.add_dependency 'mustermann', '>=1.1', '<=2'
25
25
  spec.add_dependency 'activesupport', '>= 3'
26
26
  spec.add_dependency 'mime', '~> 0'
27
- spec.add_dependency 'praxis-blueprints', '~> 3.3'
28
- spec.add_dependency 'attributor', '~> 5.1'
27
+ spec.add_dependency 'praxis-blueprints', '>= 3.4'
28
+ spec.add_dependency 'attributor', '>= 5.4'
29
29
  spec.add_dependency 'thor'
30
30
  spec.add_dependency 'terminal-table', '~> 1.4'
31
31
 
@@ -33,9 +33,9 @@ Gem::Specification.new do |spec|
33
33
  spec.add_development_dependency 'rake', '~> 0.9'
34
34
  spec.add_development_dependency 'rake-notes', '~> 0'
35
35
  if RUBY_PLATFORM !~ /java/
36
- spec.add_development_dependency 'pry', '~> 0'
37
- spec.add_development_dependency 'pry-byebug', '~> 1'
38
- spec.add_development_dependency 'pry-stack_explorer', '~> 0'
36
+ spec.add_development_dependency 'pry'
37
+ spec.add_development_dependency 'pry-byebug'
38
+ spec.add_development_dependency 'pry-stack_explorer'
39
39
  spec.add_development_dependency 'sqlite3', '~> 1'
40
40
  else
41
41
  spec.add_development_dependency 'jdbc-sqlite3'
@@ -281,7 +281,7 @@ describe Praxis::ActionDefinition do
281
281
  subject(:action) { resource_definition.actions[:show] }
282
282
 
283
283
  it 'works' do
284
- expansion = action.primary_route.path.expand(cloud_id:232, id: 2)
284
+ expansion = action.primary_route.path.expand(cloud_id:'232', id: '2')
285
285
  expect(expansion).to eq "/api/clouds/232/instances/2"
286
286
  end
287
287
 
@@ -27,7 +27,7 @@ describe Praxis::Application do
27
27
  end
28
28
 
29
29
  it 'passes the params and block to config' do
30
- ret = app.config(:key, Attributor::Hash, {option: :one}, &myblock)
30
+ ret = app.config(:key, Attributor::Hash, **{option: :one}, &myblock)
31
31
  expect(ret).to eq([:key, Attributor::Hash, {option: :one}, myblock])
32
32
  end
33
33
 
@@ -8,6 +8,7 @@ describe Praxis::Collection do
8
8
  subject!(:collection) do
9
9
  Praxis::Collection.of(member_type)
10
10
  end
11
+ let(:identifier_string) { subject.identifier.to_s }
11
12
 
12
13
  context '.of' do
13
14
  let(:member_type) do
@@ -16,7 +17,7 @@ describe Praxis::Collection do
16
17
  end
17
18
  end
18
19
 
19
- its(:identifier) { should eq 'application/an-awesome-type; type=collection' }
20
+ it { expect(identifier_string).to eq('application/an-awesome-type; type=collection') }
20
21
 
21
22
  it 'sets the collection on the media type' do
22
23
  expect(member_type::Collection).to be(collection)
@@ -34,7 +35,7 @@ describe Praxis::Collection do
34
35
  context 'defined explicitly' do
35
36
  subject(:type) { Volume::Collection }
36
37
  its(:member_type) { should be Volume }
37
- its(:identifier) { should eq 'application/vnd.acme.volumes' }
38
+ it { expect(identifier_string).to eq('application/vnd.acme.volumes') }
38
39
  end
39
40
 
40
41
  context '.member_type' do
@@ -72,12 +72,12 @@ describe Praxis::Config do
72
72
 
73
73
  it 'it is not allowed if its for the top key' do
74
74
  expect{
75
- config.define nil, config_type, config_opts
75
+ config.define nil, config_type, **config_opts
76
76
  }.to raise_error(/You cannot define the top level configuration with a non-Struct type/)
77
77
  end
78
78
 
79
79
  before do
80
- config.define config_key, config_type, config_opts
80
+ config.define config_key, config_type, **config_opts
81
81
  end
82
82
 
83
83
  it 'sets the attribute to the defined type' do
@@ -52,16 +52,6 @@ describe Praxis::MediaType do
52
52
  subject(:address_klass) { address.class }
53
53
 
54
54
  context '#identifier' do
55
- context 'in praxis v0' do
56
- it 'should be a kind of String' do
57
- if Praxis::VERSION =~ /^0/
58
- expect(subject.identifier).to be_kind_of(String)
59
- else
60
- raise 'Please remove this spec which is no longer pertinent'
61
- end
62
- end
63
- end
64
-
65
55
  context 'in praxis v1.0 and beyond' do
66
56
  it 'should be a kind of Praxis::MediaTypeIdentifier' do
67
57
  pending('interface-breaking change') if Praxis::VERSION =~ /^0/
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe Praxis::MiddlewareApp do
4
4
 
5
5
  let(:init_args){ { root: 'here'} }
6
- let(:middleware) { Praxis::MiddlewareApp.for( init_args ) }
6
+ let(:middleware) { Praxis::MiddlewareApp.for( **init_args ) }
7
7
  let(:instance){ middleware.new(target)}
8
8
 
9
9
  context '.for' do
@@ -26,7 +26,14 @@ describe Praxis::RequestStages::Action do
26
26
 
27
27
  context '.execute' do
28
28
  before do
29
- expect(controller).to receive(action_stage.name).with(request.params_hash).and_return(controller_response)
29
+ expect(controller).to receive(action_stage.name) do |args|
30
+ if args
31
+ expect(args).to eq({})
32
+ else
33
+ expect(args).to eq(nil)
34
+ end
35
+ end.and_return(controller_response)
36
+
30
37
  end
31
38
  let(:controller_response){ controller.response }
32
39
 
@@ -448,7 +448,7 @@ describe Praxis::ResponseDefinition do
448
448
  context 'with legacy multipart response' do
449
449
  subject(:response) { Praxis::Responses::Ok.new(status: response_status, headers: response_headers) }
450
450
 
451
- let(:part) { Praxis::MultipartPart.new('done', {'Status' => 200, 'Content-Type' => 'application/special'},{}) }
451
+ let(:part) { Praxis::MultipartPart.new('done', {'Status' => 200, 'Content-Type' => 'application/special'},**{}) }
452
452
 
453
453
  before do
454
454
  response_definition.parts like: :ok, media_type: 'application/special'
@@ -463,7 +463,7 @@ describe Praxis::ResponseDefinition do
463
463
  end
464
464
 
465
465
  context 'with invalid part' do
466
- let(:part) { Praxis::MultipartPart.new('done', {'Status' => 200, "Location" => "somewhere"},{}) }
466
+ let(:part) { Praxis::MultipartPart.new('done', {'Status' => 200, "Location" => "somewhere"}) }
467
467
 
468
468
  it 'validates' do
469
469
  expect {
@@ -494,6 +494,7 @@ describe Praxis::ResponseDefinition do
494
494
  let(:location) { %r{/my/url/} }
495
495
  let(:headers) { {'Header1' => 'Value1'} }
496
496
  let(:parts) { nil }
497
+ let(:parts_block) { nil }
497
498
 
498
499
  let(:response) do
499
500
  Praxis::ResponseDefinition.new(:custom) do
@@ -505,7 +506,9 @@ describe Praxis::ResponseDefinition do
505
506
  before do
506
507
  response.description(description) if description
507
508
  response.location(location) if location
508
- response.parts(parts) if parts
509
+ if parts || parts_block
510
+ parts ? response.parts(nil, **parts, &parts_block) : response.parts(nil, &parts_block)
511
+ end
509
512
  response.headers(headers) if headers
510
513
  end
511
514
 
@@ -572,7 +575,7 @@ describe Praxis::ResponseDefinition do
572
575
  its([:status]){ should == 200 }
573
576
  end
574
577
  context 'using a full response definition block' do
575
- let(:parts) do
578
+ let(:parts_block) do
576
579
  Proc.new do
577
580
  status 234
578
581
  media_type 'custom_media'
@@ -117,7 +117,7 @@ describe Praxis::Response do
117
117
  end
118
118
 
119
119
  context 'multipart responses' do
120
- let(:part) { Praxis::MultipartPart.new('not so ok', {'Status' => 400, "Location" => "somewhere"}, {}) }
120
+ let(:part) { Praxis::MultipartPart.new('not so ok', {'Status' => 400, "Location" => "somewhere"}) }
121
121
 
122
122
  context '#add_part' do
123
123
 
@@ -6,7 +6,7 @@ describe Praxis::Router do
6
6
  let(:action){ double("action", resource_definition: resource_definition ) }
7
7
  let(:target){ double("target", action: action ) }
8
8
  let(:args){ {version: "1.0"} }
9
- subject(:matcher){ Praxis::Router::VersionMatcher.new(target,args) }
9
+ subject(:matcher){ Praxis::Router::VersionMatcher.new(target,**args) }
10
10
 
11
11
  context '.initialize' do
12
12
  let(:args){ {} }
@@ -73,7 +73,7 @@ class Instances < BaseClass
73
73
 
74
74
  headers = {
75
75
  'Status' => '201',
76
- 'Content-Type' => Instance.identifier + '+json',
76
+ 'Content-Type' => (Instance.identifier + '+json').to_s,
77
77
  'Location' => definition.to_href(cloud_id: cloud_id, id: instance.id)
78
78
  }
79
79
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: praxis
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.pre.1
4
+ version: 2.0.pre.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josep M. Blanquer
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-02-22 00:00:00.000000000 Z
12
+ date: 2020-05-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
@@ -31,20 +31,20 @@ dependencies:
31
31
  requirements:
32
32
  - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: '0'
34
+ version: '1.1'
35
35
  - - "<="
36
36
  - !ruby/object:Gem::Version
37
- version: '1'
37
+ version: '2'
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
41
  requirements:
42
42
  - - ">="
43
43
  - !ruby/object:Gem::Version
44
- version: '0'
44
+ version: '1.1'
45
45
  - - "<="
46
46
  - !ruby/object:Gem::Version
47
- version: '1'
47
+ version: '2'
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: activesupport
50
50
  requirement: !ruby/object:Gem::Requirement
@@ -77,30 +77,30 @@ dependencies:
77
77
  name: praxis-blueprints
78
78
  requirement: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: '3.3'
82
+ version: '3.4'
83
83
  type: :runtime
84
84
  prerelease: false
85
85
  version_requirements: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - "~>"
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: '3.3'
89
+ version: '3.4'
90
90
  - !ruby/object:Gem::Dependency
91
91
  name: attributor
92
92
  requirement: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - "~>"
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
- version: '5.1'
96
+ version: '5.4'
97
97
  type: :runtime
98
98
  prerelease: false
99
99
  version_requirements: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - "~>"
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
- version: '5.1'
103
+ version: '5.4'
104
104
  - !ruby/object:Gem::Dependency
105
105
  name: thor
106
106
  requirement: !ruby/object:Gem::Requirement
@@ -175,42 +175,42 @@ dependencies:
175
175
  name: pry
176
176
  requirement: !ruby/object:Gem::Requirement
177
177
  requirements:
178
- - - "~>"
178
+ - - ">="
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0'
181
181
  type: :development
182
182
  prerelease: false
183
183
  version_requirements: !ruby/object:Gem::Requirement
184
184
  requirements:
185
- - - "~>"
185
+ - - ">="
186
186
  - !ruby/object:Gem::Version
187
187
  version: '0'
188
188
  - !ruby/object:Gem::Dependency
189
189
  name: pry-byebug
190
190
  requirement: !ruby/object:Gem::Requirement
191
191
  requirements:
192
- - - "~>"
192
+ - - ">="
193
193
  - !ruby/object:Gem::Version
194
- version: '1'
194
+ version: '0'
195
195
  type: :development
196
196
  prerelease: false
197
197
  version_requirements: !ruby/object:Gem::Requirement
198
198
  requirements:
199
- - - "~>"
199
+ - - ">="
200
200
  - !ruby/object:Gem::Version
201
- version: '1'
201
+ version: '0'
202
202
  - !ruby/object:Gem::Dependency
203
203
  name: pry-stack_explorer
204
204
  requirement: !ruby/object:Gem::Requirement
205
205
  requirements:
206
- - - "~>"
206
+ - - ">="
207
207
  - !ruby/object:Gem::Version
208
208
  version: '0'
209
209
  type: :development
210
210
  prerelease: false
211
211
  version_requirements: !ruby/object:Gem::Requirement
212
212
  requirements:
213
- - - "~>"
213
+ - - ">="
214
214
  - !ruby/object:Gem::Version
215
215
  version: '0'
216
216
  - !ruby/object:Gem::Dependency