luna_park 0.11.0 → 0.11.1

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: a527e6fff5165d27583a34caaab2543148c3119b895f95898eefe80be7dca8c6
4
- data.tar.gz: fc6f47bc87abfead803c5b1d78a6cd76d0450e28637649517394abf8b0fa71a6
3
+ metadata.gz: 9a850f1f3946c34d92c9f026ffb5f082abdfd066430e8e84e14284b880349cd9
4
+ data.tar.gz: 0ec998104d358ea3d025734ca7a90e4cd9b6e7a1c2d509750d8ae054b2064e74
5
5
  SHA512:
6
- metadata.gz: dfb1d4351d12c017c055b67a4f2bcedba375b52bb755d1deeef5a268f0d6fc521ff458b9c37f1f57bec5c3f2cbe842e6fcc6b11a3bff5105b2d20600f27053a1
7
- data.tar.gz: 73e4f163196f1a79616e76cb689be7a369b2c5be1d2a6e20db3d02df0ac83dffaba97a3be1a9a762dd4d799519d448edd8085d15993d045f9f245b8a4c5d9fb8
6
+ metadata.gz: 702a11e09af39984d694748e7fb5464fa5595433fd5beeb951574074004c8891fd4e095b5087e9b80a4608d0f69ba0e22eddcf57012f8b100bfce76bb664b84f
7
+ data.tar.gz: 0016553ffd33fc1b6073817dedf799acc73c4c37c1ae0eda1e5a8a11188bc3b8c9c96a42fd4f33161d11d3ed7040b7fe26accaeae368ad70c4d543a7ac8f6297
data/.gitignore CHANGED
@@ -1,17 +1 @@
1
- /.idea/
2
- /.bundle/
3
- /.yardoc
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
- /.tmp/
11
- .byebug_history
12
-
13
- # rspec failure tracking
14
- .rspec_status
15
-
16
- # gem builds
17
- *.gem
1
+ g
data/CHANGELOG.md CHANGED
@@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [0.11.1] - 2021-05-24
8
+ Added
9
+ - Inheritance of `Extensions::Injector`
10
+ - Guard and meaningfull exceptions for `Extensions::Injector`
11
+ - nil dependencies caching for `Extensions::Injector`
12
+ - `Http::Client` can accept no-response
13
+ Changed
14
+ - `Forms::Simple` now has default behavior of `#perform`, that returns valid params
15
+
7
16
  ## [0.11.0] - 2021-03-18
8
17
  Changed
9
18
  - Rename Interactors to UseCases
data/Gemfile.lock CHANGED
@@ -104,7 +104,7 @@ GEM
104
104
  http-cookie (>= 1.0.2, < 2.0)
105
105
  mime-types (>= 1.16, < 4.0)
106
106
  netrc (~> 0.8)
107
- rexml (3.2.4)
107
+ rexml (3.2.5)
108
108
  rspec (3.9.0)
109
109
  rspec-core (~> 3.9.0)
110
110
  rspec-expectations (~> 3.9.0)
@@ -70,17 +70,17 @@ module LunaPark
70
70
  request: {
71
71
  method: request.method,
72
72
  url: request.url,
73
- body: request.body,
74
- headers: request.headers,
75
73
  open_timeout: request.open_timeout,
76
74
  read_timeout: request.read_timeout,
77
- sent_at: request.sent_at
75
+ sent_at: request.sent_at,
76
+ headers: request.headers,
77
+ body: request.body
78
78
  },
79
79
  response: {
80
80
  code: response.code,
81
- body: response.body,
82
81
  headers: response.headers,
83
- cookies: response.cookies
82
+ cookies: response.cookies,
83
+ body: response.body
84
84
  },
85
85
  error_details: super
86
86
  }
@@ -108,6 +108,12 @@ module LunaPark
108
108
  end
109
109
 
110
110
  module ClassMethods
111
+ def inherited(inheritor)
112
+ dependencies.each_pair do |key, block|
113
+ inheritor.dependency(key, &block)
114
+ end
115
+ end
116
+
111
117
  ##
112
118
  # Set dependency
113
119
  #
@@ -118,7 +124,9 @@ module LunaPark
118
124
  # dependency(:example) { Bar.new }
119
125
  # end
120
126
  def dependency(name, &block)
121
- dependencies[name] = block
127
+ raise ArgumentError, 'no block given' unless block_given?
128
+
129
+ self.dependencies[name] = block
122
130
 
123
131
  define_method(name) do
124
132
  dependencies.call_with_cache(name)
@@ -48,11 +48,11 @@ module LunaPark
48
48
  # use_case.dependencies[:messenger] # => #<Proc:0x0000564a0d90d438@t.rb:34>
49
49
  # use_case.dependencies.call_with_cache(:messenger) # => 'Foobar'
50
50
  def call_with_cache(key)
51
- cache[key] ||= self[key].call
51
+ cache.key?(key) ? cache[key] : cache[key] = self.fetch(key).call
52
52
  end
53
53
 
54
54
  def []=(key, _val)
55
- cache[key] = nil
55
+ cache.delete(key)
56
56
  super
57
57
  end
58
58
 
@@ -62,13 +62,6 @@ module LunaPark
62
62
  @cache ||= {}
63
63
  end
64
64
  end
65
-
66
- # @!parse include Injector::ClassMethods
67
- # @!parse extend Injector::InstanceMethods
68
- def self.included(base)
69
- base.extend ClassMethods
70
- base.include InstanceMethods
71
- end
72
65
  end
73
66
  end
74
67
  end
@@ -8,22 +8,36 @@ module LunaPark
8
8
  ##
9
9
  # Form object represents blank document, required to filled right, and can be performed
10
10
  #
11
- # @example
11
+ # @example with default behavior
12
12
  # class MyForm < LunaPark::Forms::SingleItem
13
13
  # validation MyValidator # respond to .validate, #valid?, #errors, #valid_params
14
14
  #
15
15
  # def perform(valid_params)
16
- # "Performed #{valid_params[:foo_bar]}"
16
+ # "Performed #{valid_params[:foo]}"
17
17
  # end
18
18
  # end
19
19
  #
20
- # form = MyForm.new({ foo_bar: 'FooBar' })
20
+ # form = MyForm.new({ foo: 'Foo', excess: 'Excess' })
21
21
  #
22
22
  # if form.submit
23
- # form.result # => 'Performed FooBar'
23
+ # form.result # => 'Performed Foo'
24
24
  # else
25
- # form.errors # => { foo_bar: ['is wrong'] }
25
+ # form.errors # => { foo: ['is wrong'] }
26
26
  # end
27
+ #
28
+ # @example without default behavior
29
+ # class MyForm < LunaPark::Forms::SingleItem
30
+ # validation MyValidator # respond to .validate, #valid?, #errors, #valid_params
31
+ # end
32
+ #
33
+ # form = MyForm.new({ foo: 'Foo', excess: 'Excess' })
34
+ #
35
+ # if form.submit
36
+ # form.result # => { foo: 'Foo' }
37
+ # else
38
+ # form.errors # => { foo: ['is wrong'] }
39
+ # end
40
+ #
27
41
  class Simple
28
42
  include Extensions::Validatable
29
43
 
@@ -54,8 +68,8 @@ module LunaPark
54
68
  # :nocov:
55
69
 
56
70
  # @abstract
57
- def perform(_valid_params)
58
- raise Errors::AbstractMethod
71
+ def perform(valid_params)
72
+ valid_params
59
73
  end
60
74
  # :nocov:
61
75
  end
@@ -83,10 +83,10 @@ module LunaPark
83
83
 
84
84
  def build_original_response(rest_response)
85
85
  Response.new(
86
- body: rest_response.body,
87
- code: rest_response.code,
88
- headers: rest_response.headers,
89
- cookies: rest_response.cookies,
86
+ body: rest_response&.body,
87
+ code: rest_response&.code || 0,
88
+ headers: rest_response&.headers,
89
+ cookies: rest_response&.cookies,
90
90
  request: original_request
91
91
  )
92
92
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LunaPark
4
- VERSION = '0.11.0'
4
+ VERSION = '0.11.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: luna_park
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Kudrin
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2021-05-19 00:00:00.000000000 Z
12
+ date: 2021-05-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bugsnag