luna_park 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.overcommit.yml +18 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +106 -0
  6. data/.ruby-gemset +1 -0
  7. data/.ruby-version +1 -0
  8. data/.travis.yml +6 -0
  9. data/CHANGELOG.md +308 -0
  10. data/Gemfile +8 -0
  11. data/Gemfile.lock +182 -0
  12. data/LICENSE +21 -0
  13. data/LICENSE.txt +21 -0
  14. data/README.md +54 -0
  15. data/Rakefile +30 -0
  16. data/bin/console +15 -0
  17. data/bin/setup +8 -0
  18. data/docs/.nojekyll +0 -0
  19. data/docs/CNAME +1 -0
  20. data/docs/README.md +190 -0
  21. data/docs/_coverpage.md +18 -0
  22. data/docs/_imgs/adapter.png +0 -0
  23. data/docs/_imgs/bender.jpeg +0 -0
  24. data/docs/_imgs/bender_header.jpeg +0 -0
  25. data/docs/_imgs/collecting.png +0 -0
  26. data/docs/_imgs/conductor_schema.png +0 -0
  27. data/docs/_imgs/ddd_header.jpeg +0 -0
  28. data/docs/_imgs/ddd_map.png +0 -0
  29. data/docs/_imgs/domain_context.jpeg +0 -0
  30. data/docs/_imgs/drunk_master.jpg +0 -0
  31. data/docs/_imgs/full_map.png +0 -0
  32. data/docs/_imgs/full_map_hight_res.png +0 -0
  33. data/docs/_imgs/graph_1.png +0 -0
  34. data/docs/_imgs/graph_2.jpg +0 -0
  35. data/docs/_imgs/graph_3.png +0 -0
  36. data/docs/_imgs/graph_4.jpg +0 -0
  37. data/docs/_imgs/graph_5.jpg +0 -0
  38. data/docs/_imgs/graph_5.png +0 -0
  39. data/docs/_imgs/processing.png +0 -0
  40. data/docs/_imgs/representation.png +0 -0
  41. data/docs/_imgs/storage.png +0 -0
  42. data/docs/_imgs/tourtle_context_map.png +0 -0
  43. data/docs/_imgs/tree.png +0 -0
  44. data/docs/_imgs/wm.jpeg +0 -0
  45. data/docs/_media/bender.jpg +0 -0
  46. data/docs/_media/black_cover.jpg +0 -0
  47. data/docs/_media/logo.svg +7 -0
  48. data/docs/_sidebar.md +9 -0
  49. data/docs/architecture.md +214 -0
  50. data/docs/google48f1e6f5c35eae5f.html +1 -0
  51. data/docs/index.html +32 -0
  52. data/docs/methodology.md +376 -0
  53. data/docs/patterns/entity.md +193 -0
  54. data/docs/patterns/sequence.md +332 -0
  55. data/docs/patterns/service.md +280 -0
  56. data/docs/patterns/value.md +197 -0
  57. data/docs/way.md +66 -0
  58. data/lib/luna_park.rb +72 -0
  59. data/lib/luna_park/callable.rb +7 -0
  60. data/lib/luna_park/entities/attributable.rb +18 -0
  61. data/lib/luna_park/entities/nested.rb +28 -0
  62. data/lib/luna_park/entities/simple.rb +39 -0
  63. data/lib/luna_park/errors.rb +16 -0
  64. data/lib/luna_park/errors/base.rb +244 -0
  65. data/lib/luna_park/errors/business.rb +9 -0
  66. data/lib/luna_park/errors/http.rb +90 -0
  67. data/lib/luna_park/errors/json_parse.rb +11 -0
  68. data/lib/luna_park/errors/system.rb +9 -0
  69. data/lib/luna_park/extensions/attributable.rb +26 -0
  70. data/lib/luna_park/extensions/callable.rb +44 -0
  71. data/lib/luna_park/extensions/comparable.rb +90 -0
  72. data/lib/luna_park/extensions/comparable_debug.rb +96 -0
  73. data/lib/luna_park/extensions/data_mapper.rb +195 -0
  74. data/lib/luna_park/extensions/dsl/attributes.rb +135 -0
  75. data/lib/luna_park/extensions/dsl/foreign_key.rb +97 -0
  76. data/lib/luna_park/extensions/exceptions/substitutive.rb +83 -0
  77. data/lib/luna_park/extensions/has_errors.rb +125 -0
  78. data/lib/luna_park/extensions/injector.rb +189 -0
  79. data/lib/luna_park/extensions/injector/dependencies.rb +74 -0
  80. data/lib/luna_park/extensions/predicate_attr_accessor.rb +23 -0
  81. data/lib/luna_park/extensions/repositories/postgres/create.rb +20 -0
  82. data/lib/luna_park/extensions/repositories/postgres/delete.rb +15 -0
  83. data/lib/luna_park/extensions/repositories/postgres/read.rb +63 -0
  84. data/lib/luna_park/extensions/repositories/postgres/update.rb +21 -0
  85. data/lib/luna_park/extensions/serializable.rb +99 -0
  86. data/lib/luna_park/extensions/severity_levels.rb +120 -0
  87. data/lib/luna_park/extensions/typed_attr_accessor.rb +26 -0
  88. data/lib/luna_park/extensions/validatable.rb +80 -0
  89. data/lib/luna_park/extensions/validatable/dry.rb +24 -0
  90. data/lib/luna_park/extensions/wrappable.rb +43 -0
  91. data/lib/luna_park/forms/simple.rb +63 -0
  92. data/lib/luna_park/forms/single_item.rb +74 -0
  93. data/lib/luna_park/handlers/simple.rb +17 -0
  94. data/lib/luna_park/http/client.rb +328 -0
  95. data/lib/luna_park/http/request.rb +225 -0
  96. data/lib/luna_park/http/response.rb +381 -0
  97. data/lib/luna_park/http/send.rb +103 -0
  98. data/lib/luna_park/mappers/simple.rb +92 -0
  99. data/lib/luna_park/notifiers/bugsnag.rb +48 -0
  100. data/lib/luna_park/notifiers/log.rb +174 -0
  101. data/lib/luna_park/notifiers/sentry.rb +50 -0
  102. data/lib/luna_park/repositories/postgres.rb +38 -0
  103. data/lib/luna_park/repositories/sequel.rb +11 -0
  104. data/lib/luna_park/repository.rb +9 -0
  105. data/lib/luna_park/serializers/simple.rb +28 -0
  106. data/lib/luna_park/tools.rb +19 -0
  107. data/lib/luna_park/use_cases/scenario.rb +325 -0
  108. data/lib/luna_park/use_cases/service.rb +13 -0
  109. data/lib/luna_park/validators/dry.rb +67 -0
  110. data/lib/luna_park/values/attributable.rb +21 -0
  111. data/lib/luna_park/values/compound.rb +26 -0
  112. data/lib/luna_park/values/single.rb +35 -0
  113. data/lib/luna_park/version.rb +5 -0
  114. data/luna_park.gemspec +54 -0
  115. data/node_modules/.yarn-integrity +12 -0
  116. data/package-lock.json +3 -0
  117. data/yarn.lock +4 -0
  118. metadata +414 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a527e6fff5165d27583a34caaab2543148c3119b895f95898eefe80be7dca8c6
4
+ data.tar.gz: fc6f47bc87abfead803c5b1d78a6cd76d0450e28637649517394abf8b0fa71a6
5
+ SHA512:
6
+ metadata.gz: dfb1d4351d12c017c055b67a4f2bcedba375b52bb755d1deeef5a268f0d6fc521ff458b9c37f1f57bec5c3f2cbe842e6fcc6b11a3bff5105b2d20600f27053a1
7
+ data.tar.gz: 73e4f163196f1a79616e76cb689be7a369b2c5be1d2a6e20db3d02df0ac83dffaba97a3be1a9a762dd4d799519d448edd8085d15993d045f9f245b8a4c5d9fb8
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/.overcommit.yml ADDED
@@ -0,0 +1,18 @@
1
+ PreCommit:
2
+ Spec:
3
+ enabled: true
4
+ RuboCop:
5
+ enabled: true
6
+ on_warn: fail # Treat all warnings as failures
7
+
8
+ PostCheckout:
9
+ ALL:
10
+ enabled: false
11
+
12
+ PostCommit:
13
+ ALL:
14
+ enabled: false
15
+
16
+ PrePush:
17
+ RSpec:
18
+ enabled: true
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,106 @@
1
+ ##
2
+ # Bug with Travis rubocop and rainbow gem
3
+ # resolve:
4
+ # https://github.com/rubocop-hq/rubocop/issues/6398#issuecomment-431898694
5
+ inherit_mode:
6
+ merge:
7
+ - Exclude
8
+
9
+ AllCops:
10
+ TargetRubyVersion: 2.5
11
+ Exclude:
12
+ - '**/tmp/**/*'
13
+ - '**/script/**/*'
14
+ - Rakefile
15
+ - 'bin/*'
16
+ UseCache: true
17
+
18
+ Metrics/LineLength:
19
+ Max: 120
20
+ IgnoredPatterns: ['\s*\#\s.*$']
21
+ Exclude:
22
+ - 'spec/**/*'
23
+
24
+ # Configuration parameters: CountComments.
25
+ Metrics/MethodLength:
26
+ Exclude:
27
+ - 'spec/**/*'
28
+
29
+ Metrics/ModuleLength:
30
+ Exclude:
31
+ - 'spec/**/*'
32
+
33
+ Metrics/BlockLength:
34
+ Exclude:
35
+ - 'spec/**/*'
36
+ - 'luna_park.gemspec'
37
+
38
+ Style/AsciiComments:
39
+ Enabled: false
40
+
41
+ Lint/AmbiguousBlockAssociation:
42
+ Exclude:
43
+ - 'spec/**/*'
44
+
45
+ Style/Attr:
46
+ Enabled: false
47
+
48
+ # TODO: убрать/изменить правило
49
+ Style/Documentation:
50
+ Enabled: false
51
+
52
+ Naming/MethodParameterName:
53
+ AllowedNames: io, id, to, by, on, in, at, ip, db, pk, fk
54
+
55
+ # TODO: поговорить с Филиппом про attr
56
+ Layout/EmptyLinesAroundAttributeAccessor:
57
+ Enabled: false
58
+
59
+ Layout/SpaceAroundMethodCallOperator:
60
+ Enabled: true
61
+
62
+ Lint/DeprecatedOpenSSLConstant:
63
+ Enabled: true
64
+
65
+ Lint/MixedRegexpCaptureTypes:
66
+ Enabled: true
67
+
68
+ Lint/RaiseException:
69
+ Enabled: true
70
+
71
+ Lint/StructNewOverride:
72
+ Enabled: true
73
+
74
+ # TODO: поговорить с Филиппом про attr
75
+ Style/AccessorGrouping:
76
+ Enabled: false
77
+
78
+ Style/BisectedAttrAccessor:
79
+ Enabled: true
80
+
81
+ Style/ExponentialNotation:
82
+ Enabled: true
83
+
84
+ Style/HashEachMethods:
85
+ Enabled: true
86
+
87
+ Style/HashTransformKeys:
88
+ Enabled: true
89
+
90
+ Style/HashTransformValues:
91
+ Enabled: true
92
+
93
+ Style/RedundantAssignment:
94
+ Enabled: true
95
+
96
+ Style/RedundantFetchBlock:
97
+ Enabled: true
98
+
99
+ Style/RedundantRegexpCharacterClass:
100
+ Enabled: true
101
+
102
+ Style/RedundantRegexpEscape:
103
+ Enabled: true
104
+
105
+ Style/SlicingWithRange:
106
+ Enabled: true
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ luna_park
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.5.1
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.5.1
6
+ before_install: gem install bundler -v 1.17.1
data/CHANGELOG.md ADDED
@@ -0,0 +1,308 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [0.11.0] - 2021-03-18
8
+ Changed
9
+ - Rename Interactors to UseCases
10
+ - Rename Errors::Adaptive to Errors:Base
11
+ - Rename Errors::Processing to Errors::Business
12
+ Added
13
+ - Add class Errors::System
14
+ - Add class UseCase::Service
15
+ - Add class Extensions::HasError
16
+ Removed
17
+ - `on_error action:` instead of use Errors::Business and Errors::System directly
18
+
19
+ ## [0.10.8] - 2021-02-09
20
+ Added
21
+ - Add sentry notifier
22
+
23
+ ## [0.10.7] - 2021-02-05
24
+ Fixed
25
+ - Errors::Processing now has right default `notify` and `on_error`
26
+
27
+ ## [0.10.5] - 2021-01-15
28
+ Added
29
+ - Errors::Adaptive configurations like .message, .on_error will work with inheritance now
30
+
31
+ ## [0.10.5] - 2021-01-15
32
+ Added
33
+ - default message in Errors::Adaptive now can be generated with details usage, when message defined with block
34
+ ```
35
+ class WrongAnswerError < LunaPark::Errors::Adaptive
36
+ message { |d| "Answer is `#{d[:correct]}` - not `#{d[:wrong]}`" }
37
+ end
38
+ ```
39
+ - i18n messages in Errors::Adaptive now can use i18n interpolation
40
+ ```
41
+ de:
42
+ errors:
43
+ wrong_answer: Die richtige Antwort ist %{correct}, nicht %{wrong}
44
+ ```
45
+
46
+ ## [0.10.4] - 2020-11-16
47
+ Added
48
+ - Add injector method
49
+
50
+ ## [0.10.0] - 2020-09-22
51
+ Added
52
+ - Add adaptive errors
53
+ - Add new http client
54
+ - Add new type of interactor - Scenario
55
+ - Add new pattern Notifier, with logger & bugsnag implementation
56
+ - Add new extensions of repositories: CRUD
57
+ - Add `rake console` command
58
+ Fixed
59
+ - Codependent gems can be requested if they are installed with the correct version number
60
+
61
+ ## [0.9.0]
62
+ Was experimental and didn't make it to the master branch
63
+
64
+ ## [0.8.5] - 2019-07-12
65
+ Added
66
+ - Extensions::Attributable and Extensions::Serializable now can not duplicate attribute names
67
+
68
+ ## [0.8.4] - 2019-07-10
69
+ Added
70
+ - Extensions::Exceptions::Substitutive, that allows you to substitute
71
+ origin exception with custom exception and save backtrace of origin.
72
+ In other case information of origin exception will be losed,
73
+ that can be very painfull when something goes wrong.
74
+
75
+ ## [0.8.3] - 2019-07-10
76
+ Added
77
+ - method Interactors::Sequence#failure that returns catched Processing exception object
78
+
79
+ ## [0.8.1] - 2019-06-18
80
+ Added
81
+ - Extensions::DataMapper for implement Repository for concrete Entity
82
+ - Repositories::Sequel that uses Extensions::DataMapper
83
+
84
+ ## [0.8.0] - 2019-06-17
85
+ Update dry validations 0.13 to 1.1
86
+
87
+ ## [0.7.0] - 2019-05-30
88
+ Simplify interactors
89
+
90
+ ### Changed
91
+ - UseCases::Service - removed, instead of this methods use
92
+ `extend Extensions::Callable` or `LunaPark::Callable`
93
+ ```ruby
94
+ # Deprecated
95
+ class YourService < LunaPark::UseCases::Service
96
+ private
97
+ def execute
98
+ # your logic there
99
+ end
100
+ end
101
+
102
+ # Use
103
+ class YourService
104
+ extend Extensions::Callable
105
+
106
+ def call
107
+ # your logic there
108
+ end
109
+ end
110
+
111
+ # Or
112
+
113
+ class YourService < LunaPark::Callable
114
+ def call
115
+ # your logic there
116
+ end
117
+ end
118
+ ```
119
+
120
+ - UseCases::Command - removed, instead of this methods use
121
+ `extend Extensions::Callable` or `LunaPark::Callable`
122
+ ```ruby
123
+ # Deprecated
124
+ class YourCommand < LunaPark::UseCases::Command
125
+ private
126
+ def execute
127
+ # your logic there
128
+ end
129
+ end
130
+
131
+ # Use
132
+ class YourCommand
133
+ extend Extensions::Callable
134
+
135
+ def call
136
+ # your logic there
137
+ true
138
+ end
139
+ end
140
+
141
+ # Or
142
+
143
+ class YourCommand < LunaPark::Callable
144
+ def call
145
+ # your logic there
146
+ true
147
+ end
148
+ end
149
+ ```
150
+
151
+ - method `execute` at `Interactors::Sequnce` is removed, instead of this methods use `call!`
152
+
153
+ - method `returned_data` is removed, instead of this methods return data at `call!`
154
+
155
+ ```ruby
156
+ # Deprecated
157
+ class YourSequence < LunaPark::Intractors::Sequence
158
+ private
159
+ def execute
160
+ # your logic there
161
+ end
162
+
163
+ def returned_data
164
+ { foo: :bar }
165
+ end
166
+ end
167
+
168
+ # Use
169
+ class YourSequence < LunaPark::Intractors::Sequence
170
+ def call!
171
+ # your logic there
172
+ { foo: :bar }
173
+ end
174
+ end
175
+ ```
176
+
177
+ # Added
178
+ - callback method `on_fail` at `Interactors::Sequence`
179
+
180
+ ```ruby
181
+ class YourSequence < LunaPark::Intractors::Sequence
182
+ def call!
183
+ raise Errors::Processing
184
+ end
185
+
186
+ private
187
+
188
+ def on_fail
189
+ puts 'foobar'
190
+ end
191
+ end
192
+
193
+ i = YourSequence.call
194
+
195
+ #=> foobar
196
+
197
+ ```
198
+
199
+ ## [0.6.2] - 2019-05-03
200
+ ### Changed
201
+ - Extensions::Attributable now uses `#each_pair` instead of `#each`
202
+
203
+ ## [0.6.1] - 2019-04-17
204
+ - DSL `.fk`, `.foreign_key` method now can be reloaded with usage `super` (before the `super` was not available)
205
+
206
+ ## [0.6.0] - 2019-04-17
207
+ ### Internal changes
208
+ Moved to modules:
209
+ - Extensions::Wrappable adds `.wrap`
210
+ - Extensions::Serializable adds `#to_h` and `#serialize` as alias
211
+ - Extensions::Comparable adds `#==` and `#eql?`
212
+ - Extensions::Dsl::Attributes adds `.attr .attrs .attr? .attrs?` DSL methods
213
+ - optionaly works in synergy with Extensions::Serializable and Extensions::Comparable
214
+
215
+ ### Added
216
+ - YARDoc
217
+ - Extensions::Dsl::ForeignKey adds `.foreign_key` for create foreign key accessor with ergonomically-related object acessor. Has `.fk` as shorter variant (not alias)
218
+ - Entities::Attributable (Entities::Simple with included Extensions::Comparable, Extensions::Serializable, Extensions::Dsl::Attributes)
219
+ - Values::Attributable (Values::Simple with included Extensions::Comparable, Extensions::Serializable, Extensions::Dsl::Attributes)
220
+ - DSL `.attr` can create typed arrays by option `array: true`
221
+ - Some meaningfull exceptions when library used wrong
222
+ - Extensions::ComparableDebug#detailed_differences method that returns only differences
223
+ (#differences_structure renamed to #detailed_comparsion with alias #detailed_cmp)
224
+ - Extensions::Comparable adds `#enable_debug` and `.enable_debug` that just includes `Extensions::ComparableDebug` to current class
225
+ has aliases `#debug`, `.debug`
226
+ - Extensions::PredicateAttribute adds `#predicate_attr_reader`, `#predicate_attr_accessor` and aliased `#attr_reader?`, `#artr_accessor?`
227
+ - Extensions::TypedAttribute adds `#typed_attr_writer`, `#typed_attr_accessor`
228
+
229
+ ### Fixed
230
+ - DSL `.namespace` method now can be reloaded with using `super` (before the `super` was not available)
231
+ - `#to_h`, `#==` from Extensions::Serializable and Extensions::Comparable now works fine in inverited classes
232
+ - Values::Single now will be serialized too when you will try send #to_h to aggregate, included Values::Single instance
233
+
234
+ ### Changed
235
+ - ComparableDebug#detailed_comparsion renamed from #differences_structure.
236
+ (Now available: #detailed_differences and #detailed_comparsion
237
+ with aliases: #detailed_diff and #detailed_cmp)
238
+
239
+ ## [0.5.9] - 2019-04-09
240
+ ### Added
241
+ - `Extensions::Validateable::Dry` - same as normal `Validateable`, but method `.validator` can receive block
242
+ to create anonymous validator `Validator::Dry` (block will be passed to .validation_schema of new validator)
243
+ - `Extensions::Validateable.validator` now can be setter (when arguments given) and getter (without args)
244
+
245
+ ## [0.5.8] - 2019-04-09
246
+ ### Changed
247
+ - Validateable renamed to Validatable (without backward compatibility)
248
+ - Validator`#valid?` DEPRECATED, use `#success?` instead
249
+ - Validator`#validation_errors?` DEPRECATED, use `#errors` instead
250
+
251
+ ### Added
252
+ - Extensions::Validatable`#valid?` `#validation_errors` `#valid_params` now can work without defined `.validator`
253
+
254
+ ## [0.5.7] - 2019-03-20
255
+ ### Added
256
+ - `Forms::Simple`
257
+
258
+ ## [0.5.6] - 2019-03-19
259
+ ### Added
260
+ - Form example comment
261
+
262
+ ### Changed
263
+ - `Form#complete!` renamed to `#submit` (#complete! removed)
264
+ - `Validatable#validate!` removed
265
+
266
+ ## [0.5.5] - 2019-03-13
267
+ ### Added
268
+ - LunaPark::Mappers::Simple
269
+
270
+ ### Changed
271
+ - LunaPark::Extensions::Attributable#set_attributes now returns `self` - not given Hash
272
+
273
+ ## [0.5.4] - 2019-02-05
274
+ ### Added
275
+ - Change error message for `.wrap` from `Can't wrap OtherClass` to `MyClass can't wrap OtherClass`
276
+
277
+ ## [0.5.1] - 2018-01-14
278
+ ### Added
279
+ - This CHANGELOG
280
+ - Renamed ValueObject::Simple -> ValueObject::Single
281
+
282
+ ### Changed
283
+ - RUS Guideline: Entity - improve orthography and punctuation
284
+ - RUS Guideline: Value - improve orthography and punctuation
285
+ - RUS Guideline: Way - improve orthography and punctuation
286
+
287
+ ## [0.5.0] - 2018-12-30
288
+ ### Added
289
+ - Nested Entity
290
+ - Simple Entity
291
+ - Single item Form
292
+ - Simple Handler
293
+ - Sequence Interactor
294
+ - Simple Serializer
295
+ - Service Use Case
296
+ - Command Use Case
297
+ - Dry Validator
298
+ - Compound Value
299
+ - Single Value
300
+ - RUS Guideline: Implementation area
301
+ - RUS Guideline: Methodology
302
+ - RUS Guideline: Architecture
303
+ - RUS Guideline: The Way
304
+ - RUS Guideline: ValueObject
305
+ - RUS Guideline: Entity
306
+ - RUS Guideline: Sequence
307
+ - RUS Guideline: Services
308
+ - RUS Guideline: Value