opisator 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ec49d7b1b3a4e676d313139acdedb26f0f286a8ceed31cc1fe9e645955213fdb
4
+ data.tar.gz: 323e199df02e3a85c05dd8978fcaf80d5213fab089534c92ed11dfb67a9d8f71
5
+ SHA512:
6
+ metadata.gz: 90e617275ceaf0ee2425867604f04165a5d9afe326dafbbec3447dc0ff67e64aa8b5b63b69100f25d454b7b8a2c3ea73a26500462116bade4e19c6722f0e0bf7
7
+ data.tar.gz: 9f1b68952d834aa55ee0ff48d0e9ba19a7c2fe92a1f500120069382dc8b341bc6f300a8f2877c3170bb1cd7ce4a49b2814184397ed10342147063041232b358f
@@ -0,0 +1,9 @@
1
+ module Opisator
2
+ module Defaults
3
+ class Contract
4
+ def call(params)
5
+ params
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Opisator
2
+ module Defaults
3
+ class Interactor
4
+ def call(params)
5
+ params
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ module Opisator
2
+ module Defaults
3
+ class Presenter
4
+ def call(params)
5
+ {
6
+ json: {}
7
+ }
8
+ end
9
+ end
10
+ end
11
+ end
data/lib/opisator.rb ADDED
@@ -0,0 +1,58 @@
1
+ require "active_support/concern"
2
+
3
+ module Opisator
4
+ extend ActiveSupport::Concern
5
+
6
+ attr_accessor :contract
7
+
8
+ included do
9
+ before_action :call
10
+ end
11
+
12
+ class_methods do
13
+ def opisator_for(*actions)
14
+ actions.each { |action| define_method_for action }
15
+ end
16
+
17
+ private def method_by(action)
18
+ "call_#{action}"
19
+ end
20
+
21
+ private def define_method_for(action)
22
+ define_method method_by(action) do
23
+
24
+ @contract = Opisator::Defaults::Contract
25
+ @interactor = Opisator::Defaults::Interactor
26
+ @presenter = Opisator::Defaults::Presenter
27
+
28
+ self.send(action)
29
+
30
+ contract_params = @contract.new.call(params)
31
+
32
+ result = @interactor.new.call(contract_params)
33
+
34
+ render @presenter.new.call(result)
35
+ end
36
+ end
37
+ end
38
+
39
+ def call
40
+ return self.send(action_name) unless has_call_method?
41
+
42
+ self.send(call_method)
43
+ end
44
+
45
+ private
46
+
47
+ def call_method
48
+ instance_method_by(action_name)
49
+ end
50
+
51
+ def has_call_method?
52
+ self.class.method_defined? call_method
53
+ end
54
+
55
+ def instance_method_by(action)
56
+ self.class.send(:method_by, action)
57
+ end
58
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: opisator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Evgeny Breykin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-09-06 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Describe, what your controllers should do
14
+ email: zbrejkin@yandex.ru
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/opisator.rb
20
+ - lib/opisator/defaults/contract.rb
21
+ - lib/opisator/defaults/interactor.rb
22
+ - lib/opisator/defaults/presenter.rb
23
+ homepage: https://rubygems.org/gems/opisator
24
+ licenses:
25
+ - MIT
26
+ metadata: {}
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubygems_version: 3.1.4
43
+ signing_key:
44
+ specification_version: 4
45
+ summary: Let's rock the controllers
46
+ test_files: []