ucasy 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 17ebb25fba3f59ded4ef25011e7f2d43854619c775f9c2f2b2c3b64ac9bccd51
4
+ data.tar.gz: 99d93a1383bc0ec0695cd432c6016b7fc80677b8f198188de12e87643b885efd
5
+ SHA512:
6
+ metadata.gz: a33b805568f830558b8fa1755794bf476dd14fb9b3153d9dda2ec8009abb89c4cf3758547f43f304b956c46e960c05bbc627ab155ee8b18aef809b14142ce39c
7
+ data.tar.gz: 0152edaa9a8d096e02be2acabacf97500b9117ac6ce6f310cd218ca1074d8843d75baa5e8f6600e3894efdaf4dbed7a398b627cb222bd4f598050bd5b433f1e1
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --require spec_helper
2
+ --format documentation
3
+ --force-color
4
+ --order rand
data/.rubocop.yml ADDED
@@ -0,0 +1,11 @@
1
+ require:
2
+ - rubocop-rspec
3
+ - rubocop-rake
4
+
5
+ inherit_gem:
6
+ standard: config/base.yml
7
+
8
+ AllCops:
9
+ NewCops: enable
10
+ TargetRubyVersion: 3.3
11
+ TargetRailsVersion: 7.1
data/.standard.yml ADDED
@@ -0,0 +1,3 @@
1
+ # For available configuration options, see:
2
+ # https://github.com/standardrb/standard
3
+ ruby_version: 3.3
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Lavenda Software
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
13
+ all 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
21
+ THE SOFTWARE.
data/Makefile ADDED
@@ -0,0 +1,8 @@
1
+ GEM_TO_PUSH = `ls ucasy*.gem | tail -n 1`
2
+
3
+ build:
4
+ gem build ucasy.gemspec
5
+
6
+ publish:
7
+ @echo "gem push ${GEM_TO_PUSH}"
8
+ @gem push ${GEM_TO_PUSH}
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Ucasy
2
+
3
+ Description soon!
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ru
10
+ gem "ucasy", "~> 0.0.1"
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```bash
16
+ bundle install
17
+ ```
18
+
19
+ Or install it yourself as:
20
+
21
+ ```bash
22
+ bundle add ucasy
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ You can use a Rails generator to create setup files:
28
+
29
+ ```sh
30
+ rails g ucasy:install
31
+ ```
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ucasy.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ require "standard/rake"
7
+
8
+ task default: %i[spec standard]
@@ -0,0 +1,23 @@
1
+ module Ucasy
2
+ class InstallGenerator < Rails::Generators::Base
3
+ source_root File.expand_path("templates", __dir__)
4
+
5
+ desc "Generates a application use case base."
6
+ def create_use_case_base
7
+ copy_file "use_case_base.rb", use_case_path
8
+ copy_file ".rspec", Rails.root.join(".rspec")
9
+ end
10
+
11
+ private
12
+
13
+ def use_case_path
14
+ Rails.root.join("app/#{GENERATOR_FOLDER_NAME}/use_case_base.rb")
15
+ end
16
+
17
+ def GENERATOR_FOLDER_NAME
18
+ return Ucasy::GENERATOR_FOLDER_NAME if defined?(Ucasy::GENERATOR_FOLDER_NAME)
19
+
20
+ Ucasy::DEFAULT_GENERATOR_FOLDER_NAME
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,4 @@
1
+ --require rails_helper
2
+ --format documentation
3
+ --force-color
4
+ --order rand
@@ -0,0 +1,2 @@
1
+ class UseCaseBase < Ucasy::Base
2
+ end
data/lib/ucasy/base.rb ADDED
@@ -0,0 +1,61 @@
1
+ require_relative "context"
2
+ require_relative "failure"
3
+
4
+ module Ucasy
5
+ class Base
6
+ class << self
7
+ def call(context)
8
+ new(context).perform
9
+ end
10
+
11
+ def required_attributes(*attributes)
12
+ @required_attributes = attributes
13
+ end
14
+
15
+ def _required_attributes
16
+ @required_attributes || []
17
+ end
18
+ end
19
+
20
+ def initialize(context = {})
21
+ @context = Context.build(context)
22
+ end
23
+
24
+ def perform
25
+ return if failure?
26
+
27
+ validate_context!
28
+ before if respond_to?(:before)
29
+ call
30
+ after if respond_to?(:after)
31
+
32
+ self
33
+ rescue Failure
34
+ self
35
+ end
36
+
37
+ def call
38
+ raise StandardError, "You must implement call method"
39
+ end
40
+
41
+ private
42
+
43
+ attr_reader :context
44
+
45
+ def validate_context!
46
+ self.class._required_attributes.each do |attribute|
47
+ next if context.respond_to?(attribute)
48
+
49
+ raise ArgumentError, "You must set '#{attribute}' variable"
50
+ end
51
+ end
52
+
53
+ def method_missing(method_name, *, &block)
54
+ context.public_send(method_name)
55
+ end
56
+
57
+ def respond_to_missing?(method_name, include_private = false)
58
+ context.respond_to?(method_name, include_private)
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,23 @@
1
+ require "ostruct"
2
+
3
+ module Ucasy
4
+ class Context < OpenStruct
5
+ def self.build(context = {})
6
+ (self === context) ? context : new(context)
7
+ end
8
+
9
+ def fail!(options = {})
10
+ options.each { |key, value| self[key.to_sym] = value }
11
+ @failure = true
12
+ raise Failure, self
13
+ end
14
+
15
+ def failure?
16
+ @failure || false
17
+ end
18
+
19
+ def success?
20
+ !failure?
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,11 @@
1
+ module Ucasy
2
+ class Failure < StandardError
3
+ attr_reader :context
4
+
5
+ def initialize(context = nil)
6
+ @context = context
7
+
8
+ super
9
+ end
10
+ end
11
+ end
data/lib/ucasy/flow.rb ADDED
@@ -0,0 +1,22 @@
1
+ module Ucasy
2
+ class Flow < Base
3
+ class << self
4
+ def service_classes(*service_classes)
5
+ @service_classes = service_classes
6
+ end
7
+ alias_method :flow, :service_classes
8
+
9
+ def _service_classes
10
+ @service_classes || []
11
+ end
12
+ end
13
+
14
+ def call
15
+ self.class._service_classes.each do |service_class|
16
+ service_class.call(context)
17
+ end
18
+
19
+ self
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ module Ucasy
2
+ VERSION = "0.0.1"
3
+ end
data/lib/ucasy.rb ADDED
@@ -0,0 +1,10 @@
1
+ require_relative "ucasy/version"
2
+ require_relative "ucasy/base"
3
+ require_relative "ucasy/flow"
4
+
5
+ module Ucasy
6
+ Ucasy::DEFAULT_GENERATOR_FOLDER_NAME = "use_cases"
7
+
8
+ class Error < StandardError
9
+ end
10
+ end
@@ -0,0 +1,4 @@
1
+ module Ucasy
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
data/ucasy.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ require_relative "lib/ucasy/version"
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "ucasy"
5
+ spec.version = Ucasy::VERSION
6
+ spec.authors = ["Lavenda Software"]
7
+ spec.email = ["lavenda@lavenda.com.br"]
8
+
9
+ spec.summary = "Ucasy is just a quick test suite setup for Rails application"
10
+ spec.homepage = "https://github.com/LavendaSoftware/ucasy"
11
+ spec.license = "MIT"
12
+ spec.required_ruby_version = ">= 3.0.0"
13
+
14
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "#{spec.homepage}/blob/main/README.md"
18
+ spec.metadata["changelog_uri"] = "#{spec.homepage}/commits/main"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(__dir__) do
23
+ `git ls-files -z`.split("\x0").reject do |f|
24
+ (File.expand_path(f) == __FILE__) ||
25
+ f.start_with?(*%w[bin/ test/ spec/ features/ .git .github appveyor Gemfile])
26
+ end
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ucasy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Lavenda Software
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-05-05 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - lavenda@lavenda.com.br
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".rspec"
21
+ - ".rubocop.yml"
22
+ - ".standard.yml"
23
+ - LICENSE.txt
24
+ - Makefile
25
+ - README.md
26
+ - Rakefile
27
+ - lib/generators/ucasy/install/install_generator.rb
28
+ - lib/generators/ucasy/install/templates/.rspec
29
+ - lib/generators/ucasy/install/templates/use_case_base.rb
30
+ - lib/ucasy.rb
31
+ - lib/ucasy/base.rb
32
+ - lib/ucasy/context.rb
33
+ - lib/ucasy/failure.rb
34
+ - lib/ucasy/flow.rb
35
+ - lib/ucasy/version.rb
36
+ - sig/ucasy/spec.rbs
37
+ - ucasy.gemspec
38
+ homepage: https://github.com/LavendaSoftware/ucasy
39
+ licenses:
40
+ - MIT
41
+ metadata:
42
+ allowed_push_host: https://rubygems.org
43
+ homepage_uri: https://github.com/LavendaSoftware/ucasy
44
+ source_code_uri: https://github.com/LavendaSoftware/ucasy/blob/main/README.md
45
+ changelog_uri: https://github.com/LavendaSoftware/ucasy/commits/main
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: 3.0.0
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.5.9
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: Ucasy is just a quick test suite setup for Rails application
65
+ test_files: []