active_act 0.1.0 → 0.1.2
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d32b4fc44895ec6ae4d8f5826dfd8c99e689b60b157cc223540a30999ef2b0bc
|
4
|
+
data.tar.gz: b520dca1c499360f853c86e3c1e2bc68c7ba22193016cd4d5ea6ad107390eab6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e1d2fd0bbe132ed7ac4cd9ea68a17cf4f03c4cde6fb1a45717c7a238624ff8fe86aa7b11a02852fe74009ea6ab3c50399c64d380ff8811a4de4a26855bb87642
|
7
|
+
data.tar.gz: 66feb2659095671305ff2939fb36c4b52c8adbf2966f7b4a05a9beb7b52ac4a819f1ebec8922b4b603333f546a9f033b1ca6d0cd2ec78bbde4fe6fe941e55ecf
|
data/README.md
CHANGED
@@ -1,34 +1,113 @@
|
|
1
1
|
# ActiveAct
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/active_act`. To experiment with that code, run `bin/console` for an interactive prompt.
|
3
|
+
ActiveAct is a Rails Engine that introduces a standardized Action layer for your Rails applications. It provides a base class and generators to help you organize business logic in a clean, reusable way.
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
9
|
-
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'active_act'
|
11
|
+
```
|
10
12
|
|
11
|
-
|
13
|
+
And then execute:
|
12
14
|
|
13
|
-
```
|
14
|
-
bundle
|
15
|
+
```sh
|
16
|
+
$ bundle install
|
15
17
|
```
|
16
18
|
|
17
|
-
|
19
|
+
Run the install generator to set up the actions directory:
|
18
20
|
|
19
|
-
```
|
20
|
-
|
21
|
+
```sh
|
22
|
+
$ rails generate active_act:install
|
21
23
|
```
|
22
24
|
|
25
|
+
This will create the `app/actions` directory. The base class `ActiveAct::ApplicationAction` is provided by the gem and does not need to be generated in your app.
|
26
|
+
|
23
27
|
## Usage
|
24
28
|
|
25
|
-
|
29
|
+
### Creating a new Action
|
30
|
+
|
31
|
+
Create a new action by inheriting from `ActiveAct::ApplicationAction`:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
# app/actions/send_welcome_email.rb
|
35
|
+
class SendWelcomeEmail < ActiveAct::ApplicationAction
|
36
|
+
def initialize(user)
|
37
|
+
@user = user
|
38
|
+
end
|
39
|
+
|
40
|
+
def call
|
41
|
+
# Your business logic here
|
42
|
+
UserMailer.welcome(@user).deliver_later
|
43
|
+
rescue => e
|
44
|
+
fail(e)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
```
|
48
|
+
|
49
|
+
### Executing an Action
|
50
|
+
|
51
|
+
You can call your action from anywhere in your app:
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
SendWelcomeEmail.call(user)
|
55
|
+
```
|
56
|
+
|
57
|
+
## Base Action API
|
58
|
+
|
59
|
+
The provided `ActiveAct::ApplicationAction` includes:
|
60
|
+
|
61
|
+
- `.call(*args, **kwargs, &block)`: Instantiates and runs the action.
|
62
|
+
- `#call`: To be implemented in your subclass.
|
63
|
+
- `#fail(error = nil)`: Raises an error to signal failure.
|
64
|
+
|
65
|
+
## Example
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
# app/actions/process_payment.rb
|
69
|
+
class ProcessPayment < ActiveAct::ApplicationAction
|
70
|
+
def initialize(order)
|
71
|
+
@order = order
|
72
|
+
end
|
73
|
+
|
74
|
+
def call
|
75
|
+
PaymentService.charge(@order)
|
76
|
+
rescue PaymentService::Error => e
|
77
|
+
fail(e)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# Usage:
|
82
|
+
ProcessPayment.call(order)
|
83
|
+
```
|
84
|
+
|
85
|
+
## Contributing
|
86
|
+
|
87
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/magdielcardoso/active_act.
|
26
88
|
|
27
|
-
##
|
89
|
+
## How to contribute
|
28
90
|
|
29
|
-
|
91
|
+
1. Fork the repository: https://github.com/magdielcardoso/active_act
|
92
|
+
2. Create a new branch for your feature or fix:
|
93
|
+
```sh
|
94
|
+
git checkout -b my-feature
|
95
|
+
```
|
96
|
+
3. Make your changes, including tests if applicable.
|
97
|
+
4. Run the test suite to ensure everything is working:
|
98
|
+
```sh
|
99
|
+
bundle install
|
100
|
+
bundle exec rake spec
|
101
|
+
```
|
102
|
+
5. Commit your changes and push your branch:
|
103
|
+
```sh
|
104
|
+
git add .
|
105
|
+
git commit -m "Describe your change"
|
106
|
+
git push origin my-feature
|
107
|
+
```
|
108
|
+
6. Open a Pull Request on GitHub and describe your contribution.
|
30
109
|
|
31
|
-
|
110
|
+
Thank you for helping to improve ActiveAct!
|
32
111
|
|
33
112
|
## License
|
34
113
|
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveAct
|
4
|
+
class ApplicationAction
|
5
|
+
def self.call(*args, **kwargs, &block)
|
6
|
+
new(*args, **kwargs, &block).call
|
7
|
+
end
|
8
|
+
|
9
|
+
def call
|
10
|
+
raise NotImplementedError, "You must implement the #call method in your action."
|
11
|
+
end
|
12
|
+
|
13
|
+
def fail(error = nil)
|
14
|
+
raise(error || "Action failed")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/active_act/version.rb
CHANGED
@@ -7,15 +7,11 @@ module ActiveAct
|
|
7
7
|
class InstallGenerator < Rails::Generators::Base
|
8
8
|
source_root File.expand_path("templates", __dir__)
|
9
9
|
|
10
|
-
desc "Creates the app/actions structure
|
10
|
+
desc "Creates the app/actions structure."
|
11
11
|
|
12
12
|
def create_actions_directory
|
13
13
|
empty_directory "app/actions"
|
14
14
|
end
|
15
|
-
|
16
|
-
def copy_application_action
|
17
|
-
template "application_action.rb", "app/actions/application_action.rb"
|
18
|
-
end
|
19
15
|
end
|
20
16
|
end
|
21
17
|
end
|
@@ -1,4 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# Base class for all domain actions
|
3
4
|
class ApplicationAction
|
5
|
+
def self.call(*args, **kwargs, &block)
|
6
|
+
new(*args, **kwargs, &block).call
|
7
|
+
end
|
8
|
+
|
9
|
+
def call
|
10
|
+
raise NotImplementedError, "You must implement the #call method in your action."
|
11
|
+
end
|
12
|
+
|
13
|
+
def fail(error = nil)
|
14
|
+
raise(error || "Action failed")
|
15
|
+
end
|
4
16
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_act
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Magdiel Cardoso
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-06-
|
10
|
+
date: 2025-06-11 00:00:00.000000000 Z
|
11
11
|
dependencies: []
|
12
12
|
description: "Abstract spare methods from your controllers and models into actions
|
13
13
|
in Ruby with Active Act \U0001F680"
|
@@ -26,6 +26,7 @@ files:
|
|
26
26
|
- Rakefile
|
27
27
|
- app/actions/application_action.rb
|
28
28
|
- lib/active_act.rb
|
29
|
+
- lib/active_act/application_action.rb
|
29
30
|
- lib/active_act/engine.rb
|
30
31
|
- lib/active_act/version.rb
|
31
32
|
- lib/generators/active_act/install/install_generator.rb
|