haveapi 0.22.1 → 0.23.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3d886505aa1e12970c014a30cd9b51aecb7b97218c62d4b86069c397d2979a69
4
- data.tar.gz: 4c33b3e2c9fd695737163e00bb1dfe04799356a06591a8cecb6b1d27e675975b
3
+ metadata.gz: 6c66cdf4f10a5d8d65b70c4d934cd4ab98b96d89fd5af283cdd1d0cd21cbb4b8
4
+ data.tar.gz: d3beeb71e1da7049735864c44e76abdd512fe22fbec0df056d10f2f0ad9dc409
5
5
  SHA512:
6
- metadata.gz: 41837c1ac3eba812bf548cc00edb86f7ff7d9b6af63acbf07ba475027a099300f7a7c2109682e2108dd501b8a51d381625b1f308bee4b580ee49644894d97b57
7
- data.tar.gz: 6b1b487e12e28912230a37c327de0863056931203574e5fd0d35096c61d3dbf5018af7846d2cee9116c53f442adb799497f1b803b9609599076b0fd065287f95
6
+ metadata.gz: a139c2b9bfc85f476a77c8e113d8e9d769dc505261028d807a4804dc108e1dee07dfa65f54220988b28bc78d4893fde0cbad37fee9e0eae01d697a3c58719b88
7
+ data.tar.gz: 18525da72a705a5bd8f955b5597f87035bde722fe3520abd2db09e6fac9066cb01eafffb39dbc1f480504568b60852388144e4245861a3d2d2590ba69f7eb790
data/haveapi.gemspec CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
16
16
 
17
17
  s.add_runtime_dependency 'activesupport', '>= 7.1'
18
18
  s.add_runtime_dependency 'github-markdown'
19
- s.add_runtime_dependency 'haveapi-client', '~> 0.22.1'
19
+ s.add_runtime_dependency 'haveapi-client', '~> 0.23.0'
20
20
  s.add_runtime_dependency 'json'
21
21
  s.add_runtime_dependency 'mail'
22
22
  s.add_runtime_dependency 'nesty', '~> 1.0'
@@ -147,15 +147,12 @@ module HaveAPI::ClientExamples
147
147
  end
148
148
 
149
149
  def format_parameters(dir, params, prefix = '')
150
- ret = []
151
-
152
- params.each do |k, v|
153
- ret << if action[dir][:parameters][k][:type] == 'Custom'
154
- "#{prefix} \"#{k}\" => custom type}"
155
-
156
- else
157
- "#{prefix} \"#{k}\" => #{value(v)}"
158
- end
150
+ ret = params.map do |k, v|
151
+ if action[dir][:parameters][k][:type] == 'Custom'
152
+ "#{prefix} \"#{k}\" => custom type}"
153
+ else
154
+ "#{prefix} \"#{k}\" => #{value(v)}"
155
+ end
159
156
  end
160
157
 
161
158
  "#{prefix}[\n#{ret.join(",\n")}\n#{prefix}]"
@@ -116,7 +116,7 @@ module HaveAPI
116
116
  cls
117
117
  end
118
118
 
119
- def self.define_action(name, superclass: Action, &block)
119
+ def self.define_action(name, superclass: Action, &)
120
120
  return false if const_defined?(name)
121
121
 
122
122
  cls = Class.new(superclass)
@@ -124,7 +124,7 @@ module HaveAPI
124
124
  cls.resource = self
125
125
  cls.action_name = name
126
126
  superclass.delayed_inherited(cls)
127
- cls.class_exec(&block)
127
+ cls.class_exec(&)
128
128
  end
129
129
  end
130
130
  end
@@ -61,7 +61,6 @@ module HaveAPI::Resources
61
61
  authorize { allow }
62
62
 
63
63
  def exec
64
- ret = []
65
64
  actions = @context.server.action_state.list_pending(
66
65
  current_user,
67
66
  input[:offset],
@@ -69,11 +68,9 @@ module HaveAPI::Resources
69
68
  input[:order].to_sym
70
69
  )
71
70
 
72
- actions.each do |state|
73
- ret << state_to_hash(state)
71
+ actions.map do |state|
72
+ state_to_hash(state)
74
73
  end
75
-
76
- ret
77
74
  end
78
75
  end
79
76
 
@@ -11,6 +11,20 @@ module HaveAPI
11
11
 
12
12
  include Hookable
13
13
 
14
+ has_hook :pre_mount,
15
+ desc: 'Called before API actions are mounted in sinatra',
16
+ args: {
17
+ server: 'HaveAPI::Server',
18
+ sinatra: 'Sinatra::Base'
19
+ }
20
+
21
+ has_hook :post_mount,
22
+ desc: 'Called after API actions are mounted in sinatra',
23
+ args: {
24
+ server: 'HaveAPI::Server',
25
+ sinatra: 'Sinatra::Base'
26
+ }
27
+
14
28
  # Called after the user was authenticated (or not). The block is passed
15
29
  # current user object or nil as an argument.
16
30
  has_hook :post_authenticated,
@@ -339,12 +353,16 @@ module HaveAPI
339
353
 
340
354
  @extensions.each { |e| e.enabled(self) }
341
355
 
356
+ call_hooks_for(:pre_mount, args: [self, @sinatra])
357
+
342
358
  # Mount default version first
343
359
  mount_version(@root, @default_version)
344
360
 
345
361
  @versions.each do |v|
346
362
  mount_version(version_prefix(v), v)
347
363
  end
364
+
365
+ call_hooks_for(:post_mount, args: [self, @sinatra])
348
366
  end
349
367
 
350
368
  def mount_version(prefix, v)
@@ -8,7 +8,7 @@ module HaveAPI::Spec
8
8
  @v = v
9
9
  end
10
10
 
11
- def call(input, user: nil, &block)
11
+ def call(input, user: nil, &)
12
12
  action = @action.new(nil, @v, input, nil, HaveAPI::Context.new(
13
13
  @server,
14
14
  version: @v,
@@ -26,7 +26,7 @@ module HaveAPI::Spec
26
26
  status, data, errors = action.safe_exec
27
27
  raise(data || 'action failed') unless status
28
28
 
29
- action.instance_exec(@test, &block)
29
+ action.instance_exec(@test, &)
30
30
  data
31
31
  end
32
32
  end
@@ -74,12 +74,12 @@ module HaveAPI::Spec
74
74
  # @param version [any] API version, if not specified, the default version is used
75
75
  # @param user [any] object representing authenticated user
76
76
  # @yield [self] the block is executed in the action instance
77
- def mock_action(r_name, a_name, params, version: nil, user: nil, &block)
77
+ def mock_action(r_name, a_name, params, version: nil, user: nil, &)
78
78
  app
79
79
  v = version || @api.default_version
80
80
  action, path = find_action(v, r_name, a_name)
81
81
  m = MockAction.new(self, @api, action, path, v)
82
- m.call(params, user:, &block)
82
+ m.call(params, user:, &)
83
83
  end
84
84
 
85
85
  # Return parsed API response.
@@ -1,4 +1,4 @@
1
1
  module HaveAPI
2
2
  PROTOCOL_VERSION = '2.0'.freeze
3
- VERSION = '0.22.1'.freeze
3
+ VERSION = '0.23.0'.freeze
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haveapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.22.1
4
+ version: 0.23.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakub Skokan
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.22.1
47
+ version: 0.23.0
48
48
  type: :runtime
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: 0.22.1
54
+ version: 0.23.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: json
57
57
  requirement: !ruby/object:Gem::Requirement