lets_do_this 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d58dc7db83b2aa6ee7a9191faeddb827183f37328eb14a8bc48fe21b6df5d405
4
+ data.tar.gz: c48dbb9efd3c0030eb0537f7baa7f704e997de77554558bf8f1a242913b45b74
5
+ SHA512:
6
+ metadata.gz: 047b44f8c4fd8084a2a79130769612187d87bda3b452646147957c172e2df6907f465a45914fc60d6546d15316589ab25a76109ac26e513ad2b6c9f5177bb4d1
7
+ data.tar.gz: ca138dfd9fe17319d34e85b5faaa1540558d0e26c0859996e20a493e36dac71b9bc63ca104f1336142cdf5c4c6b9103bbb84c04cbf2bbc866251b22ba621577d
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.idea
2
+ /.bundle/
3
+ /.yardoc
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.2
6
+ before_install: gem install bundler -v 2.1.4
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in lets_do_this.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 М.Забодаев
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/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # LetsDoThis
2
+
3
+ A way to organize the business logic of a project
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'lets_do_this'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install lets_do_this
20
+
21
+ ## Usage
22
+
23
+ TODO: WIP
24
+
25
+ ## Development
26
+
27
+ 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.
28
+
29
+ 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/zabodaevmm/lets_do_this.
34
+
35
+
36
+ ## License
37
+
38
+ 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,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "lets_do_this"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,26 @@
1
+ require_relative 'lib/lets_do_this/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "lets_do_this"
5
+ spec.version = LetsDoThis::VERSION
6
+ spec.authors = ["zabodaevmm"]
7
+ spec.email = ["zabodaevmm@gmail.com"]
8
+
9
+ spec.summary = %q{A way to organize the business logic of a project}
10
+ spec.homepage = "https://github.com/zabodaevmm/lets_do_this"
11
+ spec.license = "MIT"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
13
+
14
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+ end
@@ -0,0 +1,32 @@
1
+ require 'lets_do_this/errors'
2
+
3
+ module LetsDoThis
4
+ class Act
5
+ attr_accessor :performed, :errors, :result
6
+
7
+ def initialize
8
+ @performed = false
9
+ @errors = Errors.new
10
+ end
11
+
12
+ def instructions(_stage)
13
+ raise NotImplementedError
14
+ end
15
+
16
+ def follow_instructions!(stage)
17
+ tap do
18
+ _1.performed = true
19
+ instructions_ = instructions(stage)
20
+ _1.result = instructions_.is_a?(Hash) ? instructions_ : {}
21
+ end
22
+ end
23
+
24
+ def success?
25
+ @performed && @errors.empty?
26
+ end
27
+
28
+ def failure?
29
+ @performed && @errors.present?
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,15 @@
1
+ module LetsDoThis
2
+ class Errors < Hash
3
+ def add(key, value)
4
+ self[key] ||= []
5
+ self[key] << value
6
+ self[key].uniq!
7
+ end
8
+
9
+ def add_some(errors_hash)
10
+ errors_hash.each do |key, values|
11
+ values.each { |value| add key, value }
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,57 @@
1
+ require 'lets_do_this/errors'
2
+ require 'ostruct'
3
+
4
+ module LetsDoThis
5
+ class Scenario
6
+ attr_reader :act_sequence
7
+
8
+ ACT_SEQUENCE = [].freeze
9
+ STAGE_ATTRS_WHITELIST = %i[].freeze
10
+
11
+ def initialize(input)
12
+ @input = input
13
+ @errors = Errors.new
14
+ @act_sequence = self.class::ACT_SEQUENCE.map(&:new)
15
+ @stage_attrs_whitelist = self.class::STAGE_ATTRS_WHITELIST
16
+ end
17
+
18
+ def act_out!
19
+ raise LetsDoThis::EmptyActSequence if @act_sequence.empty?
20
+
21
+ raise LetsDoThis::EmptyStageAttrsWhitelist if @stage_attrs_whitelist.empty?
22
+
23
+ go_on_stage!(@input)
24
+ @act_sequence.each do
25
+ act = _1.follow_instructions!(stage)
26
+ unless act.success?
27
+ @errors.add(act.class.name, act.errors)
28
+ break
29
+ end
30
+
31
+ go_on_stage!(act.result)
32
+ end
33
+ self
34
+ end
35
+
36
+ def stage
37
+ @stage ||= OpenStruct.new
38
+ end
39
+
40
+ def go_on_stage!(hash)
41
+ raise(ArgumentError) unless hash.is_a?(Hash)
42
+
43
+ w_symbolized_keys = hash.transform_keys { |key| key.to_sym rescue key }
44
+ w_symbolized_keys.slice(*@stage_attrs_whitelist).each_pair do |key, value|
45
+ stage.public_send("#{key}=", value)
46
+ end
47
+ end
48
+
49
+ def success?
50
+ @errors.empty?
51
+ end
52
+
53
+ def failure?
54
+ !success?
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,3 @@
1
+ module LetsDoThis
2
+ VERSION = '0.1.1'
3
+ end
@@ -0,0 +1,8 @@
1
+ require 'lets_do_this/version'
2
+ require 'lets_do_this/act'
3
+ require 'lets_do_this/scenario'
4
+
5
+ module LetsDoThis
6
+ class EmptyActSequence < StandardError; end
7
+ class EmptyStageAttrsWhitelist < StandardError; end
8
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lets_do_this
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - zabodaevmm
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-02-07 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - zabodaevmm@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - ".rspec"
22
+ - ".travis.yml"
23
+ - Gemfile
24
+ - LICENSE.txt
25
+ - README.md
26
+ - Rakefile
27
+ - bin/console
28
+ - bin/setup
29
+ - lets_do_this.gemspec
30
+ - lib/lets_do_this.rb
31
+ - lib/lets_do_this/act.rb
32
+ - lib/lets_do_this/errors.rb
33
+ - lib/lets_do_this/scenario.rb
34
+ - lib/lets_do_this/version.rb
35
+ homepage: https://github.com/zabodaevmm/lets_do_this
36
+ licenses:
37
+ - MIT
38
+ metadata:
39
+ homepage_uri: https://github.com/zabodaevmm/lets_do_this
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: 2.7.0
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubygems_version: 3.1.4
56
+ signing_key:
57
+ specification_version: 4
58
+ summary: A way to organize the business logic of a project
59
+ test_files: []