active_act 0.1.0 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 49bb1f2ed54517d7a8ec023f2540b55a7b4485abfd7b0d0d409ebe984def0cbe
4
- data.tar.gz: 2f55526b80a98e5d280b61bf3318d5ad0bfa6fbf25408d038c96937e07ae938a
3
+ metadata.gz: f97bab53c823e61bd0c317974fab745a3a0a7d5f056ca6dd992cf5d4566f741f
4
+ data.tar.gz: 6fafffba84d21351f1a5db402986bb0675c269128c65ae4058cac08dcf54d848
5
5
  SHA512:
6
- metadata.gz: 50da068f06e1de7293bb0bff4ae06cf9307b1fb3435524861964d1cc69b9c87253a06ff181543507972dac97bf53ea9e79ff8bdd22429e6abe0c840aed3a44f6
7
- data.tar.gz: 6696376e521fe681cb52238515f146403330157ef7adffe459b8188126b492731150ab7f534cd354040584a1e873d016282bdd7fa596b9f9600630701881b829
6
+ metadata.gz: 7bf8afdad1c966dd28fc0a1468cb733e903368781736fbdd858944eb9a5136324a0cc016fcedf5e521533e255ecb904b30f78cee6264faa9d3a84697661f2837
7
+ data.tar.gz: ef9578a447f242e263d2bb69dec9355ee7965d6bd46d4a41d2d80178233d0785531a0fb97f47f4b0960514f60b2e00c3b2d35a693575a33a800535c67559677b
data/README.md CHANGED
@@ -1,34 +1,119 @@
1
1
  # ActiveAct
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
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
- 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.
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'active_act'
11
+ ```
10
12
 
11
- Install the gem and add to the application's Gemfile by executing:
13
+ And then execute:
12
14
 
13
- ```bash
14
- bundle add active_act
15
+ ```sh
16
+ $ bundle install
15
17
  ```
16
18
 
17
- If bundler is not being used to manage dependencies, install the gem by executing:
19
+ Run the install generator to set up the base structure:
18
20
 
19
- ```bash
20
- gem install active_act
21
+ ```sh
22
+ $ rails generate active_act:install
21
23
  ```
22
24
 
25
+ This will create the `app/actions` directory and a base `application_action.rb` file.
26
+
23
27
  ## Usage
24
28
 
25
- TODO: Write usage instructions here
29
+ ### Creating a new Action
30
+
31
+ You can manually create a new action by inheriting from `ApplicationAction`:
32
+
33
+ ```ruby
34
+ # app/actions/send_welcome_email.rb
35
+ class SendWelcomeEmail < 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
+ Or, use the (upcoming) generator:
50
+
51
+ ```sh
52
+ $ rails generate active_act:action SendWelcomeEmail
53
+ ```
54
+
55
+ ### Executing an Action
56
+
57
+ You can call your action from anywhere in your app:
58
+
59
+ ```ruby
60
+ SendWelcomeEmail.call(user)
61
+ ```
62
+
63
+ ## Base Action API
64
+
65
+ The generated `ApplicationAction` provides:
66
+
67
+ - `.call(*args, **kwargs, &block)`: Instantiates and runs the action.
68
+ - `#call`: To be implemented in your subclass.
69
+ - `#fail(error = nil)`: Raises an error to signal failure.
70
+
71
+ ## Example
72
+
73
+ ```ruby
74
+ # app/actions/process_payment.rb
75
+ class ProcessPayment < ApplicationAction
76
+ def initialize(order)
77
+ @order = order
78
+ end
79
+
80
+ def call
81
+ PaymentService.charge(@order)
82
+ rescue PaymentService::Error => e
83
+ fail(e)
84
+ end
85
+ end
86
+
87
+ # Usage:
88
+ ProcessPayment.call(order)
89
+ ```
90
+
91
+ ## Contributing
92
+
93
+ Bug reports and pull requests are welcome on GitHub at https://github.com/magdielcardoso/active_act.
26
94
 
27
- ## Development
95
+ ## How to contribute
28
96
 
29
- 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.
97
+ 1. Fork the repository: https://github.com/magdielcardoso/active_act
98
+ 2. Create a new branch for your feature or fix:
99
+ ```sh
100
+ git checkout -b my-feature
101
+ ```
102
+ 3. Make your changes, including tests if applicable.
103
+ 4. Run the test suite to ensure everything is working:
104
+ ```sh
105
+ bundle install
106
+ bundle exec rake spec
107
+ ```
108
+ 5. Commit your changes and push your branch:
109
+ ```sh
110
+ git add .
111
+ git commit -m "Describe your change"
112
+ git push origin my-feature
113
+ ```
114
+ 6. Open a Pull Request on GitHub and describe your contribution.
30
115
 
31
- 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).
116
+ Thank you for helping to improve ActiveAct!
32
117
 
33
118
  ## License
34
119
 
Binary file
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveAct
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  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.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Magdiel Cardoso
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-06-10 00:00:00.000000000 Z
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"
@@ -24,6 +24,7 @@ files:
24
24
  - LICENSE.txt
25
25
  - README.md
26
26
  - Rakefile
27
+ - active_act-0.1.0.gem
27
28
  - app/actions/application_action.rb
28
29
  - lib/active_act.rb
29
30
  - lib/active_act/engine.rb