rdeco-task 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: 81e452abde148b27c824d6ffb5f0af7c50fbb07911323109fa23fd54f1a936b2
4
+ data.tar.gz: b6501677a09c2f4afee35407cde9264cdffcfffd21c8fc0dbba14981b2ed8605
5
+ SHA512:
6
+ metadata.gz: ad5c234a6895180a3fbd709d0cb486edeb4940e9e98aedaa506a71a5c93b66aa1f4f4371d9aca6a114f9b295ad43e748f3a8b2081dcb66d0f77e609da058c5aa
7
+ data.tar.gz: 017abf1baad98a8d3c3061a6d1a8e35f7fc30b08e5ffef43a7284b23a07cdf025d0d326107a1a11d095dfcdffd1618626f9fedaec45ac5e2cb053539c310e812
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Fuseraft
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,98 @@
1
+ # Rdeco::Task
2
+
3
+ **Rdeco::Task** is a RubyGem that provides a metaprogramming module for task execution in a specified order. It allows you to define a set of methods (tasks) in a class and execute them in a specific sequence: **before**, **main**, and **after**.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's `Gemfile`:
8
+
9
+ ```ruby
10
+ gem "rdeco-task"
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```bash
16
+ $ bundle install
17
+ ```
18
+
19
+ Or install it directly using:
20
+
21
+ ```bash
22
+ $ gem install rdeco-task
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ ### Basic Example
28
+
29
+ To use the `Rdeco::Task` module in your class, follow these steps:
30
+
31
+ ```ruby
32
+ require "rdeco/task"
33
+
34
+ class YourClass
35
+ include Rdeco::Task
36
+
37
+ before :setup, :preparation
38
+ main :core_logic
39
+ after :teardown
40
+
41
+ def setup
42
+ puts "Setting up..."
43
+ end
44
+
45
+ def preparation
46
+ puts "Doing some preparation..."
47
+ end
48
+
49
+ def core_logic
50
+ puts "Executing core logic..."
51
+ end
52
+
53
+ def teardown
54
+ puts "Tearing down..."
55
+ end
56
+ end
57
+
58
+ # Create an instance of the class
59
+ instance = YourClass.new
60
+
61
+ # Running the tasks in order: before, main, after
62
+ YourClass.run(instance)
63
+ ```
64
+
65
+ The above code will produce the following output:
66
+
67
+ ```
68
+ Setting up...
69
+ Doing some preparation...
70
+ Executing core logic...
71
+ Tearing down...
72
+ ```
73
+
74
+ ### Decorate Multiple Methods in One Line
75
+
76
+ You can decorate multiple methods in one line.
77
+
78
+ ```ruby
79
+ class AnotherClass
80
+ include Rdeco::Task
81
+
82
+ before :setup, :preparation, :setup_other
83
+ main :core_logic
84
+ after :teardown, :cleanup
85
+
86
+ # ... (rest of the class definition)
87
+ end
88
+ ```
89
+
90
+ ## Contributing
91
+
92
+ Bug reports and pull requests are welcome on GitHub at [fuseraft/rdeco-task](https://github.com/fuseraft/rdeco-task).
93
+
94
+ This project is intended to be a safe, welcoming space for collaboration and contributors.
95
+
96
+ ## License
97
+
98
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/lib/rdeco/task.rb ADDED
@@ -0,0 +1,51 @@
1
+ module Rdeco
2
+ module Task
3
+ def self.included(base)
4
+ base.extend(ClassMethods)
5
+ end
6
+
7
+ module ClassMethods
8
+ def before(*method_names)
9
+ (@before_tasks ||= []).concat(method_names)
10
+ end
11
+
12
+ def main(method_name)
13
+ @main_task = method_name
14
+ end
15
+
16
+ def after(*method_names)
17
+ (@after_tasks ||= []).concat(method_names)
18
+ end
19
+
20
+ def run(instance)
21
+ execute_before_tasks(instance)
22
+ execute_main_task(instance)
23
+ execute_after_tasks(instance)
24
+ end
25
+
26
+ private
27
+
28
+ def execute_before_tasks(instance)
29
+ return unless @before_tasks
30
+
31
+ @before_tasks.each do |task|
32
+ instance.send(task)
33
+ end
34
+ end
35
+
36
+ def execute_main_task(instance)
37
+ raise "No main task defined!" unless @main_task
38
+
39
+ instance.send(@main_task)
40
+ end
41
+
42
+ def execute_after_tasks(instance)
43
+ return unless @after_tasks
44
+
45
+ @after_tasks.each do |task|
46
+ instance.send(task)
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,51 @@
1
+ # spec/rdeco/task_spec.rb
2
+ require "rdeco/task"
3
+
4
+ RSpec.describe Rdeco::Task do
5
+ class YourClass
6
+ include Rdeco::Task
7
+
8
+ before :setup, :preparation, :setup_other
9
+ main :core_logic
10
+ after :teardown, :cleanup
11
+
12
+ def setup
13
+ puts "Setting up..."
14
+ end
15
+
16
+ def preparation
17
+ puts "Doing some preparation..."
18
+ end
19
+
20
+ def setup_other
21
+ puts "Setting up other things..."
22
+ end
23
+
24
+ def core_logic
25
+ puts "Executing core logic..."
26
+ end
27
+
28
+ def teardown
29
+ puts "Tearing down..."
30
+ end
31
+
32
+ def cleanup
33
+ puts "Cleaning up..."
34
+ end
35
+ end
36
+
37
+ let(:instance) { YourClass.new }
38
+
39
+ describe ".run" do
40
+ it "executes the tasks in the correct order" do
41
+ expect(instance).to receive(:setup).ordered
42
+ expect(instance).to receive(:preparation).ordered
43
+ expect(instance).to receive(:setup_other).ordered
44
+ expect(instance).to receive(:core_logic).ordered
45
+ expect(instance).to receive(:teardown).ordered
46
+ expect(instance).to receive(:cleanup).ordered
47
+
48
+ YourClass.run(instance)
49
+ end
50
+ end
51
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rdeco-task
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Scott Stauffer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-08-02 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.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ description: A RubyGem that provides metaprogramming attributes for task execution
28
+ in a specified order.
29
+ email:
30
+ - scott@fuseraft.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - LICENSE
36
+ - README.md
37
+ - lib/rdeco/task.rb
38
+ - spec/rdeco/task_spec.rb
39
+ homepage: https://github.com/fuseraft/rdeco-task
40
+ licenses:
41
+ - MIT
42
+ metadata:
43
+ source_code_uri: https://github.com/fuseraft/rdeco-task
44
+ allowed_push_host: https://rubygems.org
45
+ homepage_uri: https://github.com/fuseraft/rdeco-task
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '2.7'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubygems_version: 3.2.22
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: A RubyGem for the Rdeco::Task module
65
+ test_files:
66
+ - spec/rdeco/task_spec.rb