active_call 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: 4673cf511194223bf9481aa7ed85507c9162556b20469f28c9421cc59f4230a9
4
+ data.tar.gz: 20fed6531fd0ac7bc7c6e6f8ffb03d336c82e6b91131354c3c5da6e202ea56b0
5
+ SHA512:
6
+ metadata.gz: 0064c55032419b699535d0f19cfbf90d730089f57da8a7ac360bdb96fbb7f40dc6d2a19859baec6074e180aef6ef290a45bb818ba872a5418f2ad8c0432786cf
7
+ data.tar.gz: bea908f7aeb097617edaf7694a5fffd21e8ef6f3a90f8fdcebd8e4efd23cf90fba289df598914c35540b16400b7ae46dd6ce4c4bd5df29e1b42feb1ad6dabfa2
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,47 @@
1
+ plugins:
2
+ - rubocop-performance
3
+ - rubocop-rake
4
+ - rubocop-rspec
5
+
6
+ AllCops:
7
+ TargetRubyVersion: 3.1
8
+ NewCops: enable
9
+ Include:
10
+ - 'lib/**/*.rb'
11
+ - 'spec/**/*.rb'
12
+ Exclude:
13
+ - active_call.gemspec
14
+ - bin/*
15
+ - 'vendor/**/*'
16
+ - 'gem/**/*'
17
+
18
+ Lint/MissingSuper:
19
+ AllowedParentClasses:
20
+ - ActiveCall::Base
21
+
22
+ Metrics/BlockLength:
23
+ Exclude:
24
+ - spec/*/**.rb
25
+
26
+ RSpec/ExampleLength:
27
+ Enabled: false
28
+
29
+ RSpec/MultipleExpectations:
30
+ Enabled: false
31
+
32
+ Style/ClassAndModuleChildren:
33
+ EnforcedStyle: compact
34
+ Exclude:
35
+ - lib/active_call.rb
36
+
37
+ Style/Documentation:
38
+ Enabled: false
39
+
40
+ Style/StringLiterals:
41
+ EnforcedStyle: single_quotes
42
+
43
+ Style/StringLiteralsInInterpolation:
44
+ EnforcedStyle: single_quotes
45
+
46
+ Style/SymbolArray:
47
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2025-03-08
4
+
5
+ - Initial release
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Kobus Joubert
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,136 @@
1
+ # Active Call
2
+
3
+ Active Call provides a standardized way to create service objects.
4
+
5
+ ## Installation
6
+
7
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
8
+
9
+ Install the gem and add to the application's Gemfile by executing:
10
+
11
+ ```bash
12
+ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
13
+ ```
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ ```bash
18
+ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ Your child classes should inherit from `ActiveCall::Base`.
24
+
25
+ Now you can start adding your own service object classes in your gem's `lib` folder.
26
+
27
+ Each service object must define only one public method named `call`.
28
+
29
+ A `response` attribute is set with the result of the `call` method.
30
+
31
+ An `errors` object will be set if you specified any validations that failed before the `call` method could be invoked.
32
+
33
+ There is also a `before_call` hook to set up anything before invoking the `call` method. This only happens after all validations have passed.
34
+
35
+ Define a service object with optional validations and callbacks.
36
+
37
+ ```ruby
38
+ require 'active_call'
39
+
40
+ class YourGemName::SomeResource::GetService < ActiveCall::Base
41
+ attr_reader :message
42
+
43
+ validates :message, presence: true
44
+
45
+ before_call :strip_message
46
+
47
+ def initialize(message: nil)
48
+ @message = message
49
+ end
50
+
51
+ def call
52
+ { foo: message }
53
+ end
54
+
55
+ private
56
+
57
+ def strip_message
58
+ @message.strip!
59
+ end
60
+ end
61
+ ```
62
+
63
+ You will get a **response** object.
64
+
65
+ ```ruby
66
+ service = YourGemName::SomeResource::GetService.call(message: ' bar ')
67
+ service.valid? # => true
68
+ service.response # => { foo: 'bar' }
69
+ ```
70
+
71
+ And an **errors** object when validation failed.
72
+
73
+ ```ruby
74
+ service = YourGemName::SomeResource::GetService.call(message: '')
75
+ service.valid? # => false
76
+ service.errors.full_messages # => ["Message can't be blank"]
77
+ service.response # => nil
78
+ ```
79
+
80
+ If you have secrets, use a **configuration** block.
81
+
82
+ ```ruby
83
+ require 'net/http'
84
+
85
+ class YourGemName::BaseService < ActiveCall::Base
86
+ config_accessor :api_key, default: ENV['API_KEY'], instance_writer: false
87
+
88
+ def call
89
+ Net::HTTP.get_response(URI("http://example.com/api?#{URI.encode_www_form(api_key: api_key)}"))
90
+ end
91
+ end
92
+ ```
93
+
94
+ Then in your application code you can overrite the configuration defaults.
95
+
96
+ ```ruby
97
+ YourGemName::BaseService.configure do |config|
98
+ config.api_key = Rails.application.credentials.api_key || ENV['API_KEY']
99
+ end
100
+ ```
101
+
102
+ ## Gem Creation
103
+
104
+ To create your own gem for a service.
105
+
106
+ ```bash
107
+ gem update --system
108
+ ```
109
+
110
+ Build your gem.
111
+
112
+ ```bash
113
+ bundle gem your_service --test=rspec --linter=rubocop --ci=github --github-username=<your_profile_name> --git --changelog --mit
114
+ ```
115
+
116
+ Then add Active Call as a dependency in your gemspec.
117
+
118
+ ```ruby
119
+ spec.add_dependency 'active_call'
120
+ ```
121
+
122
+ Now start adding your service objects in the `lib` directory and make sure they inherit from `ActiveCall::Base`.
123
+
124
+ ## Development
125
+
126
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
127
+
128
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
129
+
130
+ ## Contributing
131
+
132
+ Bug reports and pull requests are welcome on GitHub at https://github.com/kobusjoubert/active_call.
133
+
134
+ ## License
135
+
136
+ 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,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require 'rubocop/rake_task'
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ActiveCall::Base
4
+ extend ActiveModel::Callbacks
5
+ include ActiveModel::Validations
6
+ include ActiveSupport::Configurable
7
+
8
+ attr_reader :response
9
+
10
+ define_model_callbacks :call
11
+
12
+ class << self
13
+ def call(...)
14
+ service_object = new(...)
15
+ return service_object if service_object.invalid?
16
+
17
+ service_object.run_callbacks(:call) do
18
+ service_object.instance_variable_set(:@response, service_object.call)
19
+ end
20
+
21
+ service_object
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveCall
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_model'
4
+ require 'zeitwerk'
5
+
6
+ require_relative 'active_call/version'
7
+
8
+ loader = Zeitwerk::Loader.for_gem
9
+ loader.setup
10
+
11
+ module ActiveCall
12
+ class Error < StandardError; end
13
+ end
@@ -0,0 +1,4 @@
1
+ module ActiveCall
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_call
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kobus Joubert
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2025-03-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activemodel
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '7.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '7.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: zeitwerk
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.6'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.6'
41
+ description: Active Call provides a standardized way to create service objects.
42
+ email:
43
+ - kobus@translate3d.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".rspec"
49
+ - ".rubocop.yml"
50
+ - CHANGELOG.md
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - lib/active_call.rb
55
+ - lib/active_call/base.rb
56
+ - lib/active_call/version.rb
57
+ - sig/active_call.rbs
58
+ homepage: https://github.com/kobusjoubert/active_call
59
+ licenses:
60
+ - MIT
61
+ metadata:
62
+ allowed_push_host: https://rubygems.org
63
+ rubygems_mfa_required: 'true'
64
+ homepage_uri: https://github.com/kobusjoubert/active_call
65
+ source_code_uri: https://github.com/kobusjoubert/active_call
66
+ changelog_uri: https://github.com/kobusjoubert/active_call/CHANGELOG.md
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 3.1.0
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubygems_version: 3.3.27
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: Active Call
86
+ test_files: []