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: 49bb1f2ed54517d7a8ec023f2540b55a7b4485abfd7b0d0d409ebe984def0cbe
4
- data.tar.gz: 2f55526b80a98e5d280b61bf3318d5ad0bfa6fbf25408d038c96937e07ae938a
3
+ metadata.gz: d32b4fc44895ec6ae4d8f5826dfd8c99e689b60b157cc223540a30999ef2b0bc
4
+ data.tar.gz: b520dca1c499360f853c86e3c1e2bc68c7ba22193016cd4d5ea6ad107390eab6
5
5
  SHA512:
6
- metadata.gz: 50da068f06e1de7293bb0bff4ae06cf9307b1fb3435524861964d1cc69b9c87253a06ff181543507972dac97bf53ea9e79ff8bdd22429e6abe0c840aed3a44f6
7
- data.tar.gz: 6696376e521fe681cb52238515f146403330157ef7adffe459b8188126b492731150ab7f534cd354040584a1e873d016282bdd7fa596b9f9600630701881b829
6
+ metadata.gz: e1d2fd0bbe132ed7ac4cd9ea68a17cf4f03c4cde6fb1a45717c7a238624ff8fe86aa7b11a02852fe74009ea6ab3c50399c64d380ff8811a4de4a26855bb87642
7
+ data.tar.gz: 66feb2659095671305ff2939fb36c4b52c8adbf2966f7b4a05a9beb7b52ac4a819f1ebec8922b4b603333f546a9f033b1ca6d0cd2ec78bbde4fe6fe941e55ecf
data/README.md CHANGED
@@ -1,34 +1,113 @@
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 actions directory:
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. 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
- TODO: Write usage instructions here
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
- ## Development
89
+ ## How to contribute
28
90
 
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.
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
- 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).
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
@@ -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.2"
5
5
  end
@@ -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 and the base application_action.rb file."
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.0
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 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"
@@ -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