typed_operation 0.1.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 895e2a58caa6a8a40c35d3eff22b9429fed9f0c49627f275cd583ce0c2fe4bc6
4
- data.tar.gz: 794004ac749b5ff9df514827a794ef01917e5ca4bdd2b887a5e8ea06b491a097
3
+ metadata.gz: b3c88c55bf10a3d9d6582adfbb253c94a1fd6cf287794089775c9a8dbf1dfd86
4
+ data.tar.gz: baee565ac599fb5351d1758fe720587e6793114c8ec830cbe3db6d5dc40b2d61
5
5
  SHA512:
6
- metadata.gz: e81f633626fbd914bae0c232c22d1c9b5e44cc2169691fd022c408dbbbad15179062a8d641b03f6165a033c946cde10ad740b971b636c05fc85c7f828ed643c1
7
- data.tar.gz: 65e4065dded231777a7b2ed40ef901268da46e7d8403a20edb642d5ea815e15b280a8b46a64d24753de67daab3d7e50b9985fe6bebe6898c19f98386bb8020f8
6
+ metadata.gz: 32a92d0277fee468925bd0a3c5b4b377ebb8107b3202ea13f1c23925532df4665efffaac90e76c32060f629cb9a476e654abba406e80c28da7bcf590e504c445
7
+ data.tar.gz: 82d9ae76e6ba43564a3632d577ddf99ab92758c4b44cfad985a812b121c1c63efee7ceba0d92e1839c8fc6b5a0476a4914d4a33fdeca6a84bce9f0caca6c7789
data/README.md CHANGED
@@ -1,7 +1,4 @@
1
1
  # TypedOperation
2
- Short description and motivation.
3
-
4
- ## Usage
5
2
 
6
3
  An implementation of a Command pattern, which is callable, and can be partially applied (curried).
7
4
 
@@ -96,6 +93,26 @@ Or install it yourself as:
96
93
  $ gem install typed_operation
97
94
  ```
98
95
 
96
+ ## Add an `ApplicationOperation` to your project
97
+
98
+ ```ruby
99
+ bin/rails g typed_operation:install
100
+ ```
101
+
102
+ ## Generate a new Operation
103
+
104
+ ```ruby
105
+ bin/rails g typed_operation TestOperation
106
+ ```
107
+
108
+ You can optionally specify the directory to generate the operation in:
109
+
110
+ ```ruby
111
+ bin/rails g typed_operation TestOperation --path=app/operations
112
+ ```
113
+
114
+ The default path is `app/operations`.
115
+
99
116
  ## Contributing
100
117
  Contribution directions go here.
101
118
 
@@ -0,0 +1,25 @@
1
+ Operation Generator
2
+ ===================
3
+
4
+ Description:
5
+ ------------
6
+ This generator creates an 'TypedOperation' class that inherits from ApplicationOperation.
7
+
8
+ Command:
9
+ --------
10
+ rails generate typed_operation NAME [options]
11
+
12
+ Arguments:
13
+ ----------
14
+ NAME: The class name of the Operation class to be generated, e.g. 'MyOperation'.
15
+
16
+ Options:
17
+ --------
18
+ --path=path/to/directory: The path to the directory in which the operation class should be generated. The generated class will be namespaced according to the provided path.
19
+
20
+ Example:
21
+ --------
22
+ rails generate typed_operation MyOperation --path=app/operations
23
+
24
+ This will create the following file:
25
+ app/operations/my_operation.rb
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ <% if namespace_name.present? %>
4
+ module <%= namespace_name %>
5
+ class <%= name %> < ::ApplicationOperation
6
+ # Replace with implementation...
7
+ param :param1, String, convert: true
8
+
9
+ def prepare
10
+ # Prepare...
11
+ end
12
+
13
+ def call
14
+ # Perform...
15
+ end
16
+ end
17
+ end
18
+ <% else %>
19
+ class <%= name %> < ::ApplicationOperation
20
+ # Replace with implementation...
21
+ param :param1, String, convert: true
22
+
23
+ def prepare
24
+ # Prepare...
25
+ end
26
+
27
+ def call
28
+ # Perform...
29
+ end
30
+ end
31
+ <% end %>
@@ -0,0 +1,13 @@
1
+ Install Generator
2
+ =================
3
+
4
+ Description:
5
+ ------------
6
+ This generator installs a `ApplicationOperation` class which is your base class for all Operations.
7
+
8
+ Command:
9
+ --------
10
+ rails generate typed_operation:install
11
+
12
+ This will create the following file:
13
+ app/operations/application_operation.rb
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/generators/base"
4
+
5
+ module TypedOperation
6
+ module Install
7
+ class InstallGenerator < Rails::Generators::Base
8
+ source_root File.expand_path("templates", __dir__)
9
+
10
+ def copy_application_operation_file
11
+ copy_file "application_operation.rb", "app/operations/application_operation.rb"
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ApplicationOperation < ::TypedOperation::Base
4
+ # Common properties & methods for operations of this application...
5
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/generators/named_base"
4
+
5
+ class TypedOperationGenerator < Rails::Generators::NamedBase
6
+ source_root File.expand_path("templates", __dir__)
7
+
8
+ class_option :path, type: :string, default: "app/operations"
9
+
10
+ def generate_operation
11
+ template_path = File.join(self.class.source_root, "operation.rb")
12
+ dest_path = File.join(options[:path], "#{file_name}.rb")
13
+
14
+ template(template_path, dest_path)
15
+ end
16
+
17
+ private
18
+
19
+ def namespace_name
20
+ namespace_path = options[:path].gsub(/^app\/[^\/]*\//, "")
21
+ namespace_path.split("/").map(&:camelize).join("::")
22
+ end
23
+ end
@@ -1,5 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "dry/monads"
4
+ require "vident/typed"
5
+ require "vident/typed/attributes"
6
+
3
7
  module TypedOperation
4
8
  class Base
5
9
  include Dry::Monads[:result, :do]
@@ -1,4 +1,8 @@
1
1
  module TypedOperation
2
2
  class Railtie < ::Rails::Railtie
3
+ generators do
4
+ require "generators/typed_operation/install/install_generator"
5
+ require "generators/typed_operation_generator"
6
+ end
3
7
  end
4
8
  end
@@ -1,3 +1,3 @@
1
1
  module TypedOperation
2
- VERSION = "0.1.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -1,8 +1,8 @@
1
1
  require "typed_operation/version"
2
2
  require "typed_operation/railtie"
3
3
  require "typed_operation/base"
4
- require "typed_operation/prepared"
5
4
  require "typed_operation/partially_applied"
5
+ require "typed_operation/prepared"
6
6
 
7
7
  module TypedOperation
8
8
  # Your code goes here...
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: typed_operation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Ierodiaconou
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-04 00:00:00.000000000 Z
11
+ date: 2023-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,7 +16,7 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '7.0'
19
+ version: '6.0'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: '8.0'
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '7.0'
29
+ version: '6.0'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '8.0'
@@ -44,6 +44,20 @@ dependencies:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
46
  version: 0.1.0
47
+ - !ruby/object:Gem::Dependency
48
+ name: dry-initializer
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '3.0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '3.0'
47
61
  - !ruby/object:Gem::Dependency
48
62
  name: dry-monads
49
63
  requirement: !ruby/object:Gem::Requirement
@@ -64,7 +78,8 @@ dependencies:
64
78
  - - "<"
65
79
  - !ruby/object:Gem::Version
66
80
  version: '2'
67
- description: TypedOperation is a command pattern implementation
81
+ description: TypedOperation is a command pattern implementation where inputs can be
82
+ defined with runtime type checks. Operations can be partially applied.
68
83
  email:
69
84
  - stevegeek@gmail.com
70
85
  executables: []
@@ -74,6 +89,12 @@ files:
74
89
  - MIT-LICENSE
75
90
  - README.md
76
91
  - Rakefile
92
+ - lib/generators/USAGE
93
+ - lib/generators/templates/operation.rb
94
+ - lib/generators/typed_operation/install/USAGE
95
+ - lib/generators/typed_operation/install/install_generator.rb
96
+ - lib/generators/typed_operation/install/templates/application_operation.rb
97
+ - lib/generators/typed_operation_generator.rb
77
98
  - lib/tasks/typed_operation_tasks.rake
78
99
  - lib/typed_operation.rb
79
100
  - lib/typed_operation/base.rb