vg-service_object 0.1.0

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: e0e1fea1a0c6d0cf6f8804325d01e1d29f0569db7090b659eeaceb5ee00f83cf
4
+ data.tar.gz: d428f22186c6d9130ee76245efc58181c708656ef0e7f8e265ba0d817357e9b1
5
+ SHA512:
6
+ metadata.gz: 23103f62225bff2207d1d3a15a06d1da1b64c82491ba0c97c85f72b8ef62c547d83cc817cc6db0a2014b9835e0de94eb73e2d58f8314bf4949b3ece650ee1a8e
7
+ data.tar.gz: 7f962005ba8ce5d78304726bfd7ec8c8d8fa28f36fe2363f6246785d44a21fe794322c6c3a62d53901720e85c9066c2165ec6b7c7e0fe7dce278a5774ff03139
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /lib/bundler/man/
3
+ /.yardoc
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /rdoc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+
12
+ .byebug_history
13
+ .rspec_status
14
+ .ruby-version
15
+ .ruby-gemset
16
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.2
6
+ before_install: gem install bundler -v 2.1.4
data/CHANGELOG.md ADDED
File without changes
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Gem's dependencies are specified in .gemspec file
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,68 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ vg-service_object (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ coderay (1.1.3)
10
+ diff-lcs (1.4.4)
11
+ ffi (1.15.3)
12
+ formatador (0.3.0)
13
+ guard (2.18.0)
14
+ formatador (>= 0.2.4)
15
+ listen (>= 2.7, < 4.0)
16
+ lumberjack (>= 1.0.12, < 2.0)
17
+ nenv (~> 0.1)
18
+ notiffany (~> 0.0)
19
+ pry (>= 0.13.0)
20
+ shellany (~> 0.0)
21
+ thor (>= 0.18.1)
22
+ guard-compat (1.2.1)
23
+ guard-rspec (4.7.3)
24
+ guard (~> 2.1)
25
+ guard-compat (~> 1.1)
26
+ rspec (>= 2.99.0, < 4.0)
27
+ listen (3.6.0)
28
+ rb-fsevent (~> 0.10, >= 0.10.3)
29
+ rb-inotify (~> 0.9, >= 0.9.10)
30
+ lumberjack (1.2.8)
31
+ method_source (1.0.0)
32
+ nenv (0.3.0)
33
+ notiffany (0.1.3)
34
+ nenv (~> 0.1)
35
+ shellany (~> 0.0)
36
+ pry (0.14.1)
37
+ coderay (~> 1.1)
38
+ method_source (~> 1.0)
39
+ rb-fsevent (0.11.0)
40
+ rb-inotify (0.10.1)
41
+ ffi (~> 1.0)
42
+ rspec (3.10.0)
43
+ rspec-core (~> 3.10.0)
44
+ rspec-expectations (~> 3.10.0)
45
+ rspec-mocks (~> 3.10.0)
46
+ rspec-core (3.10.1)
47
+ rspec-support (~> 3.10.0)
48
+ rspec-expectations (3.10.1)
49
+ diff-lcs (>= 1.2.0, < 2.0)
50
+ rspec-support (~> 3.10.0)
51
+ rspec-mocks (3.10.2)
52
+ diff-lcs (>= 1.2.0, < 2.0)
53
+ rspec-support (~> 3.10.0)
54
+ rspec-support (3.10.2)
55
+ shellany (0.0.1)
56
+ thor (1.1.0)
57
+
58
+ PLATFORMS
59
+ ruby
60
+
61
+ DEPENDENCIES
62
+ guard-rspec (~> 4.7)
63
+ pry
64
+ rspec (~> 3.2)
65
+ vg-service_object!
66
+
67
+ BUNDLED WITH
68
+ 2.1.4
data/Guardfile ADDED
@@ -0,0 +1,13 @@
1
+
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ directories %w(lib config spec)
5
+
6
+ guard :rspec, cmd: "rspec --format d" do
7
+ watch(%r{^spec/.+_spec\.rb$})
8
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
9
+ watch("spec/spec_helper.rb") { "spec" }
10
+ watch("spec/dummy_objects.rb") { "spec" }
11
+ watch("spec/shared_examples.rb") { "spec" }
12
+ watch("spec/helpers.rb") { "spec" }
13
+ end
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Vladimir Gorodulin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # ServiceObject pattern
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'vg-service_object'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle install
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install vg-service_object
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ Bug reports and pull requests are welcome on GitHub at https://github.com/gorodulin/service_object.
26
+
27
+ ## License
28
+
29
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/lib/vg.rb ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VG
4
+ require_relative "vg/service_object"
5
+ require_relative "vg/s_o"
6
+ #autoload(:ServiceObject, 'v_g/service_object')
7
+ #autoload(:SO, 'v_g/s_o')
8
+ end
data/lib/vg/s_o.rb ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VG
4
+ module SO
5
+ autoload(:GenerateIncludableModule, 'vg/s_o/generate_includable_module')
6
+ autoload(:GenerateSlugFromModuleName, 'vg/s_o/generate_slug_from_module_name')
7
+ autoload(:InjectRegistrationMethods, 'vg/s_o/inject_registration_methods')
8
+ autoload(:ServiceObjectModuleInheritance, 'vg/s_o/service_object_module_inheritance')
9
+ autoload(:ServiceObjectRegistrationMethods, 'vg/s_o/service_object_registration_methods')
10
+ end
11
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VG
4
+ module SO
5
+ module GenerateIncludableModule
6
+
7
+ def self.call(so_module_name, as: nil)
8
+ method_name = as || GenerateSlugFromModuleName.call(so_module_name)
9
+ Module.new do
10
+ class_eval <<~RUBY
11
+ def self.included(base)
12
+ InjectRegistrationMethods.call(base)
13
+ base.register_service_object(:#{method_name}, ::#{so_module_name})
14
+ end
15
+
16
+ def #{method_name}_fn
17
+ self.class.registered_service_objects[:#{method_name}].callable
18
+ end
19
+
20
+ def #{method_name}(...)
21
+ send("#{method_name}_fn").call(...)
22
+ end
23
+
24
+ def self.extended(_base)
25
+ raise "Do not extend ::#{so_module_name}, use include!"
26
+ end
27
+ RUBY
28
+ end
29
+ end
30
+
31
+ end # ... GenerateIncludableModule
32
+ end # ... SO
33
+ end # ... VG
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VG
4
+ module SO
5
+ module GenerateSlugFromModuleName
6
+
7
+ def self.call(module_name)
8
+ regex = /(?:::)*([A-Za-z0-9]+)$/
9
+ module_name.match(regex)[1]
10
+ .gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
11
+ .gsub(/([a-z\d])([A-Z])/,'\1_\2')
12
+ .downcase.to_sym
13
+ end
14
+
15
+ end # ... GenerateSlugFromModuleName
16
+ end # ... SO
17
+ end # ... VG
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VG
4
+ module SO
5
+ module InjectRegistrationMethods
6
+
7
+ def self.call(base)
8
+ base.include(ServiceObjectModuleInheritance)
9
+ base.include(ServiceObjectRegistrationMethods)
10
+ end
11
+
12
+ def self.included(_base)
13
+ raise "Do not include, use #call instead"
14
+ end
15
+
16
+ end # ... InjectRegistrationMethods
17
+ end # ... SO
18
+ end # ... VG
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VG
4
+ module SO
5
+ module ServiceObjectModuleInheritance
6
+
7
+ module ClassMethods
8
+ def included(base)
9
+ puts "-- #{self.name}#included call (including into #{base})"
10
+ InjectRegistrationMethods.call(base)
11
+ base.register_service_objects(registered_service_objects)
12
+
13
+ super(base)
14
+ end
15
+ end
16
+
17
+ def self.included(base)
18
+ return unless base.instance_of?(Module)
19
+ return if base.singleton_class.included_modules.include?(ClassMethods)
20
+
21
+ puts "-- prepend #{base.name}#included with ServiceObjectModuleInheritance#included"
22
+ base.singleton_class.prepend ClassMethods
23
+ end
24
+
25
+ end # ... ServiceObjectModuleInheritance
26
+ end # ... SO
27
+ end # ... VG
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VG
4
+ module SO
5
+ module ServiceObjectRegistrationMethods
6
+ module ClassMethods
7
+ def registered_service_objects
8
+ @registered_service_objects ||= {}
9
+ end
10
+
11
+ def register_service_objects(hash)
12
+ hash.each { |name, so| register_service_object(name, so) }
13
+ end
14
+
15
+ def register_service_object(name, so)
16
+ registered_service_objects[name.to_sym]&.tap do |registered_so|
17
+ return if so == registered_so
18
+ raise "#{so} clashes with #{registered_so} in #{self}" if so != registered_so
19
+ end
20
+
21
+ puts "--- register #{self.name}##{name} => #{so}#call"
22
+ registered_service_objects[name.to_sym] = so
23
+ end
24
+ end
25
+
26
+ def self.included(base)
27
+ return if base.singleton_class.included_modules.include?(ClassMethods)
28
+
29
+ puts "-- #{base.name}: extend with ServiceObjectRegistrationMethods"
30
+ base.extend ClassMethods
31
+ end
32
+
33
+ end # ... ServiceObjectRegistrationMethods
34
+ end # ... SO
35
+ end # ... VG
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VG
4
+ module ServiceObject
5
+
6
+ module ClassSingletonMethods
7
+ def call(...)
8
+ callable.call(...)
9
+ end
10
+
11
+ def callable
12
+ @callable ||= self.new
13
+ end
14
+
15
+ def as_so(method_name = nil)
16
+ ::VG::SO::GenerateIncludableModule.call(self.name, as: method_name)
17
+ end
18
+ end
19
+
20
+ module ModuleSingletonMethods
21
+ def call(...)
22
+ callable.call(...)
23
+ end
24
+
25
+ def callable
26
+ @callable ||= self::Action.new
27
+ end
28
+
29
+ def as_so(method_name = nil)
30
+ ::VG::SO::GenerateIncludableModule.call(self.name, as: method_name)
31
+ end
32
+ end
33
+
34
+ def self.included(so)
35
+ methods = so.is_a?(Class) ? ClassSingletonMethods : ModuleSingletonMethods
36
+ return if so.singleton_class.included_modules.include?(methods)
37
+ so.extend methods
38
+
39
+ so.singleton_class.instance_eval do
40
+ define_method(:included) { |_base| raise "Can't be included. Use #as_so method instead" }
41
+ end if so.instance_of?(Module)
42
+ end
43
+
44
+ end # ... ServiceObject
45
+ end # ... VG
@@ -0,0 +1,5 @@
1
+ module VG
2
+ module ServiceObject
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,32 @@
1
+ require_relative "lib/vg"
2
+ require_relative "lib/vg/service_object/version"
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "vg-service_object"
6
+ spec.version = VG::ServiceObject::VERSION
7
+ spec.authors = ["Vladimir Gorodulin"]
8
+ spec.email = ["ru.hostmaster@gmail.com"]
9
+ spec.summary = %q{Service Object pattern}
10
+ spec.description = %q{Service Object pattern as includable behavior}
11
+ spec.homepage = "https://github.com/gorodulin/service_object"
12
+ spec.license = "MIT"
13
+
14
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
15
+
16
+ spec.metadata = {
17
+ "changelog_uri" => "https://github.com/gorodulin/service_object/CHANGELOG.md",
18
+ "homepage_uri" => spec.homepage,
19
+ "source_code_uri" => "https://github.com/gorodulin/service_object",
20
+ }
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
25
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(bin|spec|config|tmp)/}) }
26
+ end
27
+
28
+ spec.require_paths = ["lib"]
29
+ spec.add_development_dependency "rspec", "~> 3.2"
30
+ spec.add_development_dependency "pry"
31
+ spec.add_development_dependency "guard-rspec", "~> 4.7"
32
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vg-service_object
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Vladimir Gorodulin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-08-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: guard-rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4.7'
55
+ description: Service Object pattern as includable behavior
56
+ email:
57
+ - ru.hostmaster@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - CHANGELOG.md
66
+ - Gemfile
67
+ - Gemfile.lock
68
+ - Guardfile
69
+ - LICENSE
70
+ - README.md
71
+ - Rakefile
72
+ - lib/vg.rb
73
+ - lib/vg/s_o.rb
74
+ - lib/vg/s_o/generate_includable_module.rb
75
+ - lib/vg/s_o/generate_slug_from_module_name.rb
76
+ - lib/vg/s_o/inject_registration_methods.rb
77
+ - lib/vg/s_o/service_object_module_inheritance.rb
78
+ - lib/vg/s_o/service_object_registration_methods.rb
79
+ - lib/vg/service_object.rb
80
+ - lib/vg/service_object/version.rb
81
+ - vg-service_object.gemspec
82
+ homepage: https://github.com/gorodulin/service_object
83
+ licenses:
84
+ - MIT
85
+ metadata:
86
+ changelog_uri: https://github.com/gorodulin/service_object/CHANGELOG.md
87
+ homepage_uri: https://github.com/gorodulin/service_object
88
+ source_code_uri: https://github.com/gorodulin/service_object
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: 2.7.0
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubygems_version: 3.1.4
105
+ signing_key:
106
+ specification_version: 4
107
+ summary: Service Object pattern
108
+ test_files: []